security(CORE-1123): block non-http(s) main-frame navigation in server webview - #3397
Conversation
…r webview The guest webview's will-navigate handler only special-cased t.co/ twitter.com redirects to open them externally. There was no general guard preventing an in-page main-frame navigation to a non-web scheme (e.g. file://) inside the server webview. Extend the handler to preventDefault() any will-navigate whose target protocol is not http: or https:, before the existing t.co/twitter.com external-open logic runs (which is unchanged). Adds src/ui/main/serverView/index.spec.ts covering: http allowed, https allowed, file:// denied, unknown custom scheme denied, and the existing t.co/twitter.com external-open behavior.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (2)
🧰 Additional context used📓 Path-based instructions (5)**/*.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{tsx,ts}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.spec.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{spec.ts,main.spec.ts}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🔇 Additional comments (2)
WalkthroughThe will-navigate handler in serverView is updated to parse the redirect URL's protocol first, immediately blocking non-HTTP(S) navigation without checking hostname or protocol allowance, then applying the existing t.co/twitter.com blocklist only for http/https redirects. A new Jest test suite validates this behavior. ChangesWill-navigate Protocol Guard
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant GuestWebContents
participant WillNavigateHandler
participant IsProtocolAllowed
participant ExternalBrowser
GuestWebContents->>WillNavigateHandler: will-navigate(redirectUrl)
WillNavigateHandler->>WillNavigateHandler: parse redirectUrl protocol
alt non-http(s) protocol
WillNavigateHandler->>GuestWebContents: preventDefault()
else http/https protocol
alt hostname in t.co/twitter.com
WillNavigateHandler->>GuestWebContents: preventDefault()
WillNavigateHandler->>IsProtocolAllowed: isProtocolAllowed(redirectUrl)
IsProtocolAllowed-->>WillNavigateHandler: allowed true/false
opt allowed
WillNavigateHandler->>ExternalBrowser: openExternal(redirectUrl)
end
end
end
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
will-navigatehandler only special-casedt.co/twitter.comredirects — a main-frame navigation to a non-web scheme (e.g.file://) inside the webview had no explicit guard.parseDeepLink, electron-dl Save-As flow,setWindowOpenHandler/isProtocolAllowed) — untouched, out of scope.nodeIntegration=false/contextIsolation=true/webSecurity=true, so these vectors don't apply to this app's threat model — adding them would be defending against attacks that can't reach the filesystem or Node from here.will-navigatenowpreventDefault()s any main-frame navigation whose protocol isn'thttp:/https:, before the existing t.co/twitter external-open logic runs. Reuses the existingnew URL()parse (no duplicate parsing).Test plan
npx tsc --noEmitcleanyarn eslintcleansrc/ui/main/serverView/index.spec.ts, 6 cases): http allowed, https allowed, file:// denied, unknown scheme denied, t.co external-open preserved (allowed + denied-by-isProtocolAllowed paths) — all passingSummary by CodeRabbit
httpandhttpsnavigations proceed.