[GH-ISSUE #2300] [Issue]: SSRF — load_url_binary/http_binary fetches content-supplied URLs with the internal-host guard disabled (allow_local=true) #1136

Closed
opened 2026-10-21 05:27:38 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2300

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: High — Security (SSRF). http_binary, the backend fetcher behind the load_url_binary command, calls is_allowed_outbound_url(url, true), which short-circuits all loopback / private / reserved / link-local / metadata host blocking. Content-supplied image URLs (character cards, gallery items, game backgrounds, message attachments) flow straight into it, so the backend can be made to fetch http://127.0.0.1:<port>/... or http://169.254.169.254/latest/meta-data/ and return the raw response body to the caller.

Expected behavior

Fetches of content-supplied URLs should block loopback/private/reserved/link-local/metadata hosts by default (is_allowed_outbound_url(url, false)), disable redirect auto-following and re-validate each redirect target, and pin the resolved IP to defeat DNS rebinding — exactly as the hardened webhook path in custom_tools.rs already does. Any genuinely-local target should require an explicit opt-in flag like the existing WEBHOOK_LOCAL_URLS_ENABLED.

Actual behavior

http_binary (src-tauri/src/commands/storage/http.rs:33-47) calls is_allowed_outbound_url(url, true). In crates/security/src/lib.rs:83-97, allow_local = true returns true for any http(s) host — the repo's own test at lib.rs:456-458 asserts it accepts 169.254.169.254 and 127.0.0.1. So the only check left is the scheme (it rejects file:// etc.).

pub(crate) async fn http_binary(url: &str, fallback_mime: &str) -> AppResult<Value> {
    if !is_allowed_outbound_url(url, true) {  // allow_local=true => NO loopback/private/metadata blocking
        return Err(AppError::invalid_input(format!("Outbound URL is not allowed: {url}")));
    }
    let client = reqwest::Client::builder().timeout(Duration::from_secs(60)).build()?; // default redirect policy: follows up to 10 redirects
    let response = client.get(url).send().await ...

Additional gaps on the same path:

  • The reqwest::Client is built with the default redirect policy (no .redirect(Policy::none())), so a public URL that 302-redirects to an internal host is followed with no re-validation.
  • The MIME allowlist (allowed_binary_mime, http.rs:88-96) only inspects the target-controlled Content-Type and permits application/octet-stream, so internal responses are returned base64 to the caller. Even when bytes are rejected, success/failure and timing leak internal reachability.

Reachability (URL is fully content-controlled): load_url_binary (commands/storage/commands/profile.rs:24-44) passes the raw frontend url. load_url_binary_for_state only intercepts asset://localhost/ and http://asset.localhost/ prefixes and falls through to http_binary for every real http(s) URL. Frontend callers: urlBinaryApi.load -> invoke("load_url_binary") (url-binary-api.ts:53-64), reached from storage-api.ts:330-339 (message attachment url/imageUrl), storage-api.ts:287-295 (gallery record.url), and game-api.ts:1529-1535 (background resolution). The only frontend filter (game-api.ts:1507-1510 isRemoteImageReferenceUrl) checks the http(s) prefix only — it does not block private/loopback/metadata hosts.

Steps to reproduce

  1. Import a character card / gallery item / game background / message attachment whose image URL is http://169.254.169.254/latest/meta-data/ or http://127.0.0.1:<port>/....
  2. Trigger the image load (open the chat, gallery, or game scene that resolves it).
  3. Observe that the backend fetches the internal URL and returns its body to the renderer.

Impact area

  • Catalog resources
  • Game mode
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ 47b16701
  • Run mode: Tauri desktop (also reachable in opt-in server mode)
  • OS + version: not relevant (static source audit, confirmed by code reading)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: any content with a remote image URL

Logs, screenshots, or video

Static source audit; no runtime logs. All claims are cited to file:line above.

Regression notes

Found via static audit of the refactor branch; not verified against main. The correct fix pattern already exists in-repo — the webhook path in commands/storage/custom_tools.rs sets redirect Policy::none() (line 144), re-validates each redirect target (158-185), pins the resolved IP via resolve_to_addrs (146) with is_local_or_reserved_ip checks (225/243), and gates local targets behind WEBHOOK_LOCAL_URLS_ENABLED (195-210). This is therefore an inconsistent application of an existing control, not a missing capability.

Additional context

Server mode escalates impact: load_url_binary is exposed via http_dispatch.rs:96/767, so a deployed host becomes an IMDS / internal-service proxy for any client past the request gate.

Suggested fix: in http_binary, call is_allowed_outbound_url(url, false), build the client with .redirect(reqwest::redirect::Policy::none()), re-validate each redirect Location against the same policy, and pin the DNS-resolved address — mirroring custom_tools.rs.

Template check

Please uncheck 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 @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2300 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: High — Security (SSRF).** `http_binary`, the backend fetcher behind the `load_url_binary` command, calls `is_allowed_outbound_url(url, true)`, which short-circuits all loopback / private / reserved / link-local / metadata host blocking. Content-supplied image URLs (character cards, gallery items, game backgrounds, message attachments) flow straight into it, so the backend can be made to fetch `http://127.0.0.1:<port>/...` or `http://169.254.169.254/latest/meta-data/` and return the raw response body to the caller. ## Expected behavior Fetches of content-supplied URLs should block loopback/private/reserved/link-local/metadata hosts **by default** (`is_allowed_outbound_url(url, false)`), disable redirect auto-following and re-validate each redirect target, and pin the resolved IP to defeat DNS rebinding — exactly as the hardened webhook path in `custom_tools.rs` already does. Any genuinely-local target should require an explicit opt-in flag like the existing `WEBHOOK_LOCAL_URLS_ENABLED`. ## Actual behavior `http_binary` (`src-tauri/src/commands/storage/http.rs:33-47`) calls `is_allowed_outbound_url(url, true)`. In `crates/security/src/lib.rs:83-97`, `allow_local = true` returns `true` for any http(s) host — the repo's own test at `lib.rs:456-458` asserts it accepts `169.254.169.254` and `127.0.0.1`. So the only check left is the scheme (it rejects `file://` etc.). ```rust pub(crate) async fn http_binary(url: &str, fallback_mime: &str) -> AppResult<Value> { if !is_allowed_outbound_url(url, true) { // allow_local=true => NO loopback/private/metadata blocking return Err(AppError::invalid_input(format!("Outbound URL is not allowed: {url}"))); } let client = reqwest::Client::builder().timeout(Duration::from_secs(60)).build()?; // default redirect policy: follows up to 10 redirects let response = client.get(url).send().await ... ``` Additional gaps on the same path: - The `reqwest::Client` is built with the **default redirect policy** (no `.redirect(Policy::none())`), so a public URL that 302-redirects to an internal host is followed with no re-validation. - The MIME allowlist (`allowed_binary_mime`, `http.rs:88-96`) only inspects the **target-controlled** `Content-Type` and permits `application/octet-stream`, so internal responses are returned base64 to the caller. Even when bytes are rejected, success/failure and timing leak internal reachability. **Reachability (URL is fully content-controlled):** `load_url_binary` (`commands/storage/commands/profile.rs:24-44`) passes the raw frontend `url`. `load_url_binary_for_state` only intercepts `asset://localhost/` and `http://asset.localhost/` prefixes and falls through to `http_binary` for every real http(s) URL. Frontend callers: `urlBinaryApi.load -> invoke("load_url_binary")` (`url-binary-api.ts:53-64`), reached from `storage-api.ts:330-339` (message attachment `url`/`imageUrl`), `storage-api.ts:287-295` (gallery `record.url`), and `game-api.ts:1529-1535` (background resolution). The only frontend filter (`game-api.ts:1507-1510 isRemoteImageReferenceUrl`) checks the http(s) prefix only — it does not block private/loopback/metadata hosts. ## Steps to reproduce 1. Import a character card / gallery item / game background / message attachment whose image URL is `http://169.254.169.254/latest/meta-data/` or `http://127.0.0.1:<port>/...`. 2. Trigger the image load (open the chat, gallery, or game scene that resolves it). 3. Observe that the backend fetches the internal URL and returns its body to the renderer. ## Impact area - [x] Catalog resources - [x] Game mode - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 47b16701 - Run mode: Tauri desktop (also reachable in opt-in server mode) - OS + version: not relevant (static source audit, confirmed by code reading) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: any content with a remote image URL ## Logs, screenshots, or video Static source audit; no runtime logs. All claims are cited to file:line above. ## Regression notes Found via static audit of the refactor branch; not verified against main. The correct fix pattern already exists in-repo — the webhook path in `commands/storage/custom_tools.rs` sets redirect `Policy::none()` (line 144), re-validates each redirect target (158-185), pins the resolved IP via `resolve_to_addrs` (146) with `is_local_or_reserved_ip` checks (225/243), and gates local targets behind `WEBHOOK_LOCAL_URLS_ENABLED` (195-210). This is therefore an inconsistent application of an existing control, not a missing capability. ## Additional context Server mode escalates impact: `load_url_binary` is exposed via `http_dispatch.rs:96/767`, so a deployed host becomes an IMDS / internal-service proxy for any client past the request gate. Suggested fix: in `http_binary`, call `is_allowed_outbound_url(url, false)`, build the client with `.redirect(reqwest::redirect::Policy::none())`, re-validate each redirect `Location` against the same policy, and pin the DNS-resolved address — mirroring `custom_tools.rs`. ## Template check Please uncheck 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:27:38 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2374, merged into refactor (squash 04cb07dd).

<!-- gh-comment-id:4637084490 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2374, merged into `refactor` (squash 04cb07dd).
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#1136
No description provided.