[PR #1477] [MERGED] fix(slurp2): validate media restored from a backup (0.3.49) #1480

Closed
opened 2026-10-21 05:11:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Agents/pull/1477
Author: @SpicyMarinara
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/slurp-restore-media


📝 Commits (2)

  • f3ba621 fix(slurp2): validate media restored from a backup (0.3.49)
  • 80edb41 fix(slurp2): name a saved picture by the type its bytes show

📊 Changes

22 files changed (+686 additions, -370 deletions)

View changed files

➕ artifacts/slurp2-0.3.49.zip (+0 -0)
📝 catalog/catalog.json (+8 -8)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+8 -8)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+8 -8)
📝 catalog/v3/notes.json (+6 -6)
📝 package.json (+1 -1)
📝 packages/slurp2/CHANGELOG.md (+6 -0)
📝 packages/slurp2/client.js (+1 -1)
📝 packages/slurp2/manifest.json (+5 -5)
📝 packages/slurp2/server.mjs (+267 -267)
📝 packages/slurp2/src/engine/packages/client/src/slp/features/onboarding/slp-release.ts (+6 -9)
📝 packages/slurp2/src/engine/packages/server/src/slp/base/media/slp-media.ts (+77 -11)
📝 packages/slurp2/src/engine/packages/server/src/slp/features/ads/slp-ads-routes.ts (+3 -5)
📝 packages/slurp2/src/engine/packages/server/src/slp/features/feed/slp-feed-post-routes.ts (+13 -14)
📝 packages/slurp2/src/engine/packages/server/src/slp/features/media/slp-media-routes.ts (+9 -11)
📝 packages/slurp2/src/engine/packages/server/src/slp/features/messages/slp-messages-media-routes.ts (+2 -2)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 scripts/run-slurp-regressions.mjs (+1 -0)

...and 2 more files

📄 Description

Pull request

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #1476

Why this change

  • A Slurp backup is outside input. Restore wrote each media/ entry back under the name it had in the archive and only checked the first bytes, so a file's extension could name a different type from its contents.
  • The Slurp media routes sent stored files through reply.sendFile, which picks Content-Type from the file extension. What the browser was told came from the name, not from the picture.
  • Restore called isAllowedImageBuffer(data) without the AVIF hint, so AVIF pictures in a backup were dropped.

What changed

Package slurp2 0.3.48 → 0.3.49 (higher than every version the catalog has published; 0.3.48 is the highest).

  • restoreCreatorMediaFile (base/media/slp-media.ts) restores only .png, .jpg, .jpeg, .webp, .gif and .avif names, and only when the extension matches the type isAllowedImageBuffer reads from the bytes (jpg and jpeg count as one type). Anything else is skipped and appears in the restore job's skipped list. Slurp has always named stored pictures after their bytes (generated pictures go through slurpImageExtension, uploads use detected.ext), so a matching file keeps its archive name and the rows that point at it still work. Rows that name a skipped file point at no file and get a 404, which is how staging already treats a picture missing from the archive. No rows are rewritten.
  • New sendSlurpImageFile(reply, path) in the same file. It reads the file header, sends the picture as the type its bytes show (sendFile(..., { contentType: false }) stops the extension from overriding that type), and adds X-Content-Type-Options: nosniff. When the caller names the download (the feed route sets Content-Disposition), the filename takes the extension of that same type, so an older file under another type's extension saves with the right one. A file that is not a picture gets a 404 with Cache-Control: no-store and the caller's Content-Disposition removed. BMP is accepted here because hosts without sharp keep generated BMPs as they are. All seven Slurp sendFile sites now use it: post media, post attachment, message media, Creator avatar, banner, Engine avatar copy and ad picture.
  • engineAvatarSource reads its header through the shared readFileHeader helper. It behaves the same.
  • Splash and notes: SLURP2_VERSION, a SLURP2_RELEASES entry and a packages/slurp2/CHANGELOG.md entry (patch, no highlight). The oldest splash entry (0.2.19) is removed so slp-release.ts stays within the 800-line architecture limit. 0.3.47 did the same with 0.2.18.
  • Tests:
    • New tests/slurp2-restore-media.regression.ts. It runs the real slp-media.ts over an Engine overlay and the Engine's real fastify and @fastify/static. It covers the accepted and refused restore names and contents, every image type sent as the type its bytes show (including files already on disk under a misleading name), the saved filename's extension following the same type, the 404 path, and a check that only sendSlurpImageFile calls sendFile. Like slurp2-engine-avatar-variant, it needs MARINARA_ENGINE_ROOT and runs without the regressions tsconfig, so it is added to PLAIN_TSX in scripts/run-slurp-regressions.mjs and to test:noodle:regressions.
    • tests/slurp2-backup-roundtrip.regression.ts checked the exact text of the old one-line restore check. That pattern now matches the stricter check, with the same message. The new regression covers the behaviour at runtime.
  • Generated: packages/slurp2/{manifest.json,client.js,server.mjs}, artifacts/slurp2-0.3.49.zip, catalog/{,v2/,v3/}{catalog,notes}.json.
  • Build pin: built with MARINARA_ENGINE_ROOT pinned to Engine ecd43884c, the same pin as 0.3.48. Rebuilding the unchanged staging head (ef521c75a) against that Engine gives the published 0.3.48 byte for byte. client.js differs only by the version and the splash entries.

Package and security impact

  • Affected package IDs: slurp2
  • Engine compatibility impact: none (range unchanged, >=2.4.6). contentType: false is a @fastify/static 10 option, and every supported Engine ships version 10.
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: none. No schema or stored-data change. Restore now skips media files whose name and contents disagree, and files that are not PNG, JPEG, WebP, GIF or AVIF. Backups made by Slurp itself are not affected.
  • Unchanged behaviour: sendFile still writes its own Cache-Control (public, max-age=0, revalidated by ETag) over the routes' Cache-Control, as it did before. This is marked with a ponytail: comment and is left for a separate decision.

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Agent-run validation on 80edb419e (the boxes above are for the human reviewer):

  • npm run check: passes (0 errors; the existing warnings are unchanged)
  • node scripts/test-catalog-lanes.mjs, node scripts/validate-package-locales.mjs, node scripts/validate-package-locale-keys.mjs, node scripts/validate-catalog.mjs, node scripts/tests/catalog-release-notes.regression.mjs, node scripts/tests/catalog-generatedat-determinism.regression.mjs, node scripts/tests/vendored-engine.regression.mjs, node scripts/validate-pr-triage.mjs, npm run test:security, npm run typecheck:packages (and slurp2 with the pinned Engine), git diff --check: all pass
  • MARINARA_ENGINE_ROOT=<Engine ecd43884c> npm run test:slurp:regressions: 299 passed, 0 failed (rerun after the review fix in 80edb419e). Pristine staging ef521c75a with the same Engine: 298 passed, 0 failed. The extra file is the new regression.
  • Fail before, pass after: on pristine staging sources, slurp2-restore-media fails first on the sendFile wiring check. With that check removed, it fails on media/a1/page.html is refused (actual true). On this branch it passes. The saved-name check added in 80edb419e fails on the previous sender (a1/photo-long.jpeg is saved as slurp-x.jpg) and passes with the fix. That commit's rebuild against the same pinned Engine changes only one line of server.mjs, the manifest/catalog checksums and the ZIP.

Manual verification notes

  • Manually verify in Marinara Engine (staging) → Agents → Download Agents that Slurp updates to 0.3.49 and the "What's new" sheet shows the 0.3.49 entry.
  • Manually verify in Slurp → Backstage that a backup made with Backup on this install restores with every post picture, attachment, message picture, avatar and banner still showing. The restore summary should report no skipped media.
  • Manually verify that a backup containing an AVIF post picture restores it, and the picture shows in the feed.
  • Manually verify that a backup whose media/ folder holds a file that is not a picture, or a picture renamed to another type's extension, restores everything else and lists that file among the skipped entries.
  • Manually verify in the browser's network panel that a post picture, a message picture, an avatar and an ad picture each come back with an image/* Content-Type matching the picture and with X-Content-Type-Options: nosniff.
  • Manually verify that saving a post picture from the feed still names the file slurp-<id>.<ext>, with the extension of the picture's real type.

Documentation impact

  • No documentation changes needed
  • Updated this README catalog and package guidance
  • Updated linked Marinara Engine documentation

No README or package doc describes restore media rules or media response headers, so no docs were changed. The change is described in packages/slurp2/CHANGELOG.md and the splash.

UI evidence (if applicable)

None. The only visible change is the "What's new" entry.

Summary by CodeRabbit

  • New Features
    • Slurp 0.3.49 restores PNG, JPEG, WebP, GIF, and AVIF files when their extensions match their contents. Unsupported files and mismatches are skipped and listed.
  • Bug Fixes
    • Fixed AVIF image restoration.
    • Stored pictures are served with the image type detected from their contents, including when filenames have misleading extensions.
    • Unreadable or unsupported image files are not served.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Agents/pull/1477 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/slurp-restore-media` --- ### 📝 Commits (2) - [`f3ba621`](https://github.com/Pasta-Devs/Marinara-Agents/commit/f3ba6219bc9388c6a5e32dcef9ae324ea770f061) fix(slurp2): validate media restored from a backup (0.3.49) - [`80edb41`](https://github.com/Pasta-Devs/Marinara-Agents/commit/80edb419e07c037b785a6ce3eb8de25d9a4f2e15) fix(slurp2): name a saved picture by the type its bytes show ### 📊 Changes **22 files changed** (+686 additions, -370 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/slurp2-0.3.49.zip` (+0 -0) 📝 `catalog/catalog.json` (+8 -8) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+8 -8) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+8 -8) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `package.json` (+1 -1) 📝 `packages/slurp2/CHANGELOG.md` (+6 -0) 📝 `packages/slurp2/client.js` (+1 -1) 📝 `packages/slurp2/manifest.json` (+5 -5) 📝 `packages/slurp2/server.mjs` (+267 -267) 📝 `packages/slurp2/src/engine/packages/client/src/slp/features/onboarding/slp-release.ts` (+6 -9) 📝 `packages/slurp2/src/engine/packages/server/src/slp/base/media/slp-media.ts` (+77 -11) 📝 `packages/slurp2/src/engine/packages/server/src/slp/features/ads/slp-ads-routes.ts` (+3 -5) 📝 `packages/slurp2/src/engine/packages/server/src/slp/features/feed/slp-feed-post-routes.ts` (+13 -14) 📝 `packages/slurp2/src/engine/packages/server/src/slp/features/media/slp-media-routes.ts` (+9 -11) 📝 `packages/slurp2/src/engine/packages/server/src/slp/features/messages/slp-messages-media-routes.ts` (+2 -2) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `scripts/run-slurp-regressions.mjs` (+1 -0) _...and 2 more files_ </details> ### 📄 Description # Pull request > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #1476 ## Why this change - A Slurp backup is outside input. Restore wrote each `media/` entry back under the name it had in the archive and only checked the first bytes, so a file's extension could name a different type from its contents. - The Slurp media routes sent stored files through `reply.sendFile`, which picks `Content-Type` from the file extension. What the browser was told came from the name, not from the picture. - Restore called `isAllowedImageBuffer(data)` without the AVIF hint, so AVIF pictures in a backup were dropped. ## What changed Package `slurp2` 0.3.48 → 0.3.49 (higher than every version the catalog has published; 0.3.48 is the highest). - `restoreCreatorMediaFile` (`base/media/slp-media.ts`) restores only `.png`, `.jpg`, `.jpeg`, `.webp`, `.gif` and `.avif` names, and only when the extension matches the type `isAllowedImageBuffer` reads from the bytes (`jpg` and `jpeg` count as one type). Anything else is skipped and appears in the restore job's skipped list. Slurp has always named stored pictures after their bytes (generated pictures go through `slurpImageExtension`, uploads use `detected.ext`), so a matching file keeps its archive name and the rows that point at it still work. Rows that name a skipped file point at no file and get a 404, which is how staging already treats a picture missing from the archive. No rows are rewritten. - New `sendSlurpImageFile(reply, path)` in the same file. It reads the file header, sends the picture as the type its bytes show (`sendFile(..., { contentType: false })` stops the extension from overriding that type), and adds `X-Content-Type-Options: nosniff`. When the caller names the download (the feed route sets `Content-Disposition`), the filename takes the extension of that same type, so an older file under another type's extension saves with the right one. A file that is not a picture gets a 404 with `Cache-Control: no-store` and the caller's `Content-Disposition` removed. BMP is accepted here because hosts without sharp keep generated BMPs as they are. All seven Slurp `sendFile` sites now use it: post media, post attachment, message media, Creator avatar, banner, Engine avatar copy and ad picture. - `engineAvatarSource` reads its header through the shared `readFileHeader` helper. It behaves the same. - Splash and notes: `SLURP2_VERSION`, a `SLURP2_RELEASES` entry and a `packages/slurp2/CHANGELOG.md` entry (patch, no highlight). The oldest splash entry (0.2.19) is removed so `slp-release.ts` stays within the 800-line architecture limit. 0.3.47 did the same with 0.2.18. - Tests: - New `tests/slurp2-restore-media.regression.ts`. It runs the real `slp-media.ts` over an Engine overlay and the Engine's real `fastify` and `@fastify/static`. It covers the accepted and refused restore names and contents, every image type sent as the type its bytes show (including files already on disk under a misleading name), the saved filename's extension following the same type, the 404 path, and a check that only `sendSlurpImageFile` calls `sendFile`. Like `slurp2-engine-avatar-variant`, it needs `MARINARA_ENGINE_ROOT` and runs without the regressions tsconfig, so it is added to `PLAIN_TSX` in `scripts/run-slurp-regressions.mjs` and to `test:noodle:regressions`. - `tests/slurp2-backup-roundtrip.regression.ts` checked the exact text of the old one-line restore check. That pattern now matches the stricter check, with the same message. The new regression covers the behaviour at runtime. - Generated: `packages/slurp2/{manifest.json,client.js,server.mjs}`, `artifacts/slurp2-0.3.49.zip`, `catalog/{,v2/,v3/}{catalog,notes}.json`. - **Build pin**: built with `MARINARA_ENGINE_ROOT` pinned to Engine `ecd43884c`, the same pin as 0.3.48. Rebuilding the unchanged staging head (`ef521c75a`) against that Engine gives the published 0.3.48 byte for byte. `client.js` differs only by the version and the splash entries. ## Package and security impact - Affected package IDs: `slurp2` - Engine compatibility impact: none (range unchanged, `>=2.4.6`). `contentType: false` is a `@fastify/static` 10 option, and every supported Engine ships version 10. - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: none. No schema or stored-data change. Restore now skips media files whose name and contents disagree, and files that are not PNG, JPEG, WebP, GIF or AVIF. Backups made by Slurp itself are not affected. - Unchanged behaviour: `sendFile` still writes its own `Cache-Control` (`public, max-age=0`, revalidated by ETag) over the routes' `Cache-Control`, as it did before. This is marked with a `ponytail:` comment and is left for a separate decision. ## Validation - [ ] `node scripts/validate-catalog.mjs` passes locally - [ ] `git diff --check` passes locally - [ ] Rebuilt every affected manifest, payload, artifact, and catalog entry - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup - [ ] Read and followed `CONTRIBUTING.md` Agent-run validation on `80edb419e` (the boxes above are for the human reviewer): - `npm run check`: passes (0 errors; the existing warnings are unchanged) - `node scripts/test-catalog-lanes.mjs`, `node scripts/validate-package-locales.mjs`, `node scripts/validate-package-locale-keys.mjs`, `node scripts/validate-catalog.mjs`, `node scripts/tests/catalog-release-notes.regression.mjs`, `node scripts/tests/catalog-generatedat-determinism.regression.mjs`, `node scripts/tests/vendored-engine.regression.mjs`, `node scripts/validate-pr-triage.mjs`, `npm run test:security`, `npm run typecheck:packages` (and `slurp2` with the pinned Engine), `git diff --check`: all pass - `MARINARA_ENGINE_ROOT=<Engine ecd43884c> npm run test:slurp:regressions`: 299 passed, 0 failed (rerun after the review fix in `80edb419e`). Pristine staging `ef521c75a` with the same Engine: 298 passed, 0 failed. The extra file is the new regression. - Fail before, pass after: on pristine staging sources, `slurp2-restore-media` fails first on the `sendFile` wiring check. With that check removed, it fails on `media/a1/page.html is refused` (actual `true`). On this branch it passes. The saved-name check added in `80edb419e` fails on the previous sender (`a1/photo-long.jpeg is saved as slurp-x.jpg`) and passes with the fix. That commit's rebuild against the same pinned Engine changes only one line of `server.mjs`, the manifest/catalog checksums and the ZIP. ### Manual verification notes - Manually verify in Marinara Engine (staging) → Agents → Download Agents that Slurp updates to 0.3.49 and the "What's new" sheet shows the 0.3.49 entry. - Manually verify in Slurp → Backstage that a backup made with Backup on this install restores with every post picture, attachment, message picture, avatar and banner still showing. The restore summary should report no skipped media. - Manually verify that a backup containing an AVIF post picture restores it, and the picture shows in the feed. - Manually verify that a backup whose `media/` folder holds a file that is not a picture, or a picture renamed to another type's extension, restores everything else and lists that file among the skipped entries. - Manually verify in the browser's network panel that a post picture, a message picture, an avatar and an ad picture each come back with an `image/*` `Content-Type` matching the picture and with `X-Content-Type-Options: nosniff`. - Manually verify that saving a post picture from the feed still names the file `slurp-<id>.<ext>`, with the extension of the picture's real type. ## Documentation impact - [ ] No documentation changes needed - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation No README or package doc describes restore media rules or media response headers, so no docs were changed. The change is described in `packages/slurp2/CHANGELOG.md` and the splash. ## UI evidence (if applicable) None. The only visible change is the "What's new" entry. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Slurp 0.3.49 restores PNG, JPEG, WebP, GIF, and AVIF files when their extensions match their contents. Unsupported files and mismatches are skipped and listed. * **Bug Fixes** * Fixed AVIF image restoration. * Stored pictures are served with the image type detected from their contents, including when filenames have misleading extensions. * Unreadable or unsupported image files are not served. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-21 05:11:57 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#1480
No description provided.