Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: fix require_app_auth matches unexpected routes #42

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

udangel-r7
Copy link
Contributor

APP_ROUTES contains an r"/app" entry to match for the /app route. This will also match repositories which start with app causing require_app_auth to return true.

This change adjusts the /app regex to match at the beginning of the string and not anywhere within the url.path

`APP_ROUTES` contains an `r"/app"` entry to match for the `/app` route. This will also match repositories which start with `app` causing `require_app_auth` to return true.

This change adjusts the `/app` regex to match at the beginning of the string and not anywhere within the url.path
@yanyongyu yanyongyu added the bug Something isn't working label Sep 1, 2023
@yanyongyu
Copy link
Owner

yanyongyu commented Sep 1, 2023

The app auth routes are copied from https://github.com/octokit/auth-app.js/blob/1c0d530c6b85890853b860b16f0c11e106bb676f/src/requires-app-auth.ts#L1-L22.

The regex in the octokit is https://github.com/octokit/auth-app.js/blob/1c0d530c6b85890853b860b16f0c11e106bb676f/src/requires-app-auth.ts#L45. We may need to change the regex at L29 instead.

Seems this change should be applied:

- APP_AUTH_REGEX = re.compile(rf"(?:{'|'.join(APP_ROUTES)})[^/]*$", re.I)
+ APP_AUTH_REGEX = re.compile(rf"^(?:{'|'.join(APP_ROUTES)})$", re.I)

Could you please update this regex instead and test it? I cannot make a pr review comment on unchanged lines.

@yanyongyu yanyongyu changed the title Update _url.py to not match for repositories starting with app Bug: fix require_app_auth matches unexpected routes Sep 1, 2023
@yanyongyu yanyongyu merged commit fd80590 into yanyongyu:master Sep 19, 2023
1 check passed
@udangel-r7 udangel-r7 deleted the fix-app-route-matching branch September 19, 2023 18:17
@brainiac
Copy link

brainiac commented Oct 13, 2023

This change breaks github enterprise, because urls begin with /api/v3, this regex no longer matches for the /app endpoint

@yanyongyu
Copy link
Owner

🤔 That's my mistake. octokit matches the path by replacing the base url first:

https://github.com/octokit/auth-app.js/blob/c0068e06081a5d930799285a7c79c9c948b676b6/src/hook.ts#L43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Rest API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants