Skip to content

Fix CodeQL finding - regex - #3926

Merged
strehle merged 3 commits into
developfrom
code-ql-fix
Jun 2, 2026
Merged

Fix CodeQL finding - regex#3926
strehle merged 3 commits into
developfrom
code-ql-fix

Conversation

@strehle

@strehle strehle commented May 30, 2026

Copy link
Copy Markdown
Member

Changes:

  • server/src/main/java/org/cloudfoundry/identity/uaa/util/UaaUrlUtils.java:115-134
    • Replaced the unbounded userinfo group (.:.@)? with ([^:/@]{0,255}:[^/@]{0,255}@)? — character classes that exclude the surrounding delimiters, so the regex engine has only one way to match each character (no quadratic backtracking) and is hard-bounded at 255 chars per part.
    • Added a MAX_REDIRECT_URI_LENGTH = 8000 length cap in isValidRegisteredRedirectUrl so pathological inputs are rejected before the regex ever runs.
  • server/src/test/java/org/cloudfoundry/identity/uaa/util/UaaUrlUtilsTest.java:649-672
    • New isValidRegisteredRedirectUrlRejectsOverlongInputQuickly test: feeds 100 000 a's, asserts false and that the call returns in under 1 second. This guards against future regressions reintroducing polynomial behaviour.

Test results: 172 tests in UaaUrlUtilsTest pass, 92 tests across ClientAdminEndpointsValidatorTests and LegacyRedirectResolverTest pass — all existing redirect-URI semantics (including userinfo
edge cases like http://username:password@some.server.com, http://:@some.server.com, and the http://AAA@@attacker.com host-confusion rejections) are preserved.

The CodeQL alert at line 126 should now clear: the regex is no longer polynomial, and the input is length-bounded before evaluation.

Changes:

  - server/src/main/java/org/cloudfoundry/identity/uaa/util/UaaUrlUtils.java:115-134
    - Replaced the unbounded userinfo group (.*:.*@)? with ([^:/@]{0,255}:[^/@]{0,255}@)? — character classes that exclude the surrounding delimiters, so the regex engine has only one way to
  match each character (no quadratic backtracking) and is hard-bounded at 255 chars per part.
    - Added a MAX_REDIRECT_URI_LENGTH = 2048 length cap in isValidRegisteredRedirectUrl so pathological inputs are rejected before the regex ever runs.
  - server/src/test/java/org/cloudfoundry/identity/uaa/util/UaaUrlUtilsTest.java:649-672
    - New isValidRegisteredRedirectUrlRejectsOverlongInputQuickly test: feeds 100 000 a's, asserts false and that the call returns in under 1 second. This guards against future regressions
  reintroducing polynomial behaviour.

  Test results: 172 tests in UaaUrlUtilsTest pass, 92 tests across ClientAdminEndpointsValidatorTests and LegacyRedirectResolverTest pass — all existing redirect-URI semantics (including userinfo
  edge cases like http://username:password@some.server.com, http://*:*@some.server.com, and the http://AAA@@attacker.com host-confusion rejections) are preserved.

  The CodeQL alert at line 126 should now clear: the regex is no longer polynomial, and the input is length-bounded before evaluation.

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.

Pull request overview

This PR mitigates a CodeQL ReDoS finding in redirect URI validation by bounding redirect URI input length and tightening the userinfo portion of the registered redirect URI regex.

Changes:

  • Adds a 8000-character maximum for registered redirect URI validation.
  • Replaces the unbounded userinfo regex group with bounded character classes.
  • Adds a regression test for overlong redirect URI rejection.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
server/src/main/java/org/cloudfoundry/identity/uaa/util/UaaUrlUtils.java Adds redirect URI length limiting and updates the allowed redirect URI pattern.
server/src/test/java/org/cloudfoundry/identity/uaa/util/UaaUrlUtilsTest.java Adds a test for quick rejection of overlong redirect URI inputs.

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread server/src/main/java/org/cloudfoundry/identity/uaa/util/UaaUrlUtils.java Outdated

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@github-project-automation github-project-automation Bot moved this from Inbox to Pending Merge | Prioritized in Foundational Infrastructure Working Group Jun 1, 2026
@strehle
strehle merged commit 5c491f4 into develop Jun 2, 2026
29 checks passed
@strehle
strehle deleted the code-ql-fix branch June 2, 2026 15:21
@github-project-automation github-project-automation Bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants