[PR #2027] [MERGED] Restore custom tool webhook safety guards #5399

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2027
Author: @Xelvanis
Created: 6/3/2026
Status: ✅ Merged
Merged: 6/3/2026
Merged by: @TheLonelyDevil9

Base: refactor ← Head: fix/custom-tool-webhook-guards


📝 Commits (3)

  • 76164ca custom tools: restore webhook safety guards
  • f3135af custom tools: tighten webhook review guards
  • db9e56c custom tools: handle bracketed IPv6 webhook literals

📊 Changes

2 files changed (+523 additions, -32 deletions)

View changed files

📝 src-tauri/crates/security/src/lib.rs (+125 -9)
📝 src-tauri/src/commands/storage/custom_tools.rs (+398 -23)

📄 Description

Linked issue

Closes #2016

Why this change

  • Refactor custom tool webhooks no longer matched the legacy safe-fetch behavior.
  • Legacy allowed public webhook calls by default, required WEBHOOK_LOCAL_URLS_ENABLED=true for local/private targets, capped success bodies at 512 KiB, and validated redirect hops.
  • The refactor path accepted local/private targets too broadly and read webhook responses without the legacy body cap.

What changed

  • Restored the legacy local/private webhook opt-in policy for custom tools.
  • Added local, private, reserved, and metadata-address detection for outbound URL checks.
  • DNS-checks and pins non-local webhook host resolutions before sending the request.
  • Disabled automatic reqwest redirects and follows redirects manually with per-hop URL validation plus a five-hop limit.
  • Restored the 512 KiB custom-tool webhook response cap.
  • Added focused Rust coverage for local/private rejection, redirected private targets, public relative redirects, and oversized responses.

Refactor impact

Primary owner:

Rust storage / custom tool executor

Impact areas reviewed:

  • Custom tool execution command
  • Shared Rust outbound URL policy helper
  • Embedded Tauri custom-tool execution path
  • Remote /api/invoke custom-tool execution path

Boundary notes:

  • Behavior stays in src-tauri; no React, engine, shared API, or command registration changes.
  • Embedded and remote execution already route through the same Rust executor, so both paths share the restored policy.
  • The security helper remains a Rust capability helper and does not introduce feature-layer coupling.

Pressure points touched:

  • src-tauri/src/commands/storage/custom_tools.rs
  • src-tauri/crates/security/src/lib.rs
  • Not touched: ModeSurface, GameSurface, shared mode UI, src-tauri/src/lib.rs command registration, import modules.

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 test --manifest-path src-tauri/Cargo.toml custom_tool - passed locally
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-security outbound_url_policy - passed locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace - passed locally
  • pnpm check - passed locally
  • git diff --check - clean

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:

  • Restores existing custom-tool webhook safety behavior; no new user-discoverable feature or workflow.

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

Docs/release notes: no docs changes needed; this restores existing legacy safety behavior for an existing custom-tool webhook path and does not alter contributor workflow or public docs.

UI evidence

N/A - Rust custom tool webhook policy only; no visible UI changes.

Summary by CodeRabbit

  • New Features

    • Added environment flag to control webhook access to local and reserved network addresses.
    • Implemented automatic redirect handling for webhooks with policy-based validation.
    • Enforced response size limits on webhook payloads.
  • Bug Fixes

    • Enhanced outbound URL validation for local and reserved IP addresses.
    • Improved webhook scheme enforcement (HTTPS always allowed; HTTP conditional).
  • Tests

    • Expanded test coverage for webhook URL policy validation and redirect handling.

Review Change Stack


🔄 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/2027 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/3/2026 **Merged by:** [@TheLonelyDevil9](https://github.com/TheLonelyDevil9) **Base:** `refactor` ← **Head:** `fix/custom-tool-webhook-guards` --- ### 📝 Commits (3) - [`76164ca`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76164cae20a63e2b2b031eef303f8304df98f17d) custom tools: restore webhook safety guards - [`f3135af`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f3135af1e78907e69b0ba1b7fffd39bb99a3f93b) custom tools: tighten webhook review guards - [`db9e56c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/db9e56c04112b0a2f35a11df9d2abf2209a59f3d) custom tools: handle bracketed IPv6 webhook literals ### 📊 Changes **2 files changed** (+523 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/security/src/lib.rs` (+125 -9) 📝 `src-tauri/src/commands/storage/custom_tools.rs` (+398 -23) </details> ### 📄 Description ## Linked issue Closes #2016 ## Why this change - Refactor custom tool webhooks no longer matched the legacy safe-fetch behavior. - Legacy allowed public webhook calls by default, required `WEBHOOK_LOCAL_URLS_ENABLED=true` for local/private targets, capped success bodies at 512 KiB, and validated redirect hops. - The refactor path accepted local/private targets too broadly and read webhook responses without the legacy body cap. ## What changed - Restored the legacy local/private webhook opt-in policy for custom tools. - Added local, private, reserved, and metadata-address detection for outbound URL checks. - DNS-checks and pins non-local webhook host resolutions before sending the request. - Disabled automatic reqwest redirects and follows redirects manually with per-hop URL validation plus a five-hop limit. - Restored the 512 KiB custom-tool webhook response cap. - Added focused Rust coverage for local/private rejection, redirected private targets, public relative redirects, and oversized responses. ## Refactor impact Primary owner: Rust storage / custom tool executor Impact areas reviewed: - Custom tool execution command - Shared Rust outbound URL policy helper - Embedded Tauri custom-tool execution path - Remote `/api/invoke` custom-tool execution path Boundary notes: - Behavior stays in `src-tauri`; no React, engine, shared API, or command registration changes. - Embedded and remote execution already route through the same Rust executor, so both paths share the restored policy. - The security helper remains a Rust capability helper and does not introduce feature-layer coupling. Pressure points touched: - `src-tauri/src/commands/storage/custom_tools.rs` - `src-tauri/crates/security/src/lib.rs` - Not touched: ModeSurface, GameSurface, shared mode UI, `src-tauri/src/lib.rs` command registration, import modules. ## 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 test --manifest-path src-tauri/Cargo.toml custom_tool` - passed locally - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-security outbound_url_policy` - passed locally - `cargo check --manifest-path src-tauri/Cargo.toml --workspace` - passed locally - `pnpm check` - passed locally - `git diff --check` - clean ## 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: - Restores existing custom-tool webhook safety behavior; no new user-discoverable feature or workflow. ## 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 Docs/release notes: no docs changes needed; this restores existing legacy safety behavior for an existing custom-tool webhook path and does not alter contributor workflow or public docs. ## UI evidence N/A - Rust custom tool webhook policy only; no visible UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added environment flag to control webhook access to local and reserved network addresses. * Implemented automatic redirect handling for webhooks with policy-based validation. * Enforced response size limits on webhook payloads. * **Bug Fixes** * Enhanced outbound URL validation for local and reserved IP addresses. * Improved webhook scheme enforcement (HTTPS always allowed; HTTP conditional). * **Tests** * Expanded test coverage for webhook URL policy validation and redirect handling. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/2027?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- 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-22 04:15: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-Engine#5399
No description provided.