Repository navigation
Conversation
…control characters When you run `proofline login`, the server answers with an approval page address and a short code. The CLI opened that address in the browser without checking where it pointed, and printed the code as is. A mis-routed, compromised or custom --base-url server could therefore make the CLI open another site (a look-alike approval page) or a file: or custom-scheme URL, and could put terminal escape sequences (ESC[2J clears the screen) or bidi controls (U+202E reverses the text) into the sign-in prompt. device::start now refuses the reply, before anything is printed or opened, when: - verification_uri or verification_uri_complete does not parse, or is not on http.origin() (same rule as the Chrome extension's auth.ts); - user_code is changed by text::one_line, i.e. it holds a control or bidi character. The returned addresses are the parsed URLs' ASCII serialization. Refusing instead of cleaning the code: a cleaned code would differ from the one the server expects, so the person would type a code that can never be approved. Tests (tests/http.rs): a_sign_in_page_on_another_origin_is_refused and a_sign_in_code_that_could_rewrite_the_terminal_is_refused fail on main and pass now. The device-code stub now answers with its real origin (from the Host header); before, it had no port, so it was off-origin.
| let verification_uri = approval_page(http, "verification_uri", &body.verification_uri)?; | ||
| let verification_uri_complete = body | ||
| .verification_uri_complete | ||
| .map(|address| approval_page(http, "verification_uri_complete", &address)) |
There was a problem hiding this comment.
Warning · Approval URL validation accepts same-origin blob: URLs
approval_page promises to reject custom schemes, but compares only origins. A blob: URL inherits its embedded URL’s origin and passes when that origin matches the console.
The CLI accepts an unsupported approval URL and may pass it to the browser.
Require the outer scheme to be http or https before comparing origins.
Details
Before this change, both fields were passed through without validation. This change introduces the scheme-rejection contract but does not enforce it for either field.
There was a problem hiding this comment.
Fixed in c1f35f9. Agreed: Url::origin() returns the inner URL's origin for blob:, so blob:<console origin>/id passed. I reproduced it first (new case in a_sign_in_page_on_another_origin_is_refused returned Ok), then made approval_page also require the http/https scheme. Same-origin plus an http(s) scheme means the scheme equals the console's.
| async fn code(State(fake): State<Fake>, headers: HeaderMap) -> Json<Value> { | ||
| let host = headers[header::HOST].to_str().unwrap(); | ||
| let mut body = json!({ | ||
| "device_code": "d".repeat(52), |
There was a problem hiding this comment.
Warning · Successful sign-in test misses approval URL regressions
The fixture supplies already-serialized URLs, and the success test asserts neither URL returned by device::start.
The test still passes if validation succeeds but the complete URL is dropped or the original URL strings are returned unchanged.
Supply same-origin URLs that change on serialization and assert both exact serialized values, including the complete URL’s query.
There was a problem hiding this comment.
Fixed in c1f35f9 (placeholder renamed in c8eeeee). Agreed. The stub now accepts an ORIGIN placeholder, and the success test sends same-origin pages with dot segments (ORIGIN/auth/./device, ORIGIN/auth/x/../device?user_code=WDJB-MJHT) and asserts the exact cleaned-up values of both fields, including the query. Checked by mutation: making approval_page return the raw string fails the test (/auth/./device vs /auth/device).
…URLs
Proofline review, round 1.
1. A blob: URL takes the origin of the URL inside it, so
"blob:<console origin>/id" passed the origin check although it is not
a web page. approval_page now also requires the http or https scheme.
New case in a_sign_in_page_on_another_origin_is_refused (failed before
this change).
2. The sign-in test did not look at the URLs start returns, so it would
still pass if the complete URL were dropped or the raw text returned.
The stub now takes "{origin}" in an overriding field, and the test sends
same-origin pages with dot segments ("/auth/./device") and asserts the
exact cleaned-up values. Returning the raw text makes it fail.
"{origin}" in a plain string looks like a format argument to clippy
(literal_string_with_formatting_args), which fails with -D warnings.
| #[tokio::test] | ||
| async fn a_sign_in_page_on_another_origin_is_refused() { | ||
| for (field, address) in [ | ||
| ("verification_uri", "https://proofline.example/auth/device"), |
There was a problem hiding this comment.
Warning · Approval URL test misses port-only origin mismatches
Both HTTP(S) rejection cases change the scheme and hostname, so the test still passes if approval_page compares those components but ignores the port.
The test would miss a regression that accepts approval URLs on a different port.
Add a URL with the fixture’s scheme and hostname but a guaranteed different port, and assert a field-specific Protocol error.
There was a problem hiding this comment.
Fixed in 5ea12ba. Agreed. Added http://127.0.0.1:1/auth/device: same scheme and host as the stand-in, port 1, which the ephemeral test port never is. It goes through the same field-specific Protocol assertion. Checked by mutation: comparing only the host makes the test fail.
…port Proofline review, round 2: every refused http(s) case also changed the host, so a check that ignored the port would still pass. The new case keeps the stand-in's scheme and host and uses port 1, which an ephemeral test port never is. A host-only comparison makes it fail.
| let verification_uri = approval_page(http, "verification_uri", &body.verification_uri)?; | ||
| let verification_uri_complete = body | ||
| .verification_uri_complete | ||
| .map(|address| approval_page(http, "verification_uri_complete", &address)) |
There was a problem hiding this comment.
Warning · Device sign-in tests miss a required-complete-URL regression
Every device-code fixture supplies verification_uri_complete, so the new URL-validation coverage would still pass if device::start rejected responses that omit it.
Sign-in could fail before falling back to verification_uri without a test failing.
Add a successful response that omits verification_uri_complete and assert that the returned field is None.
Details
The base fixture also supplied both URLs, but it did not exercise the approval-URL validation added by this change.
Fork review PR (Proofline). Upstream issue to follow.
The problem in one sentence
proofline loginopened whatever approval address the server sent, on any site or scheme, and printed the sign-in code with any hidden terminal control characters in it.Why it happens, step by step
proofline loginasks the console for a sign-in code (POST /auth/device/code, the RFC 8628 "device flow"). The reply holdsuser_code(the short code you type),verification_uri(the approval page) and, optionally,verification_uri_complete(the same page with the code filled in).device::startkept these fields exactly as sent.loginprinteduser_coderaw and passedverification_uri_completetowebbrowser::openafter checking only that it parses as some URL. Sohttps://look-alike.example/…,file:///…and custom schemes were all opened.ESC[2Jclears the screen). A bidi control (U+202E) makes the text after it display reversed. Both reached the terminal unchanged.The rest of the CLI already treats server text as untrusted (
text::terminal_safe/text::one_line), and the Proofline Chrome extension already refuses an off-originverification_uri_complete(lib/proofline/auth.ts). The CLI's sign-in was the one path that skipped both.Who is affected
With the default
https://proofline.shthis is defense in depth. It matters with a custom--base-url/PROOFLINE_BASE_URL(local or staging consoles), or a mis-routed or compromised origin: the reply could send you to a look-alike approval page, open a local file or a protocol handler, or rewrite the sign-in prompt.What this PR changes
src/device.rsonly (lib.rsis untouched).device::startnow refuses the reply, as a protocol error and before anything is printed or opened, when:verification_uriorverification_uri_completedoesn't parse, or its origin isn'thttp.origin()(same rule as the extension). Afile:URL has an opaque origin, so it never matches. A new helper,approval_page, does this check.user_codewould be changed bytext::one_line, meaning it holds a control or bidi character.The kept addresses are the parsed URLs' serialization. That text is ASCII only, so printing it is safe.
Why refuse the code instead of cleaning it
A cleaned code (control characters replaced by
�) would differ from the one the server expects, so the person would type a code that can never be approved. A clear error is better. A real console never sends such a code: RFC 8628 §6.1 recommends a short code from a small set of letters.How I tested it (Windows 11, Rust 1.100.0)
Regression tests (
tests/http.rs), written first:maina_sign_in_page_on_another_origin_is_refused(other host for each field,file:URL, not a URL)startreturnedOk)a_sign_in_code_that_could_rewrite_the_terminal_is_refused(ESC[2J, U+202E, newline)The device-code stub used to answer
http://127.0.0.1/auth/device, with no port, so it was already off-origin. It now builds the page from the request'sHostheader, so it is on the stub's real origin, like the console. The existing sign-in tests still pass.cargo test --test http: 42 passed.End to end, the real binary against a tiny local stand-in server (
proofline login --base-url http://127.0.0.1:8765, output throughcat -v):mainWDJB-MJHT\x1b[2J\u202eTHJMYour sign-in code is WDJB-MJHT^[[2JM-bM-^@M-.THJM.(escapes reach the terminal)… user_code contains control characters, exit 1verification_uri_complete=https://proofline-login.example/approve--no-browser)… verification_uri_complete is not on http://127.0.0.1:8765, exit 1, no browserverification_uri_complete=file:///C:/Windows/System32/calc.exeWhole suite:
cargo fmt --checkclean.cargo test --no-fail-fastgives the same 8 failures onmainand on this branch: tests intests/mcp.rs(5),tests/agent_install.rs,tests/local_patch.rsandsrc/update/tests.rsthat fail on this Windows machine and have nothing to do with sign-in.cargo clippy --all-targets -D warningsreports the same 3 errors onmainand here, all insrc/agent/tests.rs, which this PR doesn't touch.