Repository navigation
feat(oauth2): RFC 8707 resource indicators bind token audience (Wave 2a) - #421
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2732d8b7f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // The device-code lookup (Mapper::findBy + atomic consume) is the same | ||
| // for both; wrapped in a local lambda so both paths converge on it. | ||
| auto runDeviceCodeLookup = [plugin, sharedCb, clientId, deviceCodeHash, dbClient]() { | ||
| auto runDeviceCodeLookup = [plugin, sharedCb, clientId, deviceCodeHash, deviceResource, dbClient]() { |
There was a problem hiding this comment.
Migrate the touched device-code lookup into a repository
This change modifies the device-code lookup and its database callbacks while retaining direct Mapper access in the controller. libs/drogon/AGENTS.md explicitly requires migrating existing direct queries when they are touched; the historical exception does not waive that migrate-on-touch requirement. Move the affected lookup/consume operation behind a repository or Domain service and pass the resource indicator through that interface.
AGENTS.md reference: libs/drogon/AGENTS.md:L105-L107
Useful? React with 👍 / 👎.
| if (resource.find_first_of(" \t\r\n") != std::string::npos) | ||
| { | ||
| return "resource must not contain whitespace"; | ||
| } | ||
|
|
||
| return std::nullopt; |
There was a problem hiding this comment.
Validate the URI remainder before accepting a resource indicator
For malformed resources such as https://api.example/%GG or https://[not-an-ip]/, this validator returns success because it only checks the scheme, fragment, and a few whitespace characters. I confirmed both inputs are accepted by compiling and running the extracted validator. Consequently, the token endpoint issues tokens with malformed audiences instead of returning the documented invalid_target response. Validate the complete absolute-URI syntax, including percent escapes and authority syntax, before accepting the indicator.
Useful? React with 👍 / 👎.
Thread an optional RFC 8707 §2 `resource` parameter through the token endpoint's four grants. A valid indicator overrides the P0-4 default audience (aud = client id) on the issued access token and rebinds on refresh; absent parameters keep existing behavior byte-for-byte. Malformed indicators are rejected with the new RFC 8707 protocol error invalid_target (400) before any grant dispatch. The device grant also gains the P0-4 default audience stamp the code/CC paths already had. - TokenService/Plugin: source-compatible trailing defaulted `resource` params on exchangeCodeForToken / exchangeCodeForAuthenticatedClient / refreshAccessToken. api-diff baseline approved with --force: the 6 modified declaration lines only append trailing default parameters (source-compatible; precedent: generateAuthorizationCode authTime/amr/orgId). - RuleSet::validateResourceIndicator: RFC 3986 absolute-URI scheme parse (scheme = ALPHA *( ALPHA / DIGIT / + / - / . ) ':'), no fragment, no whitespace, <=255 chars (audience column limit). - Postgres saveAccessToken persists audience like insertPair already does (single-token path parity). - invalid_target 8-place sync: ErrorCatalog (13->14), regression + property test code lists, api-reference §5.2 table, frontends zh-CN/en catalogs (admin+user), crossAppConsistency code domain, openapi.yaml (TokenRequest.resource + 400 description), C++ doc registration, openapi.json + Python/Go/TS SDK regenerated. - Tests: TokenServiceTest exchange/refresh audience override (gtest), RuleSet indicator validation (7 DROGON cases), live-routing B3 invalid_target case; ErrorCatalogDoc OAuth table test green. Local verification: 36 TokenServiceTest gtests pass, 12 targeted DROGON cases pass, local-gates.sh 6/6 green, spec-governance OK, clients-sdk drift OK, naming gate OK.
- CategoryA initorder token-endpoint snapshot: 7 -> 8 query params (resource indicator joins grant_type/code/refresh_token/client_id/ client_secret/redirect_uri/code_verifier in the registered set). - website llms-full.txt regenerated (+1 line: the invalid_target row in docs/domains/api-reference.md) to satisfy the freshness gate.
Summary
Completes the remaining half of AI-productization Wave 2a (design:
docs-local/designs/ai/v1.5.0-ai-productization-design.md; RFC 9207issalready landed via a373cd5). Implements RFC 8707 §2 resource indicators at the token endpoint so an MCP-compliant resource server can verify audience binding — the exact confused-deputy defense the MCP spec (2026-07-28) makes mandatory for its ecosystem.Behavior
resourceform parameter accepted on all four grants (authorization_code / refresh_token / client_credentials / device_code) atPOST /oauth2/token.aud) is the resource URI, overriding the P0-4 defaultaud = client_id; absent → byte-for-byte existing behavior (pure opt-in).resource(RFC 8707 §2.1); id_tokenaudsemantics unchanged (still client_id).invalid_target(400, RFC 6749 §5.2 envelope), validated once before the F-017/F-018 gates so all grants share semantics.saveAccessTokennow persistsaudiencelike the pair insert already did.Sync checklist (invalid_target + openapi)
ErrorCatalog.ccOAuth table 13→14 +kRequiredOAuthCodes13→14ErrorCatalogRegressionTest/ErrorCatalogPropertyTestcode listsdocs/domains/api-reference.md§5.2 row (ErrorCatalogDocTestgreen)zh-CN/en× admin/user (crossAppConsistency property test + i18nKeys parity green)openapi.yamlTokenRequest.resource + 400 description; C++ doc registration;openapi.jsonregenerated; Python/Go/TS SDK regenerated (drift gate green)--force— 6 modified declaration lines only append trailing defaulted parameters (source-compatible; precedent:generateAuthorizationCodeauthTime/amr/orgId)Tests
TokenServiceTest: exchange + refresh audience override (gtest, 36/36 suite green)RuleSetresource-indicator validation: 7 new DROGON cases (RFC 3986 scheme parse — acceptshttps:/urn:, rejects relative/fragment/whitespace/>255/bad-scheme)OAuth2ProtocolEndpointRfcComplianceTestB3: liveinvalid_targetrouting caselocal-gates.sh6/6 green; naming gate greenOut of scope (by design)