Repository navigation
fix(tts-audio): sign a JWT for the Admin API and fix two hidden read bugs - #282
Merged
Merged
Conversation
…bugs
Every Admin API call sent `Authorization: Ghost <id>:<secret>`. That header takes a
**signed JWT**, so Ghost answered `400 INVALID_JWT` on every request — a message
that reads exactly like a revoked key, which sent hours of debugging at the
credential instead of at the request. Ghost's own source is unambiguous:
const decoded = jwt.decode(token, { complete: true });
if (!decoded || !decoded.header) throw BadRequestError({ code: 'INVALID_JWT' });
The unit tests never caught it because the fake `fetch` did not inspect headers.
- sign an HS256 token per request: header `{ alg, typ, kid }`, payload
`{ iat, exp, aud: "/admin/" }`, HMAC key = the **hex-decoded** secret.
A non-`id:secret` key or a non-hex secret now fails loudly instead of producing
a token that looks fine and is rejected.
- new test/auth.test.mjs decodes the header the worker builds and verifies the
signature the way Ghost does, plus asserts no call path sends the raw key.
- backfill shares the same header builder instead of its own copy.
Two more bugs the fix immediately exposed, both only reachable once auth worked:
- **locale was matched on tag *name***. This publication names its locale tags
"Español"/"English" and slugs them `es`/`en`, so every real post was judged
ineligible: the live backfill reported 0 of 221 eligible. Match the slug, which
is what routes.yaml filters on, and fall back to the name only when a webhook
payload omits it.
- **`?formats=html,md` is not a valid request**. Ghost accepts html, mobiledoc,
lexical and plaintext and answers 422 for `md`. Use `plaintext`, which is
derived from the same stored source and is what the drift check wants.
Verified against the live publication with a real key: the signed token returns
200 on /settings/ and /posts/, readPost returns a real 15.7k-character post with
locale `es`, the code-injection PUT is accepted, and the backfill dry-run now
classifies all 221 posts (was 0).
Collaborator
Author
On the CodeQL alert (
|
ngeorger
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three defects, all found by inspecting the running cluster rather than the code.
The original bug
Every Admin API call sent
Authorization: Ghost <id>:<secret>. That header takes a signed JWT, so Ghost answered400 INVALID_JWTon every request — a message that reads exactly like a revoked key. Ghost's source is unambiguous:Unit tests passed because the fake
fetchnever inspected headers.Fix: sign an HS256 token per request (header
{ alg, typ, kid }, payload{ iat, exp, aud: "/admin/" }, HMAC key = the hex-decoded secret). Newtest/auth.test.mjsdecodes the header the worker builds and verifies the signature the way Ghost does.Two more, exposed once auth worked
es/en, so every real post was ineligible — the live backfill reported 0 of 221. Now matches the slug, falling back to the name only when a webhook payload omits it.?formats=html,mdis invalid. Ghost acceptshtml,mobiledoc,lexical,plaintextand answers422formd. Usingplaintext.Three more, from the cluster
component=webhook; the backfill pod is labelledcomponent=backfill, so it listed all 221 posts and then failed to create a single Job:component in (webhook, backfill). The worker stays excluded — it runs without a service-account token and has no business reaching the API server.{"result":"ok","scanned":221,"created":0,"failed":221}. Exit code was already 1; the log now saysfailed. The new test fails without this fix.unschedulabletaint. Uncordoning it would put a pod intoImagePullBackOff. The workflow now publisheslinux/amd64,linux/arm64; the local build stays amd64 becauseload: truecannot take a multi-platform build.Verified against the live publication
/settings/,/posts/make backfill-planreadPoston a real postesPUTGETon that objectGates
deploy/tts-audio/test.sh✅ (79 tests) ·yarn verify✅ · all six PR checks ✅Still blocking audio in production (infra, not code)
tts-audio-gatewaydoes not exist, so the HTTPRoute has nostatusandtts-audio.sredevops.orgreturns Cloudflare 1016. The receiver has never received a webhook — no worker Job has ever been created.tts-sredevopsorg; a ranged seek would fail in the browser.Throughput note: a 15.7k-char post takes ~32 min at ~15 chars/s, against a 60-min Job deadline — 1.9× headroom, tight for the longest posts.