RANGER-5693: Stop logging full JWT bearer tokens on validation failure#1081
Open
ramackri wants to merge 2 commits into
Open
RANGER-5693: Stop logging full JWT bearer tokens on validation failure#1081ramackri wants to merge 2 commits into
ramackri wants to merge 2 commits into
Conversation
Replace jwtToken.serialize() in the validation-failure WARN path with safeJwtLogContext() that logs only non-sensitive metadata and a SHA-256 hash for log correlation. Add null-safety for missing audience claims and unit tests for the safe logging path.
ramackri
requested review from
dhavalshah9131,
kishorgollapalliwar,
kumaab,
mneethiraj and
pradeepagrawal8184
July 16, 2026 07:50
kumaab
reviewed
Jul 16, 2026
Per review feedback, remove sha256Hex/tokenHash from safeJwtLogContext; jwtId is sufficient for log correlation when present.
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
header.payload.signature) whenRangerJwtAuthHandlervalidation fails.subject,audience,issuer,keyId,jwtId.JIRA: https://issues.apache.org/jira/browse/RANGER-5693
Problem
On validation failure,
RangerJwtAuthHandler.authenticate()logged:validateToken()checks claims in order: expiration → signature → audience → issuer. A cryptographically valid, unexpired token rejected only for audience mismatch still hit this WARN path. The full bearer credential in logs could be replayed against another Ranger JWT consumer that trusts the same signing material and accepts the token's audience.Fix
Before:
After:
safeJwtLogContext()emits diagnostic fields only, for example:The raw bearer string is never written to operational logs.
jwtId(jticlaim) provides log correlation when present.Null-safety
validateAudiences(): guardtokenAudienceList != nullbefore iterating (avoids NPE whenaudclaim is absent).safeJwtLogContext(): guardjwtToken.getHeader()before readingkeyId; useStringUtils.join()for audience list (JDK 8 compatible, tolerates null list entries).Files changed (2)
ranger-authn/.../RangerJwtAuthHandler.javasafeJwtLogContext(), audience null guardranger-authn/.../TestRangerJwtAuthHandler.javaTest plan
Unit tests (automated)
mvn -pl ranger-authn test -Dtest=TestRangerJwtAuthHandler mvn verify -pl ranger-authn -Dtest=TestRangerJwtAuthHandler -Drat.skip=true