Skip to content

Studio: open localhost addresses typed in the desktop browser panel - #14290

Merged
danielhanchen merged 42 commits into
unslothai:mainfrom
NilayYadav:browser-panel-localhost-grants
Oct 22, 2026
Merged

danielhanchen merged 42 commits into
unslothai:mainfrom
NilayYadav:browser-panel-localhost-grants

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #14257

The desktop browser panel refused every local address, so a dev server on the same computer could not be opened beside the chat or checked by the browser agent.

Typing a local address such as localhost:7860 in the address bar now opens it in that tab, with a Local badge. Each local tab gets its own proxy that only reaches that origin, and private storage; access ends when the tab closes or leaves the address. Links, redirects, popups and the agent cannot open a new local address, and the agent uses a separate tab for public sites. Studio's own ports (8888–8908, the backend port and every port from 32768 up) are never opened. On macOS, a page whose content rules or proxy can't be set up is closed with an error instead of loading. The web app and server installs are unchanged.

Trade-off: dev servers on port 32768 or above cannot be opened.

Before / after

Desktop app (Linux debug build, WebKitGTK), merge base vs this PR: typing localhost:5173 (a dev server) was refused and now opens with a Local badge; a link from that page to https://example.com is offered with an Open prompt instead of followed; localhost:8888 (the app's own backend) stays refused, now naming it as Unsloth's own address.

Desktop browser panel before and after

Web Studio (parity): localhost, 127.0.0.1 and public sites behave the same on both sides.

Web browser panel parity

@NilayYadav NilayYadav self-assigned this Oct 19, 2026
[skip ci]
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T09:27:42.425927Z 3268b83 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d2e5750b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +534 to +535
if !matches!(origin, Some(url::Origin::Tuple(_, granted, granted_port))
if *granted_port == port && granted.to_string() == host)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the granted scheme in local proxy routing

On Windows/Linux, if a granted http://localhost:P page issues an https://localhost:P or wss://localhost:P subresource request (or the inverse), this match discards the origin's scheme and treats the request as granted based only on host and port. Those subresources are not covered by the top-document navigation checks, so a dual-protocol or multiplexed local port is dialed directly instead of falling through to the private-host refusal, exposing an origin the user never granted; include the effective HTTP/WS scheme in the grant check.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: the local proxy only dials the exact host and port typed in the address bar, so a different scheme on that port reaches the same listener the user granted, never another service. A CONNECT tunnel also does not say whether it carries ws, wss or https, so the scheme cannot be enforced reliably at this layer. The macOS rules pin the scheme because there a default port is dropped from the URL, and that let port 80 reach 443.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81af72fe4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

inner.committed.remove(&tab_id);
inner.download_starts.remove(&tab_id);
inner.placed.remove(&tab_id);
inner.local_pages.remove(&tab_id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep local profiles until their grants are forgotten

When a local tab's native view is pruned or the browser panel unmounts, the frontend deliberately closes it with forgetLocal: false so the tab can reopen, but this unconditional removal also drops LocalPage.profile. The next create_view allocates a fresh temporary/incognito profile, so on Windows/Linux the same still-open tab loses its cookies and local storage merely by closing and reopening the panel or exceeding the view cap; this drop also occurs before the live WebView is closed below. Keep the per-tab profile until forget_local is true, separately from the short-lived proxy/view.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: local views are created incognito, which is an ephemeral web context on Linux, InPrivate on Windows and a non-persistent data store on macOS, so cookies and storage never outlive the view whether or not the folder is kept. Keeping a session across view recreation would need a persistent per-tab store, and local tabs use temporary storage on purpose.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c8fbc7315

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/src-tauri/src/browser_webview.rs Outdated
Comment on lines +332 to +333
if port.is_some_and(|port| port >= ASSIGNED_PORTS || (8888..=8908).contains(&port))
|| port == backend

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude the configured Vite port from local grants

When the desktop runs with the checked-in development configuration, Studio itself listens on localhost:5173 (studio/src-tauri/tauri.conf.json), and that Vite server forwards /api and /v1 to the otherwise-blocked backend (studio/frontend/vite.config.ts). This predicate permits port 5173, so typing that address opens Studio's own origin in a local view and makes those backend routes reachable through the allowed port; reject the configured dev-server port as another Studio-owned address.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: 5173 is Studio only under tauri dev (contributor builds; release Desktop serves the UI from the bundled backend, whose port is already refused), the address has to be typed by the user, and the backend still requires its auth token. Refusing 5173 in release builds would block Vite's default port, the most common dev server users would open here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 81fa6ce, scoped to where it is real: a release build loads the app from its own scheme, so 5173 there is the user's dev server and stays openable. In a dev build (tauri::is_dev()) the configured devUrl port is now refused with the backend's, so the dev server that serves the app and forwards /api can't be opened. 3e2222e covered only the agent side of 8888-8908, not this. Test the_dev_server_the_app_is_served_from_is_never_granted added; it fails with the check removed.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81fa6ce01e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

rules.push(serde_json::json!({
"trigger": {
"url-filter": format!("^{scheme_filter}://([^/@]*@)?{authority}/"),
"if-top-url": [format!("^{scheme}://([^/@]*@)?{authority}/")],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve local access from generated local documents

On macOS 14+, if a granted app navigates its top frame to an HTML blob: URL, local_navigation_allowed keeps that document in the local view and the blob retains the granted origin, but this if-top-url pattern only matches a top URL beginning with the original http(s) scheme. The ignore rule therefore stops firing and the preceding private-host rules block the blob document's fetches or WebSockets back to the granted server, even though the same flow works on Windows/Linux; the top-frame condition needs to preserve the exact-origin exception for inherited generated documents too.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: it needs a granted app to navigate its top frame to a blob: document, which dev servers do not do in normal use, and the result fails closed (that document's requests back to the server are blocked on macOS) rather than opening anything. Widening the if-top-url pattern to generated documents would loosen the one rule that pins the exception to the typed origin.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 81fa6ce01e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d31a04d5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

thread_local! {
// WebKit objects live on the main thread, and so does this.
static RULES: RefCell<Rules> = RefCell::new(Rules::default());
static RULES: RefCell<std::collections::HashMap<Option<url::Origin>, Rules>> = RefCell::new(std::collections::HashMap::new());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Evict unused per-origin macOS content rules

On macOS 14+, every distinct loopback origin (for example, a dev server whose port changes) leaves a Retained<WKContentRuleList> in this thread-local map, while neither tab close nor clear-data removes it. Over a long-running session the native rule objects therefore grow without bound; cap or evict this cache and remove unused identifiers from WKContentRuleListStore.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: one compiled list is kept per local origin the user typed in the session, which is a handful at most, and the lists live only for the session. That is bounded by what the user types, not a leak that grows on its own, and evicting a list still attached to a live view would need more bookkeeping than it saves.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 3aa240d6e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Resolves the conflicts with main's redirect-link unwrapping and page permission
handler: the agent's local-address gate checks the redirect target, redirect
tests that relied on a port-80 loopback refusal point at Studio's own port, and
the startup budget is re-measured on top of main.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 3268b83f15

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from NilayYadav Oct 22, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 22, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 22, 2026
Re-measures the startup budget on top of main's latest raise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add a setting to allow localhost sites to be opened in the built-in browser

2 participants