Skip to content

perf(core): parse the request URI only when the Cognito or S3 filter needs it - #7932

Merged
pgermosen merged 1 commit into
floci-io:mainfrom
exoego:perf/core-request-uri-parse
Nov 10, 2026
Merged

pgermosen merged 1 commit into
floci-io:mainfrom
exoego:perf/core-request-uri-parse

Conversation

@exoego

@exoego exoego commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Summary

The Cognito custom domain filter and the S3 virtual host filter run on every request of every service. Each began by reading the full request URI, which parsed it and allocated about 340 bytes. The parse is kept for the rest of the request, so both filters had to stop.

The Cognito filter now checks the routed path first. The S3 filter reads the URI only when the Host header is missing or a bucket matched. Requests to other services no longer parse the URI, and the share of request thread CPU in the two filters fell from 1.6% to 0.6%. An S3 request still parses its URI, now in the S3 handler that reads the key. Allocation per request fell by 0.6% to 1.5%. Latency fell by up to 1.0%, and no request got slower beyond the noise.

Measured on the JVM in memory mode. Both builds ran at the same time and one client alternated between them in batches of 1,000 requests, for 6 passes on fresh servers. Each latency change is the median of the 6 paired ratios. Comparing main with itself over 6 passes stayed within 0.3% for p50, 0.8% for p95, and 0.9% for the allocation per request. S3 GetObject varied about twice as much between passes as the other requests, so its row comes from a separate run of S3 GetObject alone for 12 passes. Main against itself in that run stayed within 0.6% for p50, 0.5% for p95, and 0.2% for the allocation. Allocation comes from an async-profiler profile.

Request p50 on main, change p95 on main, change Allocated per request (bytes) Allocated in the two filters (bytes)
DynamoDB GetItem 83.2 us, -0.7% 90.7 us, -0.3% 34,148 -> 33,711 (-1.3%) 359 -> 30
SQS GetQueueUrl 79.5 us, +0.1% 87.2 us, +0.4% 28,720 -> 28,486 (-0.8%) 360 -> 29
SNS ListTopics 76.2 us, -0.5% 85.1 us, -1.0% 36,055 -> 35,816 (-0.7%) 324 -> 24
S3 GetObject 48.0 us, +0.3% 58.3 us, -0.2% 20,952 -> 20,822 (-0.6%) 992 -> 636
SSM GetParameter 65.6 us, -0.7% 72.6 us, -0.5% 27,840 -> 27,591 (-0.9%) 347 -> 32
Secrets Manager GetSecretValue 66.0 us, -0.7% 73.0 us, -0.2% 28,591 -> 28,200 (-1.4%) 363 -> 28
KMS DescribeKey 66.4 us, -0.6% 73.0 us, -0.4% 29,468 -> 29,208 (-0.9%) 342 -> 32
STS GetCallerIdentity 77.0 us, -0.4% 85.7 us, -0.3% 36,998 -> 36,756 (-0.7%) 375 -> 30
IAM ListUsers 76.5 us, -0.6% 85.0 us, -0.4% 36,168 -> 35,836 (-0.9%) 352 -> 29
Lambda ListFunctions 45.0 us, -0.3% 50.2 us, -0.7% 18,112 -> 17,912 (-1.1%) 360 -> 32
CloudWatch Logs DescribeLogGroups 67.4 us, -0.7% 73.8 us, -0.1% 30,506 -> 30,040 (-1.5%) 348 -> 35
EventBridge ListEventBuses 67.1 us, -0.1% 73.8 us, -0.3% 27,704 -> 27,422 (-1.0%) 339 -> 27
API Gateway GET with a Bearer token 58.5 us, -0.9% 66.1 us, -0.0% 46,020 -> 45,348 (-1.5%) 894 -> 528

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

No change for the paths the Cognito filter serves or for any request the S3 filter routes. Both still read the same URI for those. On a Cognito custom domain, a path that leaves /oauth2/ through encoded dots, such as /oauth2/%2E%2E/x, now gets the routing that /oauth2/../x already got. New test lines check that the URI is not read for other paths and for another service's request.

Checklist

  • ./mvnw test passes locally
  • New or updated integration test added
  • Commit messages follow Conventional Commits
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

…needs it

The Cognito custom domain filter and the S3 virtual host filter run on every
request of every service. Each read the full request URI first, which parses
it and allocates about 340 bytes. RESTEasy keeps the first parse for the
request, so both filters had to change.

The Cognito filter now checks the routed path before it reads the URI. The S3
filter reads the URI only when the Host header is missing or a bucket matched.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 19:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Avoid eager request URI parsing in Cognito and S3 filters

✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Check Cognito paths before reading the full URI, avoiding parsing on unrelated requests.
• Defer S3 URI reads until host fallback or bucket routing requires them.
Diagram

graph TD
  A["Incoming request"] --> B{"Cognito path?"} -->|yes| C["Cognito URI routing"] --> D["S3 host check"] -->|host missing| E["URI authority"] --> F{"S3 bucket?"} -->|yes| G["S3 URI rewrite"]
  B -->|no| D
  D -->|host available| F
Loading
High-Level Assessment

Keep the checks in the existing filters: each already knows when it needs the URI, so deferring reads there avoids a broader routing change. Centralizing URI parsing would not remove the unnecessary parse on unrelated requests.

Files changed (4) +17 / -5

Enhancement (2) +14 / -5
CognitoCustomDomainFilter.javaGate URI reads on candidate Cognito paths +9/-1

Gate URI reads on candidate Cognito paths

• Checks the routed path before requesting the full URI. Retains the raw-path check for candidate Cognito routes.

src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java

S3VirtualHostFilter.javaDefer S3 URI reads until routing needs them +5/-4

Defer S3 URI reads until routing needs them

• Reads the URI for host fallback only when the Host header is absent or blank. Otherwise, waits until a virtual-hosted bucket matches before reading it for path rewriting.

src/main/java/io/floci/aws/services/s3/S3VirtualHostFilter.java

Tests (2) +3 / -0
CognitoCustomDomainFilterTest.javaAssert unrelated Cognito paths skip URI reads +2/-0

Assert unrelated Cognito paths skip URI reads

• Mocks the routed path and verifies that non-candidate paths do not request the full URI.

src/test/java/io/floci/aws/services/cognito/CognitoCustomDomainFilterTest.java

S3VirtualHostFilterTest.javaAssert ignored form requests skip URI reads +1/-0

Assert ignored form requests skip URI reads

• Verifies that an unsigned form request rejected by S3 virtual-host routing never requests the full URI.

src/test/java/io/floci/aws/services/s3/S3VirtualHostFilterTest.java

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Slashless paths miss custom-domain login 🐞 Bug ≡ Correctness
Description
CognitoCustomDomainFilter.filter passes UriInfo.getPath() to mayServe, whose accepted paths
all begin with /, without first accounting for the slashless relative path that getPath() can
return. When it returns oauth2/token, login, or logout, the filter exits before domain lookup
and rewrite, leaving those custom-domain requests to other routes instead of their Cognito handlers.
Code

src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[R76-77]

+        if (!mayServe(requestContext.getUriInfo().getPath())) {
+            return;
Relevance

●●● Strong

Concrete, trivial fix: getPath() can be slashless, and a prior GuardDuty getPath normalization
suggestion was accepted; no rejection precedent.

PR-#5373

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The repository explicitly accommodates a leading-slash-less UriInfo.getPath() value elsewhere,
whereas the new predicate accepts only slash-prefixed values. The test stub always supplies a
slash-prefixed URI.getPath(), so it cannot catch this early return.

src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[75-82]
src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[123-125]
src/main/java/io/floci/aws/core/common/GlobalCorsFilter.java[170-177]
src/test/java/io/floci/aws/core/common/GlobalCorsFilterTest.java[12-21]
src/test/java/io/floci/aws/services/cognito/CognitoCustomDomainFilterTest.java[204-209]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The early Cognito path check can reject a served path when `UriInfo.getPath()` omits its leading slash.
## Fix Focus Areas
- src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[75-82]
- src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[123-125]
- src/test/java/io/floci/aws/services/cognito/CognitoCustomDomainFilterTest.java[204-208]
## Recommended Fix
Handle both relative and slash-prefixed `UriInfo` paths before applying the preliminary predicate. Test served paths with a slashless `getPath()` value rather than deriving every stubbed path from `URI.getPath()`. Preserve the separate raw-path check.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


2. Encoded paths bypass domain pool pinning 🐞 Bug ⛨ Security
Description
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.
Code

src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[R76-77]

+        if (!mayServe(requestContext.getUriInfo().getPath())) {
+            return;
Relevance

●● Moderate

Security-flavored and contests the PR's stated encoded-dot routing intent; no close precedent either
way, so uncertain.

PR-#5855
PR-#7559

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The repository documents encoded-dot decoding and dot-segment removal in the router's path, distinct
from the original raw request path. The added return precedes the only code that looks up the custom
domain and sets its pool property; the generic token route reads that property and its pool-mismatch
checks are conditional on a non-null value.

src/main/java/io/floci/aws/services/iam/IamActionRegistry.java[780-786]
src/main/java/io/floci/aws/services/iam/IamActionRegistry.java[803-815]
src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[75-82]
src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[99-120]
src/main/java/io/floci/aws/services/cognito/CognitoOAuthController.java[396-403]
src/main/java/io/floci/aws/services/cognito/CognitoOAuthController.java[614-631]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The preliminary check can miss an original `/oauth2/` path when routing normalizes encoded dot segments out of it, skipping the custom-domain pool binding.
## Fix Focus Areas
- src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[75-82]
- src/test/java/io/floci/aws/services/cognito/CognitoCustomDomainFilterTest.java[204-208]
## Recommended Fix
Ensure the preliminary decision preserves the original request path's `/oauth2/` prefix rather than relying solely on the decoded or normalized routed path. If a safe raw-path fast path is unavailable, retain URI parsing for ambiguous requests. Add a test that supplies distinct normalized and raw paths for an encoded-dot-segment URL and verifies the custom-domain response and pool isolation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Compliance rules (platform): 16 rules
✅ Web pages:
  +15 more
✅ Cross-repo context — repo relationships
  Explored: repo: floci-io/floci-labs (sha: c6c6bb16) — View relationship
  Explored: repo: floci-io/floci-duck (sha: 1e487773) — View relationship
  Explored: repo: floci-io/floci-ui (sha: 79ff2b16) — View relationship
✅ REVIEW.md
Review mode: Auto: ⚖️ Balanced: Small diff, but it changes routing in Cognito auth and S3 host filters on every request.

Grey Divider

Tip of the day
💡 Did you know, you can move or hide resolved findings to focus on what still needs action

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +76 to +77
if (!mayServe(requestContext.getUriInfo().getPath())) {
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Slashless paths miss custom-domain login 🐞 Bug ≡ Correctness

CognitoCustomDomainFilter.filter passes UriInfo.getPath() to mayServe, whose accepted paths
all begin with /, without first accounting for the slashless relative path that getPath() can
return. When it returns oauth2/token, login, or logout, the filter exits before domain lookup
and rewrite, leaving those custom-domain requests to other routes instead of their Cognito handlers.
Agent Prompt
## Issue description
The early Cognito path check can reject a served path when `UriInfo.getPath()` omits its leading slash.
## Fix Focus Areas
- src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[75-82]
- src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[123-125]
- src/test/java/io/floci/aws/services/cognito/CognitoCustomDomainFilterTest.java[204-208]
## Recommended Fix
Handle both relative and slash-prefixed `UriInfo` paths before applying the preliminary predicate. Test served paths with a slashless `getPath()` value rather than deriving every stubbed path from `URI.getPath()`. Preserve the separate raw-path check.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Copy link
Copy Markdown
Contributor Author

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.

Comment on lines +76 to +77
if (!mayServe(requestContext.getUriInfo().getPath())) {
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Encoded paths bypass domain pool pinning 🐞 Bug ⛨ Security

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
## Issue description
The preliminary check can miss an original `/oauth2/` path when routing normalizes encoded dot segments out of it, skipping the custom-domain pool binding.
## Fix Focus Areas
- src/main/java/io/floci/aws/services/cognito/CognitoCustomDomainFilter.java[75-82]
- src/test/java/io/floci/aws/services/cognito/CognitoCustomDomainFilterTest.java[204-208]
## Recommended Fix
Ensure the preliminary decision preserves the original request path's `/oauth2/` prefix rather than relying solely on the decoded or normalized routed path. If a safe raw-path fast path is unavailable, retain URI parsing for ambiguous requests. Add a test that supplies distinct normalized and raw paths for an encoded-dot-segment URL and verifies the custom-domain response and pool isolation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

@pgermosen pgermosen added enhancement New feature or request floci-core labels Nov 10, 2026

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@exoego thanks, checking the routed path first keeps the URI parse off every other service's request, and the S3 filter still reads the same host and path whenever it routes. Looks good to me.

@pgermosen
pgermosen merged commit 57e4e3f into floci-io:main Nov 10, 2026
29 checks passed
@exoego
exoego deleted the perf/core-request-uri-parse branch November 10, 2026 20:22
@hectorvent

Copy link
Copy Markdown
Member

🎉 This PR is included in version 2.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants