[PR #2413] [MERGED] Harden provider config fetch safety #5595

Closed
opened 2026-10-22 04:17:40 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2413
Author: @Promansis
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Promansis

Base: refactor ← Head: issue-2390-config-fetch-safety


📝 Commits (1)

  • 327e7c9 Harden provider config fetch safety

📊 Changes

6 files changed (+1984 additions, -239 deletions)

View changed files

📝 src-tauri/Cargo.lock (+1 -0)
📝 src-tauri/crates/llm/Cargo.toml (+1 -0)
📝 src-tauri/crates/llm/src/lib.rs (+382 -42)
📝 src-tauri/crates/security/src/lib.rs (+142 -9)
📝 src-tauri/src/commands/storage/images/providers.rs (+497 -45)
📝 src-tauri/src/commands/storage/llm.rs (+961 -143)

📄 Description

Linked issue

Closes #2390

Why this change

Surface 10-CONN-ERROR-config-url-and-provider-error-safety from #2384 regressed from legacy connection safety: refactor config/model/test fetches treated all local/private HTTP(S) targets as allowed and read provider error bodies fully before truncating or sanitizing.

What changed

  • Added a provider URL policy that allows loopback provider targets by default while blocking private, LAN, metadata, mDNS/internal/onion, and reserved targets unless the provider/image local URL opt-in is explicit.
  • Routed connection model/test GETs through a policy-aware redirect loop that revalidates each redirect target before following it.
  • Added bounded 5 MiB response readers before parsing or sanitizing model/test, LLM provider, and image provider responses.
  • Kept provider error sanitization/redaction behavior while preventing oversized HTML/error bodies from being buffered first.

Refactor impact

Primary owner:

Rust storage/provider transport and security capability helpers.

Impact areas reviewed:

  • src-tauri/src/commands/storage/llm.rs connection auth/model list paths
  • src-tauri/crates/security/src/lib.rs outbound/provider URL policy helpers
  • src-tauri/crates/llm/src/lib.rs provider transport error/body reads
  • src-tauri/src/commands/storage/images/providers.rs image provider response parsing

Boundary notes:

Rust-only change. No React UI, engine, shared API, command registration, or remote-runtime TypeScript routing changes. Local/private provider opt-ins remain environment-scoped via PROVIDER_LOCAL_URLS_ENABLED and IMAGE_LOCAL_URLS_ENABLED.

Pressure points touched:

None of ModeSurface, GameSurface, shared mode UI, src-tauri/src/lib.rs command registration, or import modules were touched.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • cargo check --manifest-path src-tauri/Cargo.toml
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-security provider_url_policy_allows_loopback_but_blocks_private_without_opt_in -- --nocapture
  • cargo test --manifest-path src-tauri/Cargo.toml provider_model_url_policy_allows_loopback_but_blocks_private_targets -- --nocapture
  • cargo test --manifest-path src-tauri/Cargo.toml provider_model_redirect_revalidates_private_target -- --nocapture
  • cargo test --manifest-path src-tauri/Cargo.toml provider_config_response_body_is_capped -- --nocapture
  • cargo test --manifest-path src-tauri/Cargo.toml image_provider_response_body_is_capped -- --nocapture
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-llm ensure_url_allowed_redacts_query_secret -- --nocapture
  • Static grep confirmed no raw response.text(), response.bytes(), or json::<Value>() remains on the targeted model/test/image/LLM provider response paths.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

Security/parity bugfix for existing provider config fetch behavior; no new user-discoverable feature.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

No UI changes.


🔄 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/2413 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `refactor` ← **Head:** `issue-2390-config-fetch-safety` --- ### 📝 Commits (1) - [`327e7c9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/327e7c949ff039238b4988c54501b41012eea20f) Harden provider config fetch safety ### 📊 Changes **6 files changed** (+1984 additions, -239 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/Cargo.lock` (+1 -0) 📝 `src-tauri/crates/llm/Cargo.toml` (+1 -0) 📝 `src-tauri/crates/llm/src/lib.rs` (+382 -42) 📝 `src-tauri/crates/security/src/lib.rs` (+142 -9) 📝 `src-tauri/src/commands/storage/images/providers.rs` (+497 -45) 📝 `src-tauri/src/commands/storage/llm.rs` (+961 -143) </details> ### 📄 Description ## Linked issue Closes #2390 ## Why this change Surface `10-CONN-ERROR-config-url-and-provider-error-safety` from #2384 regressed from legacy connection safety: refactor config/model/test fetches treated all local/private HTTP(S) targets as allowed and read provider error bodies fully before truncating or sanitizing. ## What changed - Added a provider URL policy that allows loopback provider targets by default while blocking private, LAN, metadata, mDNS/internal/onion, and reserved targets unless the provider/image local URL opt-in is explicit. - Routed connection model/test GETs through a policy-aware redirect loop that revalidates each redirect target before following it. - Added bounded 5 MiB response readers before parsing or sanitizing model/test, LLM provider, and image provider responses. - Kept provider error sanitization/redaction behavior while preventing oversized HTML/error bodies from being buffered first. ## Refactor impact Primary owner: Rust storage/provider transport and security capability helpers. Impact areas reviewed: - `src-tauri/src/commands/storage/llm.rs` connection auth/model list paths - `src-tauri/crates/security/src/lib.rs` outbound/provider URL policy helpers - `src-tauri/crates/llm/src/lib.rs` provider transport error/body reads - `src-tauri/src/commands/storage/images/providers.rs` image provider response parsing Boundary notes: Rust-only change. No React UI, engine, shared API, command registration, or remote-runtime TypeScript routing changes. Local/private provider opt-ins remain environment-scoped via `PROVIDER_LOCAL_URLS_ENABLED` and `IMAGE_LOCAL_URLS_ENABLED`. Pressure points touched: None of ModeSurface, GameSurface, shared mode UI, `src-tauri/src/lib.rs` command registration, or import modules were touched. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `cargo check --manifest-path src-tauri/Cargo.toml` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-security provider_url_policy_allows_loopback_but_blocks_private_without_opt_in -- --nocapture` - `cargo test --manifest-path src-tauri/Cargo.toml provider_model_url_policy_allows_loopback_but_blocks_private_targets -- --nocapture` - `cargo test --manifest-path src-tauri/Cargo.toml provider_model_redirect_revalidates_private_target -- --nocapture` - `cargo test --manifest-path src-tauri/Cargo.toml provider_config_response_body_is_capped -- --nocapture` - `cargo test --manifest-path src-tauri/Cargo.toml image_provider_response_body_is_capped -- --nocapture` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-llm ensure_url_allowed_redacts_query_secret -- --nocapture` - Static grep confirmed no raw `response.text()`, `response.bytes()`, or `json::<Value>()` remains on the targeted model/test/image/LLM provider response paths. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: Security/parity bugfix for existing provider config fetch behavior; no new user-discoverable feature. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence No UI changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:40 +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#5595
No description provided.