Skip to content

Studio: correct the keyless tunnel copy, which promised more than the code does - #9690

Merged
oobabooga merged 12 commits into
mainfrom
danielhanchen/keyless-tunnel-exposure
Sep 9, 2026
Merged

oobabooga merged 12 commits into
mainfrom
danielhanchen/keyless-tunnel-exposure

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #9102. Independent of #9683.

This PR reversed direction after review. It opened proposing a transport change; that was wrong, and the diff is now a one-line copy fix plus a test. Leaving the history rather than force-rewriting it, since the reasoning is the useful part.

The disagreement

The Keyless API Access card said:

A public URL or tunnel is active, so keyless access remains disabled, including on localhost, until it is stopped.

The code disables keyless on loopback while a tunnel is up, but keeps serving it on an active private LAN listener. So the card promised more than the code delivered. One of the two had to move.

Why the code was right and the copy was wrong

I first assumed the code was at fault. The review pushed back, correctly, and I confirmed both halves at head:

  1. An externally run cloudflared or ngrok sets neither app_state.cloudflare_url nor _remote_connector_active. Those are only ever written by set_studio_tunnel_runtime_callback (run.py:3064) and by run.py / colab.py. _public_tunnel_active() stays false, so no transport check can see that tunnel at all. The scenario I originally cited is undetectable, not under-handled.

  2. For the tunnel Studio does manage, the origin is app.state.server_request_host, which _bound_request_host reports as loopback on a wildcard bind, "so cloudflared's upstream stays local-only" (cloudflare_tunnel.py:401). On that bind tunnelled traffic arrives as a loopback peer and never matches the LAN branch.

So the asymmetry is principled, not an oversight. A tunnel makes a loopback peer ambiguous, because tunnelled internet traffic is indistinguishable from a real local client on that socket. Nothing makes a LAN peer ambiguous the same way. Closing LAN as well would have taken working access away from legitimate LAN clients and bought nothing.

An explicit interface bind is the one case where the managed tunnel does present a LAN origin, and keyless refuses it a layer above the scope branches: Studio starts the quick tunnel with no --http-host-header, so the request arrives with Host: <id>.trycloudflare.com, and _host_authority_is_direct refuses a name whatever the transport. test_keyless_api_access_adversarial.py already covers that.

The change

activeExposureWarning no longer says anything about LAN. It now states only that keyless access is disabled on localhost until the exposure stops.

Dropping the clause rather than correcting it is deliberate. access_exposure also returns public_url for app_state.secure, where _hosted_mode_forbidden rejects every transport including LAN, so "the LAN listener keeps serving" would be false there. The same suffix is appended to the full dialog, and full is loopback-only regardless. Telling the two causes apart would need access_exposure to report them separately, which is more than a copy fix.

tests/studio/test_usage_examples_model_source_contract.py pinned the old fragment including on localhost, so it had to move with the copy. It now pins disabled on localhost, which is the part of the sentence that carries the policy.

Plus a test for the asymmetry. Normally I would not add a test for behaviour that already works, but two readers in a row have now taken this for a bug, and the next one will too. The test says why the two transports differ, so the answer lives in the tree rather than in this thread.

Verification

  • test_keyless_tunnel_exposure.py, test_keyless_api_access.py, test_lan_access_settings.py: 147 passed
  • test_usage_examples_model_source_contract.py: 17 passed
  • Backend logic is byte-identical to main. git diff origin/main is the new test file, the one string, and the one-line guard update

The Keyless API Access card tells the admin that a public URL or tunnel disables
keyless access, including on localhost, until it stops. The exposure check sat
after the LAN branch, so it only ever reached loopback: with a tunnel published,
the LAN listener kept serving keyless.

That is harmless for the tunnel Studio manages, which targets
http://localhost:<port>, so cloudflared connects over loopback and presents a
loopback peer that the LAN branch never matches. It is not harmless when the
admin runs their own cloudflared or ngrok against the LAN address, which the LAN
card displays: the peer is then the LAN interface, request_on_lan_access matches,
and the request was admitted before anything asked whether the server was
published to the internet.

Moved the single check above both scope branches. full scope is unaffected, it
already ran the check first and is loopback-only regardless. Private-LAN
inference with no tunnel is unaffected. Stopping the tunnel restores admission,
so this is an exposure test rather than a latch.

_public_tunnel_active reports True when it cannot read the connector state, so
this also extends that fail-closed answer to the LAN path, which is the behaviour
the loopback path already had.

@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: f6fbbf2d86

ℹ️ 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 +326 to +327
if _public_tunnel_active(app_state):
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Detect unmanaged tunnels before allowing LAN keyless access

When an administrator runs the external cloudflared/ngrok scenario described above this check, neither app_state.cloudflare_url nor Studio's tunnel_connector_active() is updated, so _public_tunnel_active() remains false. The tunnel's local connection to the LAN address is then classified by request_on_lan_access() and admitted without a key, meaning this change only disables LAN keyless access while a Studio-managed tunnel is active and does not close the public exposure it claims to address.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and it changes my conclusion. Confirmed at head: _remote_connector_active is only ever set through set_studio_tunnel_runtime_callback (run.py:2796) and cloudflare_url only by run.py/colab.py, so an externally run cloudflared or ngrok sets neither and _public_tunnel_active() stays false. The scenario I cited is not detected at all.

Worse than not helping: CloudflareTunnel targets http://localhost:<port> deliberately (cloudflare_tunnel.py:402, "so cloudflared's upstream stays local-only"), so managed tunnel traffic always arrives as a loopback peer and never matches the LAN branch. The loopback deny is principled because a tunnel makes loopback peers ambiguous; there is no matching ambiguity on LAN. So the original ordering was right, and my change only removed legitimate LAN keyless access while a managed tunnel is up, for no security gain.

Reworking this PR to fix the settings copy instead, which is the side that is actually wrong.

pre-commit-ci Bot and others added 2 commits August 25, 2026 10:33
…stener

Reverts the transport change from the first commit and fixes the settings copy
instead, which is the side that was actually wrong.

The review is right that an externally run cloudflared or ngrok sets neither
app_state.cloudflare_url nor _remote_connector_active, so _public_tunnel_active
stays false and the scenario the first commit cited is not detected at all. It
also went the wrong way on the case Studio can see: CloudflareTunnel targets
http://localhost:<port> on purpose, so managed tunnel traffic always arrives as
a loopback peer and never matches the LAN branch. Closing LAN therefore removed
working access from legitimate LAN clients and bought nothing.

The original ordering was right. A tunnel makes a loopback peer ambiguous, since
tunnelled traffic is indistinguishable from a real local client on that socket;
nothing makes a LAN peer ambiguous the same way. The card claimed keyless was
disabled everywhere including localhost, which promised more than the code did
and is what sent two readers looking for a bug. It now says the loopback rule and
that a private LAN listener keeps serving.

Keeps a test for the asymmetry, since it reads as an oversight and is not.
@danielhanchen danielhanchen changed the title Studio: stop keyless access on the LAN listener too while a tunnel is up Studio: correct the keyless tunnel copy, which promised more than the code does Aug 25, 2026
@danielhanchen

Copy link
Copy Markdown
Member 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: 0478d0c34c

ℹ️ 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".

): string {
if (exposure === "public_url") {
return " A public URL or tunnel is active, so keyless access remains disabled, including on localhost, until it is stopped.";
return " A public URL or tunnel is active, so keyless access is disabled on localhost until it is stopped. An active private LAN listener still serves it: the tunnel reaches Studio over loopback, so it can never arrive with a LAN address.";

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 Distinguish tunnel inference from other public exposures

When exposure === "public_url" because app_state.secure is true, _hosted_mode_forbidden() rejects every keyless transport, including a live LAN listener, yet this text says the LAN still serves keyless access. The same suffix is also appended to CONFIRM_COPY.full, although full scope is always disabled over LAN, so secure-mode users and users confirming full access while a tunnel is active receive a false, internally contradictory confirmation; limit this claim to managed-tunnel inference or expose enough state to distinguish these cases.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct on both halves. access_exposure returns public_url for app_state.secure as well as for a tunnel, and in the secure case _hosted_mode_forbidden rejects every transport including the LAN listener, so my sentence was false there. It was also appended to CONFIRM_COPY.full, where full is never honored over LAN regardless.

I replaced one inaccuracy with another. Dropped the LAN clause instead of trying to qualify it: the warning now says only that keyless access is disabled on localhost until the exposure stops, which is true for a tunnel and for secure mode, and true in the full dialog too since full is localhost-only. Distinguishing the two causes would need access_exposure to report them separately, which is more than this copy fix should carry.

pre-commit-ci Bot and others added 2 commits August 25, 2026 11:12
access_exposure returns public_url for app_state.secure as well as for a tunnel,
and in the secure case _hosted_mode_forbidden rejects every transport including
the LAN listener, so claiming the LAN keeps serving was false there. The same
suffix is appended to the full dialog, where full is never honored over LAN
regardless.

The warning now says only that keyless access is disabled on localhost until the
exposure stops. True for a tunnel, true for secure mode, and true in the full
dialog since full is localhost-only. Telling the two causes apart would need
access_exposure to report them separately, which is more than a copy fix.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: d7726ce167

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: d7726ce167

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

CI status, since the red checks here are misleading.

Every red check on this PR is cancelled, not failure. On the current head: 36 cancelled, 4 success, 1 skipped, and gh pr checks renders cancelled as "fail". Something is clearing the org Actions queue repo-wide; I re-ran the cancelled runs once and they were cancelled again without a replacement, so re-running is not the answer.

I replicated this branch onto a staging repo, cut from fresh main and merged with this head, to get honest signal. Result: 14 success, 1 skipped, one failure, and that failure is not from this branch:

test_checked_in_file_reads_name_an_encoding
  ['tests/studio/playwright_declared_polls.py:210: write_text()']

That file is on main unchanged and is not touched by this PR. It makes Repo tests (CPU), and so Backend CI, red on every open PR. Fixed separately in #9698.

So the only genuine failure reachable from here is a pre-existing one with a fix already open. Nothing on this branch is failing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-09-08T18:20:26.003332Z c821f2d New commits
ℹ️ 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@oobabooga

Copy link
Copy Markdown
Member

I checked the new sentence against keyless_request_allowed for both reasons access_exposure returns public_url. Localhost is refused under a tunnel and in secure mode. The LAN listener keeps serving inference under a tunnel, which is what the old wording denied. Only the string ships, so the transport policy is byte identical to main. The three keyless and LAN suites pass, along with the source contract guard that had pinned the old fragment.

The wording still says only what stops working, not what keeps working. Separating a tunnel from secure mode would need access_exposure to report them apart, so it is left for later.

Repo tests (CPU) is red on main for the same five tests and is unrelated to this change.

@oobabooga
oobabooga merged commit 7b9bb03 into main Sep 9, 2026
43 of 44 checks passed
@oobabooga
oobabooga deleted the danielhanchen/keyless-tunnel-exposure branch September 9, 2026 20:59
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.

2 participants