Fix NonceUtil.isValidNonce to reject all whitespace, not just spaces - #1399
Open
UditDewan wants to merge 1 commit into
Open
Fix NonceUtil.isValidNonce to reject all whitespace, not just spaces#1399UditDewan wants to merge 1 commit into
UditDewan wants to merge 1 commit into
Conversation
isValidNonce intended to reject any nonce containing whitespace, but
the check used nonce.indexOf(' '), which only matches the literal space
character. A nonce containing a tab, newline, or carriage return passed
validation despite the local being named hasWhiteSpace. Such a nonce is
later sent into the OIDC login flow via LoginConfiguration, where
embedded whitespace can break request handling.
Switch to Char.isWhitespace() so all whitespace characters are rejected,
and add regression tests for tab, newline, and carriage return.
Co-authored-by: Baradhan-Madhu <26barumadhu@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NonceUtil.isValidNonceis meant to reject any nonce that contains whitespace, but the check only matched the literal space character:Despite the local being named
hasWhiteSpace, a nonce containing a tab (\t), newline (\n), or carriage return (\r) passed validation. That nonce is later fed into the OIDC login flow throughLoginConfiguration'srequire(NonceUtil.isValidNonce(nonce) && ...), where embedded whitespace can break request handling downstream.Change
Use
Char.isWhitespace()so every whitespace character is rejected:Tests
Added regression coverage in
NonceUtilTestfor tab, newline, and carriage return — each of which previously passed validation and now correctly fails. Existing valid/space/empty cases are unchanged.