Repository navigation
perf(core): parse the request URI only when the Cognito or S3 filter needs it #7932
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,9 +72,13 @@ public CognitoCustomDomainFilter(CognitoService cognitoService) { | |
|
|
||
| @Override | ||
| public void filter(ContainerRequestContext requestContext) { | ||
| // Every request of every service passes here, so the URI is parsed only for a path this filter may serve. | ||
| if (!mayServe(requestContext.getUriInfo().getPath())) { | ||
| return; | ||
|
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Encoded paths bypass domain pool pinning CognitoCustomDomainFilter.filter now gates its raw-path check on UriInfo.getPath(), although the routed path can have encoded dot segments removed before that check. For a custom-domain request such as /oauth2/%2E%2E/cognito-idp/oauth2/token, that gate can exit before setting the pool property, allowing the normalized path to reach the generic token handler without the custom-domain pool restriction; valid token credentials are still required. Agent Prompt
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This opens no new way to reach the token handler. The filter rewrites /oauth2/token to /cognito-idp/oauth2/token, and a client can send /cognito-idp/oauth2/token to the custom domain host directly. The filter has always left that path alone, since it does not start with /oauth2/. Before this change, /oauth2/%2E%2E/cognito-idp/oauth2/token got the 404 for an unknown /oauth2/ path. It now routes like /oauth2/../cognito-idp/oauth2/token, which the URI normalization already sent past the filter. The PR description notes this. |
||
| } | ||
| URI originalUri = requestContext.getUriInfo().getRequestUri(); | ||
| String path = originalUri.getRawPath(); | ||
| if (path == null || !(path.startsWith(OAUTH_PREFIX) || MANAGED_LOGIN_PATHS.contains(path))) { | ||
| if (path == null || !mayServe(path)) { | ||
| return; | ||
| } | ||
| String host = RequestHost.of(requestContext); | ||
|
|
@@ -116,6 +120,10 @@ public void filter(ContainerRequestContext requestContext) { | |
| RequestUriRewrite.apply(requestContext, newUri); | ||
| } | ||
|
|
||
| private static boolean mayServe(String path) { | ||
| return path.startsWith(OAUTH_PREFIX) || MANAGED_LOGIN_PATHS.contains(path); | ||
| } | ||
|
|
||
| private static String stripPort(String host) { | ||
| int colonIndex = host.lastIndexOf(':'); | ||
| if (colonIndex > 0) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Slashless paths miss custom-domain login
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation toolsDismiss ↗ | View ↗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UriInfo.getPath() keeps the leading slash here. RESTEasy Reactive returns the decoded request path with its leading slash, and Floci sets no application path, so nothing is cut from it. SignedServiceRoute and the SQS queue URL filter already compare this value with slash-prefixed paths. CognitoCustomDomainOAuthContractIntegrationTest sends /oauth2/token to a custom domain over HTTP and passes on this branch.