fix: return 403 Forbidden for origin validation failures#2911
fix: return 403 Forbidden for origin validation failures#2911amikofalvy merged 3 commits intomainfrom
Conversation
…on failures When a web_client app's origin doesn't match allowedDomains, the error response was a misleading 401 "Invalid Token" (rendered as internal_server_error). Now throws createApiError with code 'forbidden' and message 'Origin not allowed for this app', matching the existing pattern in the anonymous session route. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 28f89b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
TL;DR — Origin validation failures for Key changes
Summary | 3 files | 3 commits | base:
In
|
There was a problem hiding this comment.
Clean, well-scoped fix. The change from returning a failure result to throwing createApiError({ code: 'forbidden' }) is correct — the thrown HTTPException propagates cleanly through the catch block at runAuth.ts:998-1001 which re-throws HTTPException instances. This matches the existing pattern in auth.ts:173 and is consistent with how JWT verification failures are already handled at line 638. The test mock update to use vi.importActual for createApiError is the right approach since the real implementation is now exercised in the origin-rejection path. No concerns.
Claude Opus | 𝕏
There was a problem hiding this comment.
New commit is indentation-only (fixing the mock return object alignment). No functional changes. Approval stands.
Claude Opus | 𝕏
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
No documentation updates needed for this fix. The existing App Credentials docs describe the domain allowlist feature without specifying error codes, and this improvement aligns the API behavior with standard HTTP semantics (403 for origin restrictions). |
Ito Test Report ✅14 test cases ran. 14 passed. All 14 origin-validation and app-credential tests passed (14/14) in local verification, confirming that allowed-origin anonymous session minting works and legitimate wildcard subdomains (for example, *.example.com) are correctly accepted on protected Run endpoints. The run also verified strong deny behavior and stability: disallowed or missing Origin headers consistently returned explicit 403 forbidden with the expected origin-denied contract across chat and conversation routes (including burst and mobile attempts), while spoofed/lookalike origins, cross-origin token replay, cross-app token/app-id mismatch, and disallowed deep-link conversation reads were blocked with no data leakage, port matching remained strict, and requests without x-inkeep-app-id stayed on the non-app auth path. ✅ Passed (14)Commit: Tell us how we did: Give Ito Feedback |
* fix: return 403 Forbidden with actionable message for origin validation failures When a web_client app's origin doesn't match allowedDomains, the error response was a misleading 401 "Invalid Token" (rendered as internal_server_error). Now throws createApiError with code 'forbidden' and message 'Origin not allowed for this app', matching the existing pattern in the anonymous session route. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * style: auto-format with biome * add changeset for origin validation error fix Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary
web_clientapp's origin doesn't matchallowedDomains, the API now returns a clear403 Forbiddenwith"Origin not allowed for this app"instead of a misleading401with"Invalid Token"(which was rendered asinternal_server_error)auth.ts:173)createApiError()directly fromtryAppCredentialAuthinstead of returning a failure result, consistent with JWT verification failures at line 638Before
{ "code": "internal_server_error", "status": 401, "detail": "Error processing request: Invalid Token" }After
{ "code": "forbidden", "status": 403, "detail": "Origin not allowed for this app" }Test plan
app-credential-auth.test.ts— "should reject when origin is not allowed" now asserts 403 +forbiddencode + correct detail message🤖 Generated with Claude Code