Skip to content

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

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

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

Conversation

@shitratgit

@shitratgit shitratgit Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1921 (base worker/sec165-products); merge #1921 first.

Why (sec-20261125-167, high)

castingwordsWebhookReceiver in skill-lesson serves /api/webhooks/castingwords on epic-web, epic-react and total-typescript. 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 #1921's head. skill-lesson lib/ is 27/27. tsc shows no errors in the changed files (the convertkit.ts errors already exist). 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. scriptkit gets the same change in its own repo. Rotating before this ships would just leak the new key into the next caption track.

shitratgit Bot added 3 commits November 25, 2026 20:47
…ec-165)

The upload flow strips the signature off the presigned PUT and stores the
bare partner-uploads object URL, which Mux, Deepgram, CastingWords and an
external deepgram-wrangler worker then fetched without credentials. That only
worked because the prefix was publicly readable.

presignUploadGet (skill-lesson) signs a short-lived GET for an object in the
app's upload bucket and folder at the moment of the service call: inside
createMuxAsset, the CastingWords order (24h, a human service), and epic-web's
Deepgram provider. originalMediaUrl stays unsigned; replies and errors are
redacted, so no signed URL is stored or returned in step output.

epic-web's tip flow ordered transcripts through deepgram-wrangler on an
account we cannot audit, with the URL in its query string. It now orders
Deepgram directly like process-video-resource, and our Deepgram webhook emits
the transcript-created event the tip flow waits for.
…gned (sec-166)

/api/webhooks/deepgram/transcript trusted the videoResourceId query and
wrote any posted transcript to Sanity, set the video ready, and emitted SRT
events that put captions on the Mux asset. With sec-165 it also emits the
tip transcript event, so a forged call could drive the tip flow too.

The provider now signs the callback URL: an HMAC-SHA256 (NEXTAUTH_SECRET)
over a label, the videoResourceId and a 24h expiry, the same shape as
course-builder's transcription callback (sec-059). The webhook refuses a
missing, forged, expired or other-resource signature with 401 before it
reads anything. The existing skip-if-transcript-exists check keeps a valid
callback one-shot.
…p the API key away from Mux (sec-167)

castingwordsWebhookReceiver is unauthenticated. writeTranscriptToVideoResource
interpolated the posted order into a GROQ query, so a crafted value selected
any videoResource, and the posted audiofile was not tied to that order, so a
forged call could write one video's transcript and captions onto another.
It also handed Mux the CastingWords SRT URL, whose query carries our API key,
as the caption track source.

The lookup is now parameterized and matches only the video resource holding
the exact order and audiofile pair stored from our own order response; an
unmatched pair returns 404 before any CastingWords call or write. The SRT is
fetched server-side, stored under the upload folder, and Mux gets a 6h
presigned GET for it. getSRTText no longer returns the keyed URL.
@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
badass-turbo Ready Ready Preview Nov 26, 2026 5:26am UTC
epic-react-v1 Ready Ready Preview Nov 26, 2026 5:26am UTC
3 Skipped Deployments
Project Deployment Actions Updated
epic-web Ignored Ignored Preview Nov 26, 2026 5:26am UTC
testing-javascript Ignored Ignored Preview Nov 26, 2026 5:26am UTC
total-typescript-turbo Ignored Ignored Preview Nov 26, 2026 5:26am UTC

@joelhooks joelhooks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sec-167: CastingWords webhook bound to the stored order. Tree identical to the security-reviewed fc16c46. SR 🐀

@shitratgit
shitratgit Bot marked this pull request as ready for review November 26, 2026 05:33
@shitratgit
shitratgit Bot merged commit 785054b into main Nov 26, 2026
9 checks passed
@shitratgit
shitratgit Bot deleted the worker/sec167-castingwords branch November 26, 2026 05:33
shitratgit Bot added a commit to skillrecordings/scriptkit that referenced this pull request Nov 26, 2026
…p the API key away from Mux (sec-167) (#44)

* fix(security): sign upload URLs for Mux and CastingWords (sec-165)

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.

* fix(security): bind the CastingWords webhook to our stored order, keep 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.

* fix(skill-lesson): refuse a CastingWords error page as transcript or captions (sec-167 review)

---------

Co-authored-by: shitratgit[bot] <286405550+shitratgit[bot]@users.noreply.github.com>

This branch was successfully deployed

5 active (3 outdated) deployments
Preview – epic-react-v1 — 989c6b58 Deployed Nov 26, 2026 by vercel[bot]
Preview – badass-turbo — 989c6b58 Deployed Nov 26, 2026 by vercel[bot]
Preview – epic-web — fc16c465 Deployed Nov 26, 2026 by vercel[bot]
Preview – total-typescript-turbo — fc16c465 Deployed Nov 26, 2026 by vercel[bot]
Preview – testing-javascript — fc16c465 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.

1 participant