Skip to content

Fix NonceUtil.isValidNonce to reject all whitespace, not just spaces - #1399

Open
UditDewan wants to merge 1 commit into
facebook:mainfrom
UditDewan:fix/nonce-whitespace-validation
Open

Fix NonceUtil.isValidNonce to reject all whitespace, not just spaces#1399
UditDewan wants to merge 1 commit into
facebook:mainfrom
UditDewan:fix/nonce-whitespace-validation

Conversation

@UditDewan

@UditDewan UditDewan commented Jun 30, 2026

Copy link
Copy Markdown

Summary

NonceUtil.isValidNonce is meant to reject any nonce that contains whitespace, but the check only matched the literal space character:

val hasWhiteSpace = nonce.indexOf(' ') >= 0
return !hasWhiteSpace

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 through LoginConfiguration's require(NonceUtil.isValidNonce(nonce) && ...), where embedded whitespace can break request handling downstream.

Change

Use Char.isWhitespace() so every whitespace character is rejected:

val hasWhiteSpace = nonce.any { it.isWhitespace() }
return !hasWhiteSpace

Tests

Added regression coverage in NonceUtilTest for tab, newline, and carriage return — each of which previously passed validation and now correctly fails. Existing valid/space/empty cases are unchanged.

Note: the SDK's test suite requires the Android SDK/Gradle toolchain, which wasn't available in my local environment, so the new tests were validated by inspection. CI should exercise them.
Co-authored-by:Baradhan-Madhu

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>
@meta-cla meta-cla Bot added the CLA Signed label Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant