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.
…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.
…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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #81
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, isn'thttp/https, or its origin isn'thttp.origin()(same rule as the extension). An origin is scheme + host + port. Afile:URL has no real origin, so it never matches. The scheme is checked as well because ablob:URL takes the origin of the URL inside it. A new helper,approval_page, does these checks.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, other port only,file:URL, same-originblob:URL, not a URL)startreturnedOk)a_sign_in_code_that_could_rewrite_the_terminal_is_refused(ESC[2J, U+202E, newline)device_sign_in_waits_for_approval_and_keeps_the_organizationnow also checks the exact URLs returned (/auth/./device→/auth/device, query kept)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. A test can override any field, andORIGINin it stands for that origin. Mutation checks: returning the raw address fails the success test, and comparing only the host fails the port case.cargo test --test http: 42 passed. Fork CI (checkon Linux,windows): pass.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.Proofline review log
Fork review PR: Ahmar004#2 (2 rounds, the cap for this contribution). 3 findings, 3 fixed, 0 disagreed.
blob:URL on the console's origin passes the origin check (src/device.rs)Url::origin()ofblob:http://host/idishttp://host. Reproduced with a new failing case first.c1f35f9: also requirehttp/httpstests/http.rs)c1f35f9(+c8eeeee, clippy-safe placeholder): exact values asserted, mutation-checked5ea12ba:http://127.0.0.1:1/..., mutation-checkedProofline marked round-1 findings fixed itself. Commit
5ea12bastarted a third automatic review, which I'm not answering, per the 2-round cap.