Repository navigation
News: review follow-ups for 0.10.10 - #1559
Merged
Merged
Conversation
GET /news/media/:file now always sends the Content-Type its regex-locked file extension implies, so a bad metadata write on the R2 object can never make the API origin serve text/html. Tested: the media route tests now run the public news routes in workerd through Miniflare, which reaches the 200 branch bun cannot; the new test fails on the old code (text/html) and passes (22 pass).
zod accepted 9999-12-31T23:59:59-12:00, which SQLite datetime() turns into NULL (a 500 from the NOT NULL insert), and 0000-01-01T00:00:00+14:00, stored as year -0001. The year as written must now be 2000 through 2100, so both are a 400 naming published_at. Tested: new cases for both extremes on POST and PUT, the years just outside, and the accepted edges; they fail on the old code (500, 201) and pass (70 pass).
Each admin write now inserts an audit_log row (news_post_created, news_post_updated, news_post_deleted; resource_type news_post, resource_id the post id; details with id, slug, status, published_at and the actor's username) in the same D1 batch as the write, so a failed audit insert fails the request with nothing written. The row is read from the post itself (INSERT ... SELECT) because a create's id does not exist until its INSERT runs; for update and delete this also means a 404 writes no row. Tested on real SQLite migrations: rows for all three writes, none for refused or missed writes, and a trigger-failed audit insert rolls each write back; the 5 new tests fail on the old code (75 pass).
An upload publishes: the object is readable by anyone with its URL, and the API can neither list nor delete it. POST /admin/news/media now writes a news_media_uploaded row (resource_id the file name; details with url, type, size, already_stored, actor) before the R2 put, so an audit insert that fails leaves nothing stored. Re-uploads of existing bytes are audited too. Tested: rows for a new and a repeated upload, none for every refusal, and a trigger-failed audit insert stores nothing; the 2 new tests fail on the old code (24 pass).
Trimming GET /admin/news to the summary columns would empty the website's admin list: its parseAdminNewsList (nemarOrg/website#372) drops any row without a string body. The list keeps full posts until the website parses it as summaries; the test now pins the body on every row. Tested: news-routes.test.ts (75 pass).
Adds an Operations section: how to recall a mistaken image (R2 object delete with --remote, the API and website cache purges, the website redeploy), how long a post stays visible after unpublish or delete from the public routes' Cache-Control, and why the deploy token needs R2 (run 36610376353 attempt 1). Also records the new audit rows. Tested: test/adr-index.unit.test.ts.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1559Version: 🤖 Updated on each push. |
This was referenced Sep 29, 2026
neuromechanist
added a commit
that referenced
this pull request
Sep 29, 2026
Merged
This branch was previously deployed
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.
Follow-ups from the prod-safety review of #1553 (news posts, squash 53f3a24), to land before the 0.10.10 release (#1557).
Changes
backend/src/routes/news.ts).GET /news/media/:filealways sends the type its regex-locked extension implies (<sha256>.(png|jpg|webp|gif)) and no longer reads the R2 object'shttpMetadata.contentType, so a bad metadata write can never make the API origin servetext/html.backend/src/services/news.ts,backend/src/routes/admin/news.ts). Create, update and delete each writenews_post_created/news_post_updated/news_post_deletedwithresource_typenews_post,resource_idthe post id,user_idthe actor, anddetails{id, slug, status, published_at, actor}(the actor's username). The audit insert rides in the samedb.batch()as the write, the patternusers.tsuses for the upload-access repair, so a failed audit insert rolls the write back and the request is a 500 with nothing written.INSERT ... SELECTfrom the post rather thanauditLogStatement: a create's id only exists after its INSERT runs, so the audit statement, queued after it, reads the row back by slug (unique). Update (queued after the UPDATE) and delete (queued before the DELETE) select by id, so a 404 writes no audit row. The columns matchAUDIT_LOG_INSERT_SQL, anddetailsstays far underAUDIT_DETAILS_MAX_BYTESbecause each field is capped by migration 0087's CHECKs or is fixed-width.POST /admin/news/mediawritesnews_media_uploaded(resource_typenews_media,resource_idthe file name,details{url, content_type, bytes, already_stored, actor}) BEFORE the R2 put, through a hook instoreNewsImage. An R2 put cannot share a transaction with D1, and this order fails safe: an audit insert that fails leaves nothing stored. The cost is an extra row for a put that fails after it. A re-upload of bytes already stored is audited too, withalready_stored: true.published_atis bounded to the years 2000 through 2100 (backend/src/routes/admin/news.ts). The check is on the year as written.9999-12-31T23:59:59-12:00(a 500 from the NOT NULL insert, sincedatetime()returned NULL) and0000-01-01T00:00:00+14:00(stored as year -0001) are now 400s namingpublished_at: "published_at must be in the years 2000 through 2100". An offset can still move an edge date across a year boundary in UTC (2100-12-31T23:59:59-12:00is stored as2101-01-01 11:59:59). That stays readable./news/media/<file>and the/nemar/news/media/<file>alias, and the website's copy (purge, or a redeploy for a fresh edge-cache namespace).no-store. The list and detail sendpublic, max-age=30, s-maxage=300, stale-while-revalidate=600, so a cache can hold the old copy for at most 15 minutes. The website's own page caching comes on top.Authentication error [code: 10000]on/r2/buckets/nemar-news-media-devat 18:22Z, and attempt 2 (18:29Z to 18:32Z) succeeded with the same token.--remote: Wrangler 4 runsr2 objectcommands against local storage without it, so the command as first drafted would have "deleted" nothing.Not done
parseAdminNewsListin nemarOrg/websitesrc/lib/news.ts(Updata command not working #372, merged tostaging) parses each row withparseNewsPost, which drops any row without a stringbody. ReturningNEWS_SUMMARY_COLUMNSwould silently empty/admin/newson the website. The list page renders no body, so the fix is website-side first: parse the admin list as summaries, then switch this route to the summary columns (tracked in Admin news list: return summaries once the website parses them #1560).listAllNewsnow says so, and the admin-list test pinsbodyon every row so the switch cannot land alone.expires_athas the same unbounded-year gap: a year-10000 value becomes NULL.createNotice's round-trip guard turns that into a 500, not a silent never-expiring notice. It is outside News posts: storage, public read, admin CRUD, image upload #1553 and changes a different API, so it is left for its own change (Notice expires_at accepts years SQLite cannot read #1561).Verification
bun run typecheck(root and backend),bun run lint, andbiome checkon every changed backend file: clean.backend/test/news-routes.test.ts: 75 pass. It has 10 new tests: 5 for the year bounds, 5 for audit rows. The audit tests cover rows for all three writes, none for 400/403/404/409, and a trigger-failed audit insert rolling back each write. On the old code, the year tests fail (500 and 201) and the audit tests fail.backend/test/news-media-routes.test.ts: 24 pass. It has 4 new tests:text/html,text/html; charset=utf-8,application/xhtml+xml, none);Every refusal now also asserts no audit row. The Miniflare instance now runs the public news routes in workerd (bundled from
backend/test/helpers/news-routes-worker.ts), which reaches the 200 branch that bun cannot (DataCloneError). That closes the path the file header used to list as uncovered. The Content-Type test fails on the old code (text/html).test/admin-route-inventory.unit.test.ts: 4 pass (no route changes).test/adr-index.unit.test.ts: 8 pass.The whole offline
unit-puretier, withtest.yml's file classification, run locally: 419 files, 7411 pass, 26 skip, 0 fail.No mocks. Everything runs on real SQLite with every migration applied, and on Miniflare's R2 in workerd. Audit failures are produced by a real
RAISE(ABORT)trigger, astest/backfill-names-route.test.tsdoes.