Skip to content

login: refuse a sign-in page off the console's origin or a code with control characters - #82

Open
Ahmar004 wants to merge 4 commits into
prooflinedev:mainfrom
Ahmar004:fix/validate-device-sign-in-fields
Open

Ahmar004 wants to merge 4 commits into
prooflinedev:mainfrom
Ahmar004:fix/validate-device-sign-in-fields

Conversation

@Ahmar004

Copy link
Copy Markdown

Fixes #81

The problem in one sentence

proofline login opened 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

  1. proofline login asks the console for a sign-in code (POST /auth/device/code, the RFC 8628 "device flow"). The reply holds user_code (the short code you type), verification_uri (the approval page) and, optionally, verification_uri_complete (the same page with the code filled in).
  2. device::start kept these fields exactly as sent.
  3. login printed user_code raw and passed verification_uri_complete to webbrowser::open after checking only that it parses as some URL. So https://look-alike.example/…, file:///… and custom schemes were all opened.
  4. A control character is an invisible character that tells the terminal to do something (ESC[2J clears 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-origin verification_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.sh this 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.rs only (lib.rs is untouched). device::start now refuses the reply, as a protocol error and before anything is printed or opened, when:

  • verification_uri or verification_uri_complete doesn't parse, isn't http/https, or its origin isn't http.origin() (same rule as the extension). An origin is scheme + host + port. A file: URL has no real origin, so it never matches. The scheme is checked as well because a blob: URL takes the origin of the URL inside it. A new helper, approval_page, does these checks.
  • user_code would be changed by text::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:

Test main this PR
a_sign_in_page_on_another_origin_is_refused (other host for each field, other port only, file: URL, same-origin blob: URL, not a URL) FAILED (start returned Ok) ok
a_sign_in_code_that_could_rewrite_the_terminal_is_refused (ESC[2J, U+202E, newline) FAILED ok
device_sign_in_waits_for_approval_and_keeps_the_organization now also checks the exact URLs returned (/auth/./device → /auth/device, query kept) ok ok

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's Host header, so it is on the stub's real origin, like the console. A test can override any field, and ORIGIN in 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 (check on 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 through cat -v):

Server reply main this PR
code WDJB-MJHT\x1b[2J\u202eTHJM Your sign-in code is WDJB-MJHT^[[2JM-bM-^@M-.THJM. (escapes reach the terminal) … user_code contains control characters, exit 1
verification_uri_complete = https://proofline-login.example/approve accepted (opened without --no-browser) … verification_uri_complete is not on http://127.0.0.1:8765, exit 1, no browser
verification_uri_complete = file:///C:/Windows/System32/calc.exe accepted refused the same way
normal same-origin reply prompt printed, polls same prompt, unchanged

Whole suite: cargo fmt --check clean. cargo test --no-fail-fast gives the same 8 failures on main and on this branch: tests in tests/mcp.rs (5), tests/agent_install.rs, tests/local_patch.rs and src/update/tests.rs that fail on this Windows machine and have nothing to do with sign-in. cargo clippy --all-targets -D warnings reports the same 3 errors on main and here, all in src/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.

Round Finding What I made of it Outcome
1 blob: URL on the console's origin passes the origin check (src/device.rs) Correct: Url::origin() of blob:http://host/id is http://host. Reproduced with a new failing case first. Fixed in c1f35f9: also require http/https
1 Success test doesn't assert the returned URLs (tests/http.rs) Correct: dropping the complete URL or returning raw text would go unnoticed. Fixed in c1f35f9 (+ c8eeeee, clippy-safe placeholder): exact values asserted, mutation-checked
2 No case differs from the console only by port Correct, a gap in the test. Fixed in 5ea12ba: http://127.0.0.1:1/..., mutation-checked

Proofline marked round-1 findings fixed itself. Commit 5ea12ba started a third automatic review, which I'm not answering, per the 2-round cap.

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proofline login opens and prints the server's sign-in address and code without checking them

1 participant