Repository navigation
fix(gateway): clients can identify authorization failures - #110925
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8158ea43a
ℹ️ 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".
| and can change except where a compatibility note says otherwise. Method-level | ||
| authorization failures use top-level `code: "FORBIDDEN"` with one of these | ||
| structured detail shapes: |
There was a problem hiding this comment.
Convert remaining method-level scope denials to FORBIDDEN
When a caller passes the method's base scope but fails a secondary authorization check, this documented contract is still false: talk.config with includeSecrets returns INVALID_REQUEST without details at src/gateway/server-methods/talk.ts:725-731, and admin-only node.invoke commands do the same at src/gateway/server-methods/nodes.ts:1450-1458 (the embedded agent reset check at src/gateway/server-methods/agent-reset-phase.ts:76-81 is another instance). Clients therefore still need message parsing for several method-level missing-scope failures; route these checks through missingScopeErrorShape as well.
Useful? React with 👍 / 👎.
| missingScopeErrorShape({ | ||
| missingScope: approved.missingScope, | ||
| requiredScopes: [approved.missingScope], | ||
| }), |
There was a problem hiding this comment.
Return the full pairing scope set
For a node request declaring commands such as system.run, resolveNodePairApprovalScopes requires both operator.pairing and operator.admin, but this response reports only whichever scope failed first. A caller missing both is told that requiredScopes is only operator.pairing, then encounters a second denial after granting it, contradicting the new contract that this field contains the complete known set. Preserve and return the full approval scope list from approveNodePairing instead of constructing it from missingScope.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4671a42b01
ℹ️ 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".
| const resolvedRequiredScopes = isOperatorScope(registeredScope) | ||
| ? [registeredScope] | ||
| : resolveLeastPrivilegeOperatorScopesForMethod(method, params); | ||
| return missingScopeErrorShape({ |
There was a problem hiding this comment.
Preserve the node diagnostics authentication fallback
When a locally stored device token's recorded scopes pass the CLI preflight but the gateway's current pairing has since been narrowed or revoked, node.list and node.describe now throw GatewayClientRequestError with gatewayCode: "FORBIDDEN" and detail code MISSING_SCOPE. The fallback predicate in src/cli/nodes-cli/rpc.ts:47-65 recognizes only the legacy INVALID_REQUEST response or connect-auth detail codes, so callNodeDiagnosticsGatewayCli rethrows instead of trying local shared auth and ordinary credentials. Update that predicate to recognize the new structured missing-scope response.
Useful? React with 👍 / 👎.
| requiredScopes: readonly string[]; | ||
| }): ErrorShape { | ||
| const details = buildMissingScopeErrorDetails(params); | ||
| return errorShape(ErrorCodes.FORBIDDEN, `missing scope: ${params.missingScope}`, { details }); |
There was a problem hiding this comment.
Map FORBIDDEN admin RPC responses to HTTP 403
When a trusted-proxy caller supplies a narrowed x-openclaw-scopes header and invokes an allowlisted Admin HTTP RPC method requiring a scope it lacks, this new error reaches extensions/admin-http-rpc/src/handler.ts:45-66, whose status switch has no FORBIDDEN case and therefore returns HTTP 500. This misclassifies a caller authorization failure as a server fault and can trigger incorrect retries or alerts; add the new code to that adapter's error-code set and map it to 403.
Useful? React with 👍 / 👎.
4671a42 to
908d91b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 908d91b1a4
ℹ️ 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".
| const resolvedRequiredScopes = isOperatorScope(registeredScope) | ||
| ? [registeredScope] | ||
| : resolveLeastPrivilegeOperatorScopesForMethod(method, params); | ||
| return missingScopeErrorShape({ |
There was a problem hiding this comment.
Handle FORBIDDEN in the question-list unavailable path
When a Swift chat client reconnects after operator.questions has been removed, question.list now returns FORBIDDEN, but questionListIsUnavailable only recognizes INVALID_REQUEST at apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift:397-400. The error therefore falls into the best-effort catch instead of the branch that clears existing question cards, leaving stale actionable cards visible until local expiry; update that client predicate to recognize the new structured missing-scope response.
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 4:44 PM ET / 20:44 UTC. Summary PR surface: Source +92, Tests +106, Docs +15, Generated 0, Other +23. Total +236 across 18 files. Reproducibility: yes. from source with medium confidence: invoke a gateway method through the affected CLI, Admin HTTP RPC, Swift question-list, or remaining scope-denial paths after it returns the new Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Make one canonical structured authorization-error path, migrate every gateway denial and downstream legacy-code consumer to it, and add focused regression coverage for WebSocket, HTTP, CLI fallback, Admin HTTP RPC, and Swift recovery behavior. Do we have a high-confidence way to reproduce the issue? Yes, from source with medium confidence: invoke a gateway method through the affected CLI, Admin HTTP RPC, Swift question-list, or remaining scope-denial paths after it returns the new Is this the best way to solve the issue? No, not yet. The structured protocol shape is a maintainable solution, but it must be applied consistently to all method-level authorization denials and existing consumers before it replaces the legacy error code. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 42bacaa112c5. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +92, Tests +106, Docs +15, Generated 0, Other +23. Total +236 across 18 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Merged via squash.
|
…10925) * fix(gateway): structure authorization errors * test(gateway): align authorization contracts * fix(gateway): regenerate protocol bindings * fix(gateway): preserve optional scope errors * fix(gateway): report complete pairing scopes * style(gateway): format protocol exports
…10925) * fix(gateway): structure authorization errors * test(gateway): align authorization contracts * fix(gateway): regenerate protocol bindings * fix(gateway): preserve optional scope errors * fix(gateway): report complete pairing scopes * style(gateway): format protocol exports
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where gateway clients received only free-form strings for method-level authorization failures, forcing third-party clients to parse messages to identify missing scopes. PinchChat added exactly such a parser in commit 3d5a897 to provide actionable guidance.
Why This Change Was Made
Method-level authorization failures now use the semantic
FORBIDDENcode and additiveMISSING_SCOPEdetails containing the missing scope and complete known required scope set. The legacymissing scope: <scope>message remains unchanged for compatibility. HTTP 403 scope responses mirror the structured details when a concrete scope is available and preserve the prior fallback otherwise. Node-pairing approval failures report both pairing and additional admin requirements when applicable.While this PR was in flight, main moved webchat session mutations onto the ordinary operator-scope policy. The obsolete client-mode-specific rejection and proposed discriminator were therefore dropped; webchat mutation failures now receive the same
MISSING_SCOPEcontract as other RPCs. Protocol schemas, generated Swift bindings, SDK exports, and docs expose the new additive contract. No protocol version bump is needed.User Impact
Gateway clients can show reliable, actionable authorization guidance without regex-parsing human-readable messages. Older clients continue to receive the legacy missing-scope text.
Release-note context: gateway authorization failures now include structured missing-scope details for third-party clients.
Evidence
FORBIDDENwith the unchanged message and exactMISSING_SCOPE,missingScope, andrequiredScopesfields.pnpm check:changedpassed on Blacksmith Testbox.openclaw/ci-gate.