Skip to content

fix(streams): enforce sender ownership on createStream (#809)#967

Open
jadonamite wants to merge 1 commit into
LabsCrypt:mainfrom
jadonamite:feat/issue-809-createstream-ownership
Open

fix(streams): enforce sender ownership on createStream (#809)#967
jadonamite wants to merge 1 commit into
LabsCrypt:mainfrom
jadonamite:feat/issue-809-createstream-ownership

Conversation

@jadonamite

@jadonamite jadonamite commented Jun 30, 2026

Copy link
Copy Markdown

Fixes #809

Problem

createStream wired requireAuth but never read req.user. It called prisma.stream.upsert keyed only on the client-supplied streamId, whose update branch set { isActive: true }. So any logged-in wallet could:

  • POST { streamId: <someone else's cancelled stream>, ... } and flip isActive back to true (the body's sender/recipient are ignored on update), and
  • insert rows with an arbitrary sender it does not own.

Fix

  • Reject 401 when unauthenticated and 403 when the JWT subject (req.user.publicKey) is not the body sender.
  • Validate sender / recipient / tokenAddress before any DB write.
  • Before the upsert, look up the existing row and reject 403 if it is owned by another wallet, so the update branch can never reactivate or overwrite someone else's stream.

Tests

Added controller tests covering: unauthenticated (401), caller≠sender (403), missing sender (400), and a non-owner attempting to reactivate a victim's cancelled stream (403, no DB write). All stream.controller.test.ts tests pass.

Acceptance criteria

  • createStream rejects (403) when req.user.publicKey is not the body sender
  • The upsert update branch no longer unconditionally sets isActive:true for an existing stream owned by someone else
  • Integration test proving a non-owner cannot reactivate a cancelled stream via POST /v1/streams
  • sender/recipient/tokenAddress validated before any DB write

createStream never read req.user, so any authenticated wallet could POST
an arbitrary sender or flip another owner's cancelled stream back to active
via the upsert update branch (keyed only on client-supplied streamId).

- 401 when unauthenticated; 403 when JWT subject != body sender
- validate sender/recipient/tokenAddress before any DB write
- reject (403) upsert against a streamId already owned by another wallet,
  so the update branch can never reactivate someone else's stream
- add controller tests covering non-owner reactivation and field validation
@jadonamite jadonamite force-pushed the feat/issue-809-createstream-ownership branch from f647c82 to f67e5da Compare June 30, 2026 09:27
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.

[Security] POST /v1/streams (createStream) lets any authenticated wallet reactivate/overwrite arbitrary streams

1 participant