Repository navigation
Studio: correct the keyless tunnel copy, which promised more than the code does - #9690
Conversation
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.
There was a problem hiding this comment.
💡 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".
| if _public_tunnel_active(app_state): | ||
| return False |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
…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.
|
@codex review |
There was a problem hiding this comment.
💡 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."; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
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.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
CI status, since the red checks here are misleading. Every red check on this PR is I replicated this branch onto a staging repo, cut from fresh That file is on So the only genuine failure reachable from here is a pre-existing one with a fix already open. Nothing on this branch is failing. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
I checked the new sentence against The wording still says only what stops working, not what keeps working. Separating a tunnel from secure mode would need
|
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:
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:
An externally run cloudflared or ngrok sets neither
app_state.cloudflare_urlnor_remote_connector_active. Those are only ever written byset_studio_tunnel_runtime_callback(run.py:3064) and byrun.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.For the tunnel Studio does manage, the origin is
app.state.server_request_host, which_bound_request_hostreports 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 withHost: <id>.trycloudflare.com, and_host_authority_is_directrefuses a name whatever the transport.test_keyless_api_access_adversarial.pyalready covers that.The change
activeExposureWarningno 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_exposurealso returnspublic_urlforapp_state.secure, where_hosted_mode_forbiddenrejects every transport including LAN, so "the LAN listener keeps serving" would be false there. The same suffix is appended to thefulldialog, and full is loopback-only regardless. Telling the two causes apart would needaccess_exposureto report them separately, which is more than a copy fix.tests/studio/test_usage_examples_model_source_contract.pypinned the old fragmentincluding on localhost, so it had to move with the copy. It now pinsdisabled 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 passedtest_usage_examples_model_source_contract.py: 17 passedmain.git diff origin/mainis the new test file, the one string, and the one-line guard update