Skip to content

fix(security): bind the CastingWords webhook to our stored order, keep the API key away from Mux (sec-167) - #44

Merged
shitratgit[bot] merged 4 commits into
mainfrom
worker/sec167-castingwords
Nov 26, 2026
Merged

shitratgit[bot] merged 4 commits into
mainfrom
worker/sec167-castingwords

Conversation

@shitratgit

@shitratgit shitratgit Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Stacked on #43 (base worker/sec165-scriptkit); merge #43 first. Same change as skillrecordings/products#1922.

Why (sec-20261125-167, high)

castingwordsWebhookReceiver in skill-lesson serves /api/webhooks/castingwords on scriptkit. It authenticates nothing, and writeTranscriptToVideoResource:

  1. GROQ injection: builds *[_type == "videoResource" && castingwords.orderId == "${order}"][0] from the posted order, so a crafted value selects any videoResource, which then gets patched.
  2. Cross-video writes: the posted audiofile isn't tied to that order, so a forged call can write video A's transcript and captions onto video B.
  3. Key leak: hands Mux createTrack({url: srtUrl}), where srtUrl is the CastingWords SRT URL with api_key=<CASTINGWORDS_API_TOKEN> in its query. Every caption track created this way stored our key on Mux's side.

What

  • Bound lookup: *[_type == "videoResource" && castingwords.orderId == $order && castingwords.audioFileId in [$audiofile, $audiofileNumber]][0], with parameters. Only the resource holding the exact pair we stored from our own order response (updateVideoResourceWithTranscriptOrderId) matches.
    • An unmatched pair returns 404 before any CastingWords call or Sanity write.
    • A replayed genuine pair just re-fetches the correct transcript into the correct resource.
    • CastingWords can't sign webhooks, and no account change is needed.
  • Captions: the SRT is fetched server-side, and storeCaptionForMux puts it at partner-uploads/captions/<videoResourceId>/<audiofile>.srt with the upload key. That key has PutObject, and GetObject since sec-165. Mux gets a 6h presigned GET for it. If the bucket isn't configured, no track is created and a warning is logged, rather than falling back to the keyed URL. Mux errors are redacted.
  • getSRTText now returns {srt} only, so the keyed URL never leaves the request. audiofile is URL-encoded in both CastingWords fetches.

Tests

lib/castingwords-webhook.test.ts (4):

  • The query takes order and audiofile as parameters, and an injection string isn't interpolated.
  • An unmatched pair returns 404 with no CastingWords fetch, no write and no track.
  • A matched pair writes, PUTs the SRT to the captions key, and gives Mux a presigned S3 URL with no castingwords.com and no token.
  • With no bucket, no track is created.

All 4 fail on #43's head. skill-lesson lib/ is 27/27. tsc shows no errors in the changed files. prettier is clean.

After deploy

The secret cell rotates CASTINGWORDS_API_TOKEN and sets the new value on epic-web, total-typescript-turbo and scriptkit. Rotating before this ships would just leak the new key into the next caption track.

shitratgit Bot added 2 commits November 25, 2026 20:50
skill-api returns the bare partner-uploads object URL as publicUrl, and the
Sanity videoResource webhook hands it to Mux and CastingWords, which fetched
it without credentials because the prefix was publicly readable.

presignUploadGet signs a short-lived GET for an object in the app's upload
bucket and folder at the moment of the call: inside createMuxAsset (6h) and
the CastingWords order (24h). originalMediaUrl stays unsigned and Mux errors
are redacted. Same change as skillrecordings/products#1921.
…p the API key away from Mux (sec-167)

Same change as skillrecordings/products#1922: a parameterized lookup that
only matches the video resource holding the exact order and audiofile pair we
stored when ordering (404 otherwise, before any CastingWords call or write),
and captions handed to Mux as a presigned GET on our own S3 object instead of
the CastingWords SRT URL carrying our API key.
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
scriptkit Ready Ready Preview Nov 26, 2026 5:46am UTC

@shitratgit
shitratgit Bot changed the base branch from worker/sec165-scriptkit to main November 26, 2026 05:43
@shitratgit
shitratgit Bot marked this pull request as ready for review November 26, 2026 05:44
@shitratgit
shitratgit Bot merged commit 44f1ef5 into main Nov 26, 2026
3 of 4 checks passed

This branch was successfully deployed

1 active deployment
Preview — f8d4c413 Deployed Nov 26, 2026 by vercel[bot]
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.

0 participants