fix(api): require admin on /coupons/redeem and /clicks ingest (authz gap) - #61
Open
keithfawcett wants to merge 1 commit into
Open
fix(api): require admin on /coupons/redeem and /clicks ingest (authz gap)#61keithfawcett wants to merge 1 commit into
keithfawcett wants to merge 1 commit into
Conversation
…gap)
/coupons/redeem was gated only by requireAuth + grantScope('events:write').
grantScope is a pass-through for any non-scoped principal, so a logged-in
PARTNER (session or partner API key) reached the handler and could forge
conversions — synthesizing Click+Identity+Event and minting commissions
crediting themselves. /clicks had the same shape (grantScope('clicks:write')
with no role gate); lower impact since the handler derives partner/program
from the Link row, but it's still a server-to-server ingest route that must
not accept partner principals.
Both now match the sibling /attribution/events route: requireAuth →
grantScope → requireAdmin. Scoped federation keys (clicks:write /
events:write) still work — grantScope rewrites them to admin before
requireAdmin runs. Added regression tests asserting a partner key gets 403
while admin/scoped reaches the handler.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
Two server-to-server ingest routes were missing the
requireAdmingate that their sibling/attribution/eventsroute has.Critical —
/coupons/redeem. Gated only byrequireAuth+grantScope('events:write').grantScopeis a pass-through for any non-scoped principal (auth.ts:170), andrequireAuthadmits partner sessions and partner API keys. So a logged-in partner reached the handler and could POST an arbitraryuserId/value/code→ the handler synthesizes Click+Identity+Event and runs attribution → mints commissions crediting themselves, which then auto-approve and reach payout.Lower —
/clicks. Same shape (grantScope('clicks:write'), no role gate). Impact is smaller because the handler derivespartnerId/programIdfrom the Link row rather than caller input, so a partner can't credit themselves — only inflate click counts or create clicks crediting a link's real owner. Still a server-to-server route that shouldn't accept partner principals.Surfaced by an unsteered Codex review of the whole app.
Fix
Both routes now match
/attribution/events:requireAuth → grantScope(...) → requireAdmin. Scoped federation keys (clicks:write/events:write) are unaffected —grantScoperewrites a valid scoped key toadminbeforerequireAdminruns, so the Network federation path and CRM/Zapier integrations keep working. Only bare partner/non-admin principals are now rejected.Tests
New regression cases in
integration.test.ts: a minted partner key gets 403 on both routes, while the admin key passes auth and reaches the handler (404 on the unknown coupon/link). Full typecheck clean; the two new tests pass alongside the existing integration suite.Notes
Independent of #60 (branched off
main). This is one item from a broader payment/subscription + whole-app audit; the remaining findings (e.g.PartnerProgramRLS, SSRF on webhook/postback URLs, entitlement/revenue leaks) are being triaged separately.🤖 Generated with Claude Code