Skip to content

fix: reject malformed token and DPoP proof input with SDK errors - #151

Merged
kishore7snehil merged 4 commits into
mainfrom
fix/reject-non-object-jwt-segments
Oct 28, 2026
Merged

kishore7snehil merged 4 commits into
mainfrom
fix/reject-non-object-jwt-segments

Conversation

@kishore7snehil

@kishore7snehil kishore7snehil commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📋 Changes

This PR makes verify_access_token(), verify_dpop_proof() and verify_request() reject malformed tokens and DPoP proofs with VerifyAccessTokenError or InvalidDpopProofError. Previously several shapes raised AttributeError, TypeError or ValueError instead, which callers that only catch the SDK's own errors did not handle.

🐛 Bug Fixes

  • Non-object segments: A JWT header or payload that is not a JSON object (for example a list, string, number or null) is rejected. Nesting too deep for the JSON parser is also rejected.
  • alg: A header whose alg is not a string raises VerifyAccessTokenError.
  • exp and nbf: A non-numeric or non-finite exp raises VerifyAccessTokenError("Invalid 'exp' claim in token"). A non-finite nbf is rejected the same way.
  • DPoP proof header: An unparseable proof header, or a jwk that cannot be imported, raises InvalidDpopProofError.
  • DPoP claims: A non-string htm and a non-finite iat raise InvalidDpopProofError.
  • Token stores: decrypt() raises ValueError for a stored value whose header is not a JSON object, and session_fingerprint() falls back to the SHA-256 of the token for any payload it cannot parse.
  • Response lifetimes: A negative expires_in from the token endpoint now raises ApiError with code invalid_response in get_access_token_for_connection() and get_client_credentials_token(), as get_token_by_exchange_profile() already did.

🔧 API Changes

  • get_unverified_header() and get_unverified_payload() now raise ValueError when the segment is not a JSON object or is nested too deeply. They previously returned the decoded value as is. These helpers are not exported from the package root.
  • exp set to true or false now raises "Invalid 'exp' claim in token". It previously raised "Token is expired".
  • exp set to null or a string now raises VerifyAccessTokenError. It previously raised TypeError.
  • Tokens and proofs that verified before are unaffected, apart from non-finite exp, nbf and iat values, which are now rejected.

📖 Documentation

  • docs/OrganizationPolicy.md now states that get_token_on_behalf_of() and get_access_token_for_connection() apply the organization policy only when a token_store is configured and verified is not passed.
  • The README Token Vault example now calls verify_access_token() before the exchange.
  • docs/TokenStorage.md now says the index token_key starts with the caller's sub in plain text.

🧪 Testing

  • This change adds test coverage
  • This change has been tested on the latest version of the platform/language

Contributor Checklist

@kishore7snehil
kishore7snehil requested a review from a team as a code owner October 27, 2026 14:54
Comment thread tests/test_api_client.py Resolved
Comment thread tests/test_utils.py Resolved
Comment thread src/auth0_api_python/api_client.py Resolved
@kishore7snehil
kishore7snehil merged commit f2fa73c into main Oct 28, 2026
7 checks passed
@kishore7snehil
kishore7snehil deleted the fix/reject-non-object-jwt-segments branch October 28, 2026 11:55
rmad17 added a commit that referenced this pull request Oct 29, 2026
Co-Authored-By: Claude <noreply@anthropic.com>
@kishore7snehil kishore7snehil mentioned this pull request Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants