Skip to content

security: 为 Tauri WebView 启用最小 CSP#359

Merged
H-Chris233 merged 1 commit into
Open-Less:betafrom
H-Chris233:fix/issue-226-tauri-csp
May 8, 2026
Merged

security: 为 Tauri WebView 启用最小 CSP#359
H-Chris233 merged 1 commit into
Open-Less:betafrom
H-Chris233:fix/issue-226-tauri-csp

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

@H-Chris233 H-Chris233 commented May 8, 2026

User description

概述

  • 将 Tauri WebView 从 csp: null 改为最小 CSP,避免无说明地关闭纵深防御。
  • 限制脚本、对象、base URL、表单提交和嵌入来源,只保留 Tauri IPC 与开发模式本机连接。
  • 增加 docs/tauri-csp.md 记录 CSP 边界,说明 provider / updater / 模型下载走 Rust 侧,不在 WebView CSP 放开外部域名。

验证

  • npm run build
  • npm run tauri -- info
  • cargo check --manifest-path src-tauri/Cargo.toml

Closes #226


PR Type

Enhancement, Documentation


Description

  • Replaced null CSP with minimal Content Security Policy.

  • Restricted script, object, base, form, frame sources.

  • Allowed only IPC, local dev, and inline styles.

  • Added docs/tauri-csp.md explaining boundaries and Rust networking.


Diagram Walkthrough

flowchart LR
  A["Previous: WebView with csp: null"] -- "Enforce" --> B["Minimal CSP enabled"]
  B --> C["script-src: self-only"]
  B --> D["connect-src: IPC & local dev"]
  B --> E["object-src, base-uri, form-action: none"]
  B --> F["New doc: tauri-csp.md"]
  D -- "Keeps networking on Rust side" --> G["Provider/updater/model requests"]
Loading

File Walkthrough

Relevant files
Documentation
tauri-csp.md
Document CSP boundaries and rationale                                       

docs/tauri-csp.md

  • Added documentation explaining the minimal CSP and its boundaries.
  • Lists permitted sources for scripts, styles, fonts, and connections.
  • Clarifies that provider/updater/model networking uses Rust, not
    WebView fetch.
  • Notes CSP is defense-in-depth; QA sanitizer remains primary XSS
    defense.
+10/-0   
Security
tauri.conf.json
Enable minimal CSP in Tauri WebView config                             

openless-all/app/src-tauri/tauri.conf.json

  • Replaced csp: null with a minimal Content Security Policy.
  • Set script-src to 'self', object-src/base-uri/form-action to 'none'.
  • Allowed connect-src only for ipc:, localhost:1420, and WebSocket HMR.
  • Permitted inline styles and Google Fonts for current React UI
    implementation.
+12/-1   

The desktop WebView no longer runs with an unexplained disabled CSP. The policy keeps scripts self-hosted, permits Tauri IPC and local Vite development connections, keeps provider/update/model networking on the Rust side, and documents the only unsafe allowance for React inline styles used by the existing pixel-aligned UI.

Constraint: Issue Open-Less#226 requires csp:null to be replaced or explicitly bounded

Constraint: Provider validation, updater checks, and model downloads are Rust-side paths, not frontend fetch allowlist entries

Rejected: Keep csp:null with documentation only | weaker defense-in-depth and leaves the WebView effectively unconstrained

Confidence: high

Scope-risk: narrow

Directive: Do not add external provider domains to WebView connect-src unless a frontend fetch path is introduced

Tested: npm run build

Tested: npm run tauri -- info

Tested: cargo check --manifest-path src-tauri/Cargo.toml
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

226 - PR Code Verified

Compliant requirements:

  • csp: null was replaced with an explicit CSP policy.
  • A boundary/rationale document was added in docs/tauri-csp.md.
  • script-src, object-src, base-uri, and connect-src are explicitly constrained.
  • The use of unsafe-inline is documented with a local rationale.

Requires further human verification:

  • Main window, capsule, and QA window startup plus IPC behavior under the new CSP.
  • Packaged-app verification that provider validation, model list requests, and update checks still work as expected.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@H-Chris233 H-Chris233 merged commit d51f6ee into Open-Less:beta May 8, 2026
4 checks passed
@H-Chris233 H-Chris233 deleted the fix/issue-226-tauri-csp branch May 9, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(tauri): 为桌面 WebView 建立最小 CSP 或记录关闭边界

1 participant