Skip to content

fix: enforce invoice ownership on single-invoice reads (BOLA) - #2

Merged
arko33 merged 6 commits into
mainfrom
fix/bola-guard
Oct 21, 2026
Merged

arko33 merged 6 commits into
mainfrom
fix/bola-guard

Conversation

@arko33

@arko33 arko33 commented Oct 21, 2026

Copy link
Copy Markdown
Owner

What

GET /api/invoices/:id skipped the ownership check whenever SECURE_MODE was not on, so any caller could read another owner's invoice — BOLA / OWASP API1:2023 #1.

Ownership is now enforced unconditionally and the env-var gate is gone, so no deployment can silently turn the hole back on.

-  if (!isSecureMode()) {
-    return { invoice, allowed: true };
-  }
   const allowed = invoice.ownerId === requestingUserId;
   return { invoice, allowed };

Behaviour

Caller Before After
alice → inv-1001 (own) 200 200
bob → inv-1001 (not own) 200 + full payload 403
bob → inv-9999 (missing) 404 404
no x-user-id 401 401

403 vs 404 is preserved so a caller who cannot read an invoice also cannot probe whether the id exists.

Also in this PR

  • docs/openapi.json — the contract the TestSprite suite is built from (invoices + health + autopsy, inline schemas, no $ref)
  • docs/test-prd.md — the PRD the generated tests assert against
  • README no longer documents SECURE_MODE; there is nothing to configure

Verification

curl -H "x-user-id: bob" https://ghostinthecodebase.vercel.app/api/invoices/inv-1001   # 403 after merge

Typecheck passes (npx tsc --noEmit). The TestSprite suite pins all four rows above.

GET /api/invoices/:id skipped the ownership check whenever SECURE_MODE was
not 'on', so any caller could read another owner's invoice (BOLA / OWASP
API1:2023 #1). Ownership is now enforced unconditionally and the env-var gate
is gone, so no deployment can silently turn the hole back on.

403 for 'exists but not owned' and 404 for 'missing' are unchanged.
Adds the spec the TestSprite project is built from (invoices + health +
autopsy, inline schemas) and the PRD the generated tests assert against.
@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ghostinthecodebase Ready Ready Preview Oct 21, 2026 12:37am UTC

@testsprite

testsprite Bot commented Oct 21, 2026

Copy link
Copy Markdown

Running Test Run In Progress

TestSprite has queued 13 tests for ghostinthecodebase and will run them against this PR's deployment: https://ghostinthecodebase-git-fix-bola-guard-ako-7127.vercel.app.

This comment will update automatically when the run completes. View Execution Live ↗


Automated end-to-end testing powered by TestSprite

@arko33
arko33 merged commit 7635f0e into main Oct 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant