[PR #3661] [CLOSED] fix(security): handle missing content-type and gzip responses in safeFetch JSON paths #6043

Closed
opened 2026-10-23 04:06:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3661
Author: @Lamboozled
Created: 7/15/2026
Status: ❌ Closed

Base: main ← Head: fix/safefetch-compressed-json-responses


📝 Commits (3)

  • 790da41 chore: start v2.3.1 development
  • d4114de Merge pull request #3659 from Pasta-Devs/agent/start-v2.3.1
  • 2d8542d fix(security): handle missing content-type and gzip in safeFetch JSON paths

📊 Changes

14 files changed (+24 additions, -15 deletions)

View changed files

📝 CHANGELOG.md (+7 -0)
📝 README.md (+1 -1)
📝 android/app/build.gradle (+3 -3)
📝 package.json (+1 -1)
📝 packages/client/package.json (+1 -1)
📝 packages/client/public/manifest.json (+1 -1)
📝 packages/server/package.json (+1 -1)
📝 packages/server/src/services/bot-browser/fetch-json.ts (+1 -0)
📝 packages/server/src/services/capability-packages/package-manager.service.ts (+1 -0)
📝 packages/server/src/utils/security.ts (+1 -1)
📝 packages/shared/package.json (+1 -1)
📝 packages/shared/src/constants/defaults.ts (+1 -1)
📝 win/installer/install.bat (+2 -2)
📝 win/installer/installer.nsi (+2 -2)

📄 Description

Linked issue

Closes #3660

Why this change

  • safeFetch's allowedContentTypes guard used !contentType || which rejects responses that omit the Content-Type header entirely, even when the body is valid content. Card browser API calls (fetchBotBrowserJson) and the capability package catalog both hit this, logging "Outbound response content type is not allowed: " on startup and during browsing.
  • readCappedResponse reads the raw response byte stream via response.body.getReader(), bypassing undici's built-in Content-Encoding decompression. GitHub raw content (capability catalog) and some card browser APIs return gzip-compressed responses, causing response.json() to throw a SyntaxError with raw gzip bytes.

What changed

  • packages/server/src/utils/security.ts — change !contentType || to contentType && in the allowedContentTypes guard so only explicitly wrong content types are rejected; missing headers are allowed through
  • packages/server/src/services/bot-browser/fetch-json.ts — add decodeCompressedResponse: true so gzip API responses are decompressed before parsing
  • packages/server/src/services/capability-packages/package-manager.service.ts — add decodeCompressedResponse: true to the catalog fetch for the same reason

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Verified card browser (ChubAI) loads character listings without "content type not allowed" errors in server log
  • Verified capability package catalog loads on startup without SyntaxError gzip parse failure in server log

Docs and release impact

  • No docs changes needed
  • Updated docs as needed
  • Version/release files updated

Summary by CodeRabbit

  • Release

    • Updated the application and platform installers to version 2.3.1.
    • Updated the latest stable release information across supported platforms.
  • Bug Fixes

    • Improved handling of compressed upstream responses.
    • Requests without a content-type header are now handled correctly when content-type validation is enabled.

🔄 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-Engine/pull/3661 **Author:** [@Lamboozled](https://github.com/Lamboozled) **Created:** 7/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/safefetch-compressed-json-responses` --- ### 📝 Commits (3) - [`790da41`](https://github.com/Pasta-Devs/Marinara-Engine/commit/790da416a998d93e5ae2c52b07ae9c451f58cb12) chore: start v2.3.1 development - [`d4114de`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d4114de0e8d7264de16a56ca7f1c43204a1cfe9c) Merge pull request #3659 from Pasta-Devs/agent/start-v2.3.1 - [`2d8542d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2d8542dfb96653f0a1af5666ed41d7d4dc1e041e) fix(security): handle missing content-type and gzip in safeFetch JSON paths ### 📊 Changes **14 files changed** (+24 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+7 -0) 📝 `README.md` (+1 -1) 📝 `android/app/build.gradle` (+3 -3) 📝 `package.json` (+1 -1) 📝 `packages/client/package.json` (+1 -1) 📝 `packages/client/public/manifest.json` (+1 -1) 📝 `packages/server/package.json` (+1 -1) 📝 `packages/server/src/services/bot-browser/fetch-json.ts` (+1 -0) 📝 `packages/server/src/services/capability-packages/package-manager.service.ts` (+1 -0) 📝 `packages/server/src/utils/security.ts` (+1 -1) 📝 `packages/shared/package.json` (+1 -1) 📝 `packages/shared/src/constants/defaults.ts` (+1 -1) 📝 `win/installer/install.bat` (+2 -2) 📝 `win/installer/installer.nsi` (+2 -2) </details> ### 📄 Description ## Linked issue Closes #3660 ## Why this change - `safeFetch`'s `allowedContentTypes` guard used `!contentType ||` which rejects responses that omit the `Content-Type` header entirely, even when the body is valid content. Card browser API calls (`fetchBotBrowserJson`) and the capability package catalog both hit this, logging "Outbound response content type is not allowed: " on startup and during browsing. - `readCappedResponse` reads the raw response byte stream via `response.body.getReader()`, bypassing undici's built-in `Content-Encoding` decompression. GitHub raw content (capability catalog) and some card browser APIs return gzip-compressed responses, causing `response.json()` to throw a `SyntaxError` with raw gzip bytes. ## What changed - `packages/server/src/utils/security.ts` — change `!contentType ||` to `contentType &&` in the `allowedContentTypes` guard so only explicitly wrong content types are rejected; missing headers are allowed through - `packages/server/src/services/bot-browser/fetch-json.ts` — add `decodeCompressedResponse: true` so gzip API responses are decompressed before parsing - `packages/server/src/services/capability-packages/package-manager.service.ts` — add `decodeCompressedResponse: true` to the catalog fetch for the same reason ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Verified card browser (ChubAI) loads character listings without "content type not allowed" errors in server log - Verified capability package catalog loads on startup without SyntaxError gzip parse failure in server log ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs as needed - [ ] Version/release files updated <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Release** * Updated the application and platform installers to version 2.3.1. * Updated the latest stable release information across supported platforms. * **Bug Fixes** * Improved handling of compressed upstream responses. * Requests without a `content-type` header are now handled correctly when content-type validation is enabled. <!-- 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-23 04:06:31 +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-Engine#6043
No description provided.