fix(sharing): verified authz on share-link routes (#2851)#2853
Merged
Conversation
The raw-app share-link routes trusted x-user-id/x-tenant-id headers and the service ignored the caller on revoke — so a client could forge link attribution, enumerate another user's link tokens (?createdBy=<victim>, which then resolve records under a system context bypassing RLS), and revoke arbitrary users' links. - Verified identity: SharingServicePlugin derives the caller (+ their positions/permissions) from resolveAuthzContext (session/API key/OAuth), never headers. Route default is SECURE (anonymous). Create/list/revoke require a signed-in principal (401); the public /:token/resolve stays public but keys its audience:'signed_in' check off the verified session, not a spoofable x-user-id. - List scoping: GET /share-links is forced to the caller's own links — no more ?createdBy=<victim> enumeration. - Revoke ownership: revokeLink requires the caller to be the creator (system callers bypass); previously the context was ignored. - Create access check: createLink verifies the record is visible to the caller (read under the caller's RLS) before minting — you can only share a record you can see. ShareLinkExecutionContext gains optional positions/permissions for the record-access check. Companion to #2848 (settings routes). Tests: revoke-ownership (non-owner denied, creator + system allowed), create-access (untrusted caller → 403 for an unseen record, system → 404). plugin-sharing 79 green; spec api-surface unchanged; tsc clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 96 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
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.
Closes #2851. Companion to #2848 (settings routes) — same root cause (a raw-app route registration trusting identity headers). Found by the ADR-0090 D10 adversarial security review.
The hole
The share-link routes (
POST/GET/DELETE /api/v1/share-links, registered bySharingServicePluginon the raw Hono app) derived the caller fromx-user-id/x-tenant-idheaders, and the service ignored the caller context on revoke. So a client could:created_by);GET /api/v1/share-links?createdBy=<victim>→ enumerate another user's link tokens, which then resolve records via the public/:token/resolveunder a system context (RLS bypassed);DELETE→ revoke arbitrary users' links (sharing DoS).The fix
SharingServicePluginderives the caller (and theirpositions/permissions) fromresolveAuthzContext(session / API key / OAuth), never headers. The route default is secure (anonymous). Create / list / revoke require a signed-in principal (401 otherwise). The public/:token/resolvestays public (the token is the authorization) but keys itsaudience: 'signed_in'check off the verified session, not a spoofablex-user-id.GET /api/v1/share-linksis forced to the caller's own links — no more?createdBy=<victim>enumeration.revokeLinkrequires the caller to be the link's creator (system/internal callers bypass).createLinkverifies the record is visible to the caller (read under the caller's own RLS) before minting — you can only share a record you can actually see. (This also hardens the already-verified dispatcher handler, which shares the service.)ShareLinkExecutionContextgains optionalpositions/permissionsso the record-access check evaluates the real principal.Tests
403(no existence leak); a system caller still gets the plain404.plugin-sharing79 green; specapi-surfaceunchanged;tscclean.Behaviour change
Managing share links now requires a real verified credential (which the console already presents). The
contextFromRequestoption remains the escape hatch for bespoke gateways.🤖 Generated with Claude Code