Skip to content

fix(security): bin owner tokens and reject framing headers in /response-headers - #275

Merged
jaredwray merged 7 commits into
mainfrom
cursor/bin-owner-tokens-framing-headers-5d37
Nov 19, 2026
Merged

jaredwray merged 7 commits into
mainfrom
cursor/bin-owner-tokens-framing-headers-5d37

Conversation

@jaredwray

@jaredwray jaredwray commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Breaking change. Management routes for bins now require an owner token.

Migration

POST /bins returns token one time. The server stores only the SHA-256 hash.

Send the token on later management calls:

Authorization: Bearer <token>

This header is required for these routes:

  • GET /bins
  • GET /bins/:id
  • GET /bins/:id/requests
  • GET /bins/:id/requests/:reqId
  • DELETE /bins/:id/requests
  • DELETE /bins/:id

Send no token and the route returns HTTP 401. Send a token that does not match and the route returns HTTP 404. A missing bin returns the same HTTP 404. The body does not show that the bin exists.

GET /bins returns only the bin for the presented token. It does not return other bins.

The capture route /b/:id stays open. Do not send the owner token there.

In-process mock.bins methods do not require the token. createBin() also returns token.

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce?

Bug fix. This is a breaking API change.

Findings fixed

HIGH 1. Bins had no access control. The audit commit is 6abbcb83. Any caller could list, read, clear, and delete any bin, including captured Authorization, Cookie, and stripe-signature headers. POST /bins now returns a 32-byte owner token in base64url. The store keeps the SHA-256 hash. Management routes compare that hash with crypto.timingSafeEqual.

HIGH 2. GET /response-headers?trailer=x, or a POST body with a trailer key, crashed the process with ERR_HTTP_TRAILER_INVALID when helmet is on. With http2 on, transfer-encoding, keep-alive, and upgrade also crashed it. The route now accepts only an RFC 7230 header name. It rejects trailer, transfer-encoding, content-length, connection, keep-alive, upgrade, te, proxy-connection, host, and a name that starts with :. The response is HTTP 400 JSON. reply.header is wrapped, so a remaining invalid header does not abort the process.

Out of scope

These findings stay out of scope: bin size limits, /range amplification, the /healthz leak, the TLS listener, and PEM echo.

Test evidence

pnpm test passed. 588 tests passed. 1 test skipped. Line coverage is 100%.

Test audit

The new tests protect caller-visible contracts. The old tests do not cover those contracts.

Rewrote GET /bins lists created bins. The old test protected public enumeration. That contract is the vulnerability. The new test checks that the list contains only the bin for the presented token.

Rewrote the unknown-bin 404 cases so they send a bearer token. A request with no token now returns 401. The 404 contract remains when a token does not match.

Updated the worker tests that read, list, or delete a bin. They now send the owner token. They still protect storage behavior.

Changed the worker runtime list check from HTTP 200 with an empty list to HTTP 401.

Added tests for a prototype response key, invalid JSON on /response-headers, a full one-character id space, a stale token on a replacement bin, two stores that share one Keyv, and a rejected fractional idLength.

No test was deleted.

Open in Web Open in Cursor 

cursoragent and others added 2 commits November 18, 2026 19:33
POST /bins returns a random owner token one time.
The store keeps only the SHA-256 hash.
Send the token as Authorization: Bearer on management routes.

A missing token returns HTTP 401.
A wrong token returns HTTP 404, the same as a missing bin.
GET /bins returns only the bin for that token.
The capture route stays open.

Co-authored-by: Jared Wray <me@jaredwray.com>
The route accepts only an RFC 7230 header name.
It rejects framing names and a name that starts with a colon.
An invalid header returns HTTP 400.
The process stays up.

Co-authored-by: Jared Wray <me@jaredwray.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T19:35:28.476585Z 252b3cc PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread src/mock-http-bins.ts
Comment on lines +149 to +150
const matches = ownerHashMatches(doc?.tokenHash, token);
if (!doc || !matches) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium - Existing persisted bins become inaccessible after upgrade

When a deployment upgrades while its Keyv store still contains bins created before owner-token support, those documents have no tokenHash and every HTTP management request is denied as unauthorized to the bin. Because captures and ordinary updates preserve the legacy document without assigning a token, existing captured requests cannot be read, cleared, or deleted through the documented management API until the bins expire, with persistent Worker/Mongo bins affected across deployments.

Show fix

Provide a migration or compatibility path for legacy documents before enforcing ownership, such as assigning and exposing a new owner token for each legacy bin during upgrade, or explicitly migrate/expire and communicate the affected records. Ensure the migration persists the token hash so subsequent captures retain manageable ownership.

More info - Reply on this comment to give feedback or ignore the issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior is intentional. Do not add a migration that issues a new token.

A bin saved before this change has no owner. ownerHashMatches returns false when tokenHash is missing (src/mock-http-bins.ts, lines 33-44). authorizeOwner then returns { ok: false } (lines 149-151). The management route sends HTTP 404 when the caller presents a token, and HTTP 401 when the caller sends no token. The two results do not show that the bin exists.

There is no previous owner who can receive a new token. If the first caller receives a token, anonymous access returns. That is the defect this change closes.

The capture route stays open and does not mint a token. A capture must not become the owner.

The default bin lifetime is 24 hours. Keyv drops the old bin at the end of that lifetime. The pull request states this break at the top. In-process mock.bins methods can still read a bin in this process. They do not use the HTTP token.

Comment thread src/routes/bins/management.ts Resolved
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (63314dc) to head (59902c5).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #275    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           44        44            
  Lines         1865      2012   +147     
  Branches       409       434    +25     
==========================================
+ Hits          1865      2012   +147     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

cursoragent and others added 2 commits November 18, 2026 19:41
The echo object uses a null prototype, so the key stays an own field.
Rollback removes each header that the route already set.
A strict 400 schema no longer turns other 400 responses into HTTP 500.

Co-authored-by: Jared Wray <me@jaredwray.com>
createBin does not replace an id that is already in use.
A read, clear, or delete checks the token on that same document.
A stale token cannot act on a replacement bin.

Co-authored-by: Jared Wray <me@jaredwray.com>
Comment thread src/mock-http-bins.ts Resolved
A bin id of length 4 or less walks the whole space.
Create fails only when every id is already in use.
A long id still uses a small number of random attempts.

Co-authored-by: Jared Wray <me@jaredwray.com>
Comment thread src/mock-http-bins.ts Resolved
Comment thread src/mock-http-bins.ts Resolved
cursoragent and others added 2 commits November 18, 2026 19:55
Two stores that share one Keyv wait on the same bin id.
A second create does not replace the first bin.
idLength must be a positive integer. A fraction throws at construction.

Co-authored-by: Jared Wray <me@jaredwray.com>
Keep main's header error text.
Reject content-length and host as well as the names from main.
A bad header value returns HTTP 400.

Co-authored-by: Jared Wray <me@jaredwray.com>
@jaredwray
jaredwray merged commit ac04632 into main Nov 19, 2026
14 checks passed
@jaredwray
jaredwray deleted the cursor/bin-owner-tokens-framing-headers-5d37 branch November 19, 2026 07:53
@jaredwray jaredwray mentioned this pull request Nov 19, 2026
7 tasks done
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.

2 participants