[GH-ISSUE #3617] [Issue]: Bot Browser JSON proxies duplicate uncapped fetch logic outside safeFetch #1957

Closed
opened 2026-10-21 05:44:09 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @Xelvanis on GitHub (Jul 14, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3617

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The Chub, CharacterTavern, and Wyvern Bot Browser route modules each contain the same plain-fetch() JSON proxy helper instead of using Marinara's existing safeFetch outbound-request boundary. The helpers have a timeout, but no response-size cap and no Marinara-controlled redirect/DNS policy.

This is both duplicated maintenance logic and an outbound-fetch hardening gap. The initial API origins are fixed constants, so this is not a direct arbitrary-URL SSRF report; the concrete risks are uncapped JSON buffering, weaker redirect handling, and future fixes drifting across the three copies.

Expected behavior

  • Bot Browser JSON proxy requests share one bounded helper built on the existing safeFetch policy.
  • Responses have an explicit size limit and JSON content-type policy.
  • HTTPS, redirect destinations, and permitted provider hosts are handled deliberately.
  • Provider-specific headers and legitimate response-size differences remain configurable at the callsite.

Actual behavior

Identical proxyFetch() implementations exist independently in three route files. Each helper:

  1. Creates a 30-second AbortController timeout.
  2. Calls ordinary fetch().
  3. Includes the first 300 characters of a non-success response in an error.
  4. Calls res.json(), buffering and parsing the complete successful body without a response-size cap.

The same route modules already use safeFetch for avatar requests, so Bot Browser traffic currently has two different outbound safety paths depending on whether the response is JSON or an image.

safeFetch already provides private/reserved-address rejection, redirect revalidation, cross-origin sensitive-header stripping, protocol restrictions, and a default 10 MB response cap. It does not currently expose an exact provider-host allowlist, so consolidation should not be a blind text replacement: permitted hosts/redirects and suitable limits need to be decided for each provider.

Steps to reproduce

  1. Inspect the proxyFetch() definitions in the Chub, CharacterTavern, and Wyvern route modules; the bodies are identical.
  2. Call a Bot Browser JSON endpoint such as Chub search, Chub character detail, CharacterTavern top tags, or Wyvern search/detail.
  3. Have the upstream return a very large successful JSON body. The helper calls res.json() with no response-size limit, so the complete body is buffered and parsed.
  4. Alternatively, have the upstream return a redirect. The request follows ordinary fetch() behavior rather than Marinara's safeFetch redirect and resolved-address validation.

Runtime reproduction with a controlled upstream was not performed for this report. The duplicate helpers, plain-fetch path, and absence of a response-size policy were verified by static inspection of current staging.

Environment

  • Marinara Engine version: staging at 694bc88f16bd99838aa52b70bd07b56fe9e354e4 (2026-07-15)
  • Install type: source inspection
  • OS + version: Not applicable (platform-independent server code)
  • Browser or app shell: Not applicable (server-side outbound requests)

Logs, screenshots, or video

None. This report is based on static inspection; no controlled-upstream runtime logs or screenshots were captured.

Additional context

Duplicate helpers:

Existing shared boundary:

Suggested remediation:

  1. Introduce a narrow shared fetchBotBrowserJson() helper built on safeFetch.
  2. Preserve the 30-second timeout while respecting any caller-provided cancellation signal.
  3. Require HTTPS and an appropriate JSON content type.
  4. Choose a bounded default response size with explicit per-endpoint overrides where full character data legitimately needs more room than search/tag responses.
  5. Decide the expected redirect/provider-host policy before enabling redirects. A strict allowlist must account for legitimate provider migrations or CDN/API domains; otherwise it can break integrations, as previously seen with avatar hosts.
  6. Keep provider-specific authentication and headers outside the generic helper.

Related but not duplicate:

  • #2705 covered unbounded avatar-image proxies and import validation.
  • #3319 covered broken avatar host/content-type/size policies across providers.

This issue is scoped first to the three identical JSON helpers. Other direct raw-fetch paths in the Bot Browser modules handle different payloads or authentication and should be evaluated separately rather than mechanically folded into the same abstraction.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (Jul 14, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3617 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The Chub, CharacterTavern, and Wyvern Bot Browser route modules each contain the same plain-`fetch()` JSON proxy helper instead of using Marinara's existing `safeFetch` outbound-request boundary. The helpers have a timeout, but no response-size cap and no Marinara-controlled redirect/DNS policy. This is both duplicated maintenance logic and an outbound-fetch hardening gap. The initial API origins are fixed constants, so this is not a direct arbitrary-URL SSRF report; the concrete risks are uncapped JSON buffering, weaker redirect handling, and future fixes drifting across the three copies. ## Expected behavior - Bot Browser JSON proxy requests share one bounded helper built on the existing `safeFetch` policy. - Responses have an explicit size limit and JSON content-type policy. - HTTPS, redirect destinations, and permitted provider hosts are handled deliberately. - Provider-specific headers and legitimate response-size differences remain configurable at the callsite. ## Actual behavior Identical `proxyFetch()` implementations exist independently in three route files. Each helper: 1. Creates a 30-second `AbortController` timeout. 2. Calls ordinary `fetch()`. 3. Includes the first 300 characters of a non-success response in an error. 4. Calls `res.json()`, buffering and parsing the complete successful body without a response-size cap. The same route modules already use `safeFetch` for avatar requests, so Bot Browser traffic currently has two different outbound safety paths depending on whether the response is JSON or an image. `safeFetch` already provides private/reserved-address rejection, redirect revalidation, cross-origin sensitive-header stripping, protocol restrictions, and a default 10 MB response cap. It does not currently expose an exact provider-host allowlist, so consolidation should not be a blind text replacement: permitted hosts/redirects and suitable limits need to be decided for each provider. ## Steps to reproduce 1. Inspect the `proxyFetch()` definitions in the Chub, CharacterTavern, and Wyvern route modules; the bodies are identical. 2. Call a Bot Browser JSON endpoint such as Chub search, Chub character detail, CharacterTavern top tags, or Wyvern search/detail. 3. Have the upstream return a very large successful JSON body. The helper calls `res.json()` with no response-size limit, so the complete body is buffered and parsed. 4. Alternatively, have the upstream return a redirect. The request follows ordinary `fetch()` behavior rather than Marinara's `safeFetch` redirect and resolved-address validation. Runtime reproduction with a controlled upstream was not performed for this report. The duplicate helpers, plain-fetch path, and absence of a response-size policy were verified by static inspection of current `staging`. ## Environment - Marinara Engine version: `staging` at `694bc88f16bd99838aa52b70bd07b56fe9e354e4` (2026-07-15) - Install type: source inspection - OS + version: Not applicable (platform-independent server code) - Browser or app shell: Not applicable (server-side outbound requests) ## Logs, screenshots, or video None. This report is based on static inspection; no controlled-upstream runtime logs or screenshots were captured. ## Additional context Duplicate helpers: - [Chub `proxyFetch()`](https://github.com/Pasta-Devs/Marinara-Engine/blob/694bc88f16bd99838aa52b70bd07b56fe9e354e4/packages/server/src/routes/bot-browser.routes.ts#L24-L38) - [CharacterTavern `proxyFetch()`](https://github.com/Pasta-Devs/Marinara-Engine/blob/694bc88f16bd99838aa52b70bd07b56fe9e354e4/packages/server/src/routes/bot-browser-chartavern.routes.ts#L17-L30) - [Wyvern `proxyFetch()`](https://github.com/Pasta-Devs/Marinara-Engine/blob/694bc88f16bd99838aa52b70bd07b56fe9e354e4/packages/server/src/routes/bot-browser-wyvern.routes.ts#L11-L24) Existing shared boundary: - [`safeFetch`](https://github.com/Pasta-Devs/Marinara-Engine/blob/694bc88f16bd99838aa52b70bd07b56fe9e354e4/packages/server/src/utils/security.ts#L563-L631) - [Chub avatar requests already using `safeFetch`](https://github.com/Pasta-Devs/Marinara-Engine/blob/694bc88f16bd99838aa52b70bd07b56fe9e354e4/packages/server/src/routes/bot-browser.routes.ts#L11-L21) - [CharacterTavern avatar requests already using `safeFetch`](https://github.com/Pasta-Devs/Marinara-Engine/blob/694bc88f16bd99838aa52b70bd07b56fe9e354e4/packages/server/src/routes/bot-browser-chartavern.routes.ts#L32-L56) Suggested remediation: 1. Introduce a narrow shared `fetchBotBrowserJson()` helper built on `safeFetch`. 2. Preserve the 30-second timeout while respecting any caller-provided cancellation signal. 3. Require HTTPS and an appropriate JSON content type. 4. Choose a bounded default response size with explicit per-endpoint overrides where full character data legitimately needs more room than search/tag responses. 5. Decide the expected redirect/provider-host policy before enabling redirects. A strict allowlist must account for legitimate provider migrations or CDN/API domains; otherwise it can break integrations, as previously seen with avatar hosts. 6. Keep provider-specific authentication and headers outside the generic helper. Related but not duplicate: - #2705 covered unbounded avatar-image proxies and import validation. - #3319 covered broken avatar host/content-type/size policies across providers. This issue is scoped first to the three identical JSON helpers. Other direct raw-fetch paths in the Bot Browser modules handle different payloads or authentication and should be evaluated separately rather than mechanically folded into the same abstraction. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:44:09 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jul 14, 2026):

Ownership: @SpicyMarinara is addressing this in fix/3616-3625-open-issues. A staging-targeted draft PR will be linked as soon as the first reproducible fix is committed.

<!-- gh-comment-id:4974861917 --> @SpicyMarinara commented on GitHub (Jul 14, 2026): Ownership: @SpicyMarinara is addressing this in `fix/3616-3625-open-issues`. A staging-targeted draft PR will be linked as soon as the first reproducible fix is committed.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 14, 2026):

Draft implementation PR is now open: #3626. It remains draft while the linked regression lanes are implemented and validated.

<!-- gh-comment-id:4974876107 --> @SpicyMarinara commented on GitHub (Jul 14, 2026): Draft implementation PR is now open: #3626. It remains draft while the linked regression lanes are implemented and validated.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 14, 2026):

Addressed in ready-for-review PR #3626 targeting staging. The fix and regression coverage have been pushed and validated locally.

<!-- gh-comment-id:4975034110 --> @SpicyMarinara commented on GitHub (Jul 14, 2026): Addressed in ready-for-review PR #3626 targeting staging. The fix and regression coverage have been pushed and validated locally.
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#1957
No description provided.