Skip to content

nul-terminate base64-decoded JWT payload before cJSON_Parse - #5543

Open
Kartik (sage-mode-hunter) wants to merge 1 commit into
confluentinc:masterfrom
sage-mode-hunter:oidc-jwt-payload-nul-term
Open

nul-terminate base64-decoded JWT payload before cJSON_Parse#5543
Kartik (sage-mode-hunter) wants to merge 1 commit into
confluentinc:masterfrom
sage-mode-hunter:oidc-jwt-payload-nul-term

Conversation

@sage-mode-hunter

Copy link
Copy Markdown

The base64url JWT payload decoded in the OIDC token path is left un-terminated:

  • rd_kafka_jwt_b64_decode_payload allocates nbytesdecoded+1 bytes but EVP_DecodeBlock never writes the trailing NUL
  • rd_kafka_oidc_token_try_validate hands that buffer straight to cJSON_Parse, which runs strlen() on it
  • when the base64 payload length is a multiple of 4 (no "=" padding) EVP_DecodeBlock fills every byte, so the last byte stays uninitialized and strlen reads past the heap allocation (ASAN heap-buffer-overflow read on the token endpoint response)

Terminate after a successful decode, matching rd_base64_decode in rdbase64.c. Added a regression case with an unpadded payload to the existing sub-claim unit test.

@sage-mode-hunter
Kartik (sage-mode-hunter) requested a review from a team as a code owner July 1, 2026 08:46
@confluent-cla-assistant

Copy link
Copy Markdown

Please sign the Contributor License Agreement here before this PR can be approved.
❌ sage-mode-hunter
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

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.

1 participant