Repository navigation
fix: OIDC accepts valid tokens again (#273) - #283
Merged
Merged
Conversation
- Run a mock OIDC issuer on 127.0.0.1 (discovery document and a JWKS with RSA keys) and the real flapi binary with auth.type oidc for REST and mcp.auth.type oidc for MCP - Sign RS256 tokens in the test: a valid token must get 200 and its sub and roles must reach the template as auth.username / auth.roles; a key rotated into the JWKS must be picked up; MCP tools/call must succeed - Refuse a bad signature, a foreign key with a known kid, wrong issuer, wrong audience, expired, missing exp, missing sub, unknown kid (after a JWKS refetch), alg none and garbage, on REST and MCP - Fails today: every valid token gets 401, the log says "JWT header missing 'alg' field" - Add cryptography to the integration test dependencies
- decodeJWT returned std::make_pair(header, payload): copies of the crow
rvalues. A copied rvalue does not own the buffer it points into; the
originals freed it on return, so header.has("alg") read freed memory
and every token got 401 ("JWT header missing 'alg' field")
- Add DecodedJWT: it holds the owning roots, cannot be copied, and a move
hands the buffer over, so the parsed values cannot outlive their text;
validateToken reads them by reference
- Decode rejects tokens that are not three parts or whose header/payload
are not JSON objects, and drops the unused jwt::decode call
- Check kid/alg/email_verified types before reading them, and refuse a
token without exp by name instead of through the zero time_point
- Unit tests read the decoded values after the decoding scope is gone and
the heap churned; the E2E test now passes (REST and MCP)
- CHANGELOG: OIDC: valid tokens were rejected (#273)
- The authentication guide keeps one line saying v26.11.25 rejected every token; the MCP guide points at OIDC as a working option
jrosskopf
force-pushed
the
fix/gh-273-oidc-decode
branch
from
November 25, 2026 16:24
30707ce to
2363c25
Compare
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
auth.type: oidc(REST) ormcp.auth.type: oidc(MCP), every token got 401, valid ones included.OIDCAuthHandler::decodeJWTreturnedstd::make_pair(header, payload), i.e. copies of thecrow::json::rvalueroots. A copied rvalue does not own the buffer it points into (crow'sr_stringcopy clearsowned_). The originals freed that buffer on return, soheader.has("alg")read freed memory and the log saidJWT header missing 'alg' field. ASAN on the same pattern reportsheap-use-after-free.DecodedJWTtype: it holds the owning roots, copying is deleted, and a move hands the buffer over, so the parsed values cannot outlive their text.validateTokenreads them by reference.Decodealso rejects tokens that are not exactly three parts or whose header/payload are not JSON objects. The unusedjwt::decodecall is gone.kid/alg/email_verifiedare type-checked before they are read (.s()/.b()threw on the wrong type), and a token withoutexpis refused by name instead of through the zerotime_point.src/for the same pattern: rvalues returned or stored by value, children of a temporaryload(), and by-value rvalue parameters.decodeJWTwas the only instance. JWKS (oidc_jwks_manager.cpp) and discovery parsing keep their root alive while they read from it.Test plan
test/integration/test_oidc_e2e.py. It runs a mock issuer on 127.0.0.1 (discovery + JWKS, RSA keys) and the real binary, and signs RS256 tokens itself.subandrolesreach the template asauth.username/auth.roles, an audience list works, and a key rotated into the JWKS is picked up.tools/callwith a valid token succeeds, andallowed-rolesgates on the OIDC roles (403 without the role).OIDC error: JWT header missing 'alg' field) and every refusal passes. Green with the fix: 20 passed.test/cpp/oidc_decode_jwt_test.cpp. It reads the decoded values after the decoding scope is gone and the heap has been churned, checks moved objects and malformed tokens, andstatic_asserts that the type is not copyable.ctest -R "oidc|auth|decode": 64/64 passed.check_skills.py --static-only: passed.cryptographyis added to the integration test dependencies (uv.lockupdated).Closes #273
🤖 Generated with Claude Code
https://claude.ai/code/session_018txuxF9jXyiKakpUoXrKBi
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.