Skip to content

fix: accept percent-encoded runtime path prefixes in wss mint (#168) - #178

Merged
chaodu-agent merged 3 commits into
mainfrom
fix/followup-168
Nov 24, 2026
Merged

chaodu-agent merged 3 commits into
mainfrom
fix/followup-168

Conversation

@chaodu-agent

@chaodu-agent chaodu-agent commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Refs #168. This PR fixes only the percent-encoded runtime prefix item.

Change

  • mint_inner no longer rejects every % in the runtime. A %XX escape is accepted in the path prefix. A malformed escape (%zz, %2) is refused.
  • The decoded path must not carry control characters, @, ?, # or \, so an escape cannot smuggle userinfo, a query or a fragment past the check. A % in the host part is refused.
  • The admin credential is also checked against the decoded runtime, so a percent-encoded credential is refused before any request and is not stored in grants.json.

Tests

  • wss_mint_accepts_a_percent_encoded_runtime_prefix: fails on main, passes with this change.
  • a_percent_encoded_credential_inside_the_runtime_is_refused_before_any_request: fails on main, passes with this change.
  • a_malformed_or_smuggling_percent_escape_in_the_runtime_is_refused: passes on main. It guards the refusal path that stays in place.

Results on the final head (ece9a9f)

  • Swift: swift build and swift test on the build host: 852 executed, 0 failures.
  • Rust: cargo test on the build host: 601 passed, 1 failed. The failure is proc::tests::a_pid_that_does_not_exist_signals_nothing_and_does_not_panic. The same test fails on current main, so it predates this change.

Left open on #168 for the owner

  • Minimum credential length (changes which credentials are accepted).
  • Trust root alignment between the mint and the WebSocket dial, or documenting the difference.
  • The two LOW items: returning short non-credential error bodies, and the redaction edge case.

The mint refused any runtime containing `%`, so a valid percent-encoded
path prefix such as `ws://host/pod%20a` stopped minting. The runtime is
now parsed for percent escapes: `%XX` is allowed in the path prefix only,
malformed escapes are refused, and the decoded path must not carry
userinfo, query, fragment or control characters. The admin credential is
also checked against the decoded runtime, so an encoded credential cannot
be persisted in grants.json.

Left open on #168 for the owner: minimum credential length, trust root
alignment between mint and dial, and the two LOW items on error body
detail and redaction.

Tests:
- wss_mint_accepts_a_percent_encoded_runtime_prefix (fails on main)
- a_percent_encoded_credential_inside_the_runtime_is_refused_before_any_request (fails on main)
- a_malformed_or_smuggling_percent_escape_in_the_runtime_is_refused (passes on main, guards the refusal)
Rust: 601 passed, 1 failed (proc::tests::a_pid_that_does_not_exist_signals_nothing_and_does_not_panic),
which also fails on current main.
Swift: swift build and swift test, 852 executed, 0 failures.
cargo fmt --check failed in CI on the #168 change. Formatting only.

Re-run on this head: cargo fmt --check passes. cargo test: 601 passed,
1 failed (proc::tests::a_pid_that_does_not_exist_signals_nothing_and_does_not_panic,
also fails on current main). Swift: swift build, swift test: 852 executed, 0 failures.
CI clippy (-D warnings) rejected map_or(true, ..) as unnecessary_map_or.
Same behaviour.

Re-run on this head: cargo fmt --check passes; cargo clippy --all-targets
-D warnings passes; cargo test: 601 passed, 1 failed
(proc::tests::a_pid_that_does_not_exist_signals_nothing_and_does_not_panic,
also fails on current main). One run also failed
liveness_tests::calls_running_when_the_socket_closes_are_cancelled under
load; it passes 5 of 5 when run alone and passed on the next full run.
Swift: swift build, swift test: 852 executed, 0 failures.
@chaodu-agent
chaodu-agent merged commit 3543b18 into main Nov 24, 2026
14 of 16 checks passed
@chaodu-agent

Copy link
Copy Markdown
Contributor Author

Important

CHANGES REQUESTED ⚠️ - The percent-escape support works for the tested cases, but the validator checks a lossy decoded view while the raw string is sent and stored, and encoded / and dot segments pass unchecked.

What This PR Does

Refs #168. mint_inner used to refuse every % in the runtime address. This PR accepts %XX escapes in the path prefix, refuses malformed escapes and any % in the authority, and checks the decoded path for userinfo, query, fragment and backslash characters. It also checks the decoded runtime for the admin credential, so an encoded credential is refused before any request and never reaches grants.json.

How It Works

  • A new percent_decode helper decodes %XX escapes and returns None for a malformed escape. The bytes are converted with String::from_utf8_lossy.
  • The raw runtime goes through the old character check, minus %. The decoded runtime goes through a second check that rejects controls, @, ?, # and \.
  • host_part (everything before the first /) must not contain %.
  • The admin-credential substring check now also runs against the decoded runtime.
  • The raw, still-encoded runtime is what goes into the mint URL ({scheme}://{rest}/admin/sessions/{session}/tools-attach) and what is persisted.

Findings

# Severity Finding Location
1 🟡 Encoded path separators and dot segments (%2F, %2E%2E) are accepted poc/reverse-attach-linux/src/attach/client.rs:138-152
2 🟡 from_utf8_lossy lets invalid UTF-8 escapes such as %FF pass as U+FFFD poc/reverse-attach-linux/src/attach/client.rs:68-88
3 🟡 The decoded check omits is_whitespace, but the comment says the decoded path gets "the same check" poc/reverse-attach-linux/src/attach/client.rs:136-152
4 🟡 The code validates one representation and sends and stores another; there is no canonical form poc/reverse-attach-linux/src/attach/client.rs:141-181
5 🟢 Malformed escapes are refused, the credential check runs on the decoded form, and the new tests fail on main poc/reverse-attach-linux/src/attach/mint_tests.rs:577-617
Finding Details

🟡 F1: Encoded path separators and dot segments are accepted

Inputs such as ws://host/pod%2F..%2Fother and ws://host/pod/%2E%2E/other pass both checks and are concatenated into the mint URL. The admin credential is sent on that request. If a reverse proxy or the runtime router decodes and normalizes the path, the request can leave the intended prefix and reach a different endpoint.

Plain /../ was already accepted on main, and the runtime address is operator-supplied, so this is not a new privilege. It is still the case this PR is about, and the repository already detects plain and encoded .. segments in src/manifest.rs (has_dot_dot), which could be reused here.

Requested change: After decoding, reject . and .. path segments and reject decoded / (and \) inside a segment. Alternatively, define one canonical path form that every consumer uses. Add regression tests for %2F, %2E%2E, mixed case (%2e%2E) and plain ...

🟡 F2: Lossy decoding

percent_decode ends with String::from_utf8_lossy. An escape such as %FF becomes U+FFFD and passes the check, so the validator sees a different string from the one the HTTP client and the server see. Distinct inputs can also map to the same checked string.

This is not a credential bypass: lossy conversion keeps valid spans intact, so a percent-encoded credential is still found. It is still fail-open by construction.

Requested change: Use String::from_utf8(out).ok() so invalid UTF-8 is refused through the existing None path, or validate the decoded bytes directly. Add tests for %FF and an overlong sequence such as %C0%AF.

🟡 F3: The whitespace policy does not match the comment

The raw check rejects is_whitespace. The decoded check rejects only controls and @ ? # \. So %20 is accepted, and the new positive test asserts that it is. That may be intended, but the comment says "The decoded path must pass the same check", which is not true.

Requested change: Choose a policy. Either allow encoded whitespace, fix the comment and test the policy (for example %09 refused as a control and %20 allowed), or apply has_bad_char to the decoded string as well.

🟡 F4: No canonical representation

The validator decodes rest for checking, but the raw encoded string is interpolated into the mint URL and persisted, and the dial loop reuses that raw value later (http.rs:697-711, store.rs:101-114). host_part is a manual split on the first /, which leaves port and IPv6 handling to ureq. Two spellings of the same prefix (/pod%20a and /pod%20%61) are stored as different runtimes.

Requested change: At minimum, document that the raw form is canonical and that the decoded form is used only for refusal checks. Longer term, parse the runtime once with a URL parser (for example the url crate), check the authority and path segments on the parsed value, and send and store its serialized form.

🟢 F5: Well-scoped fix with failing-first tests

  • Malformed escapes (%zz, %2) and % in the authority are refused.
  • Encoded @, ? and NUL are refused through the decoded check.
  • Checking the credential against the decoded runtime closes a real persistence leak into grants.json.
  • Two of the three new tests fail on main and pass here. The third guards the refusal path that stays in place.
  • The PR body lists clearly which follow-up from #164: wss mint, percent-encoded runtime prefixes and three LOW items #168 items are left open.
Baseline Check
  • PR opened: 2026-11-23
  • Head: ece9a9f28661a167dfeee998398e958fc10d0fec
  • Base: main, merge-base 845a6743178f3633447d28d028e2c5888e792ef3 (the current main)
  • Diff: 2 files, +82/-3 (attach/client.rs, attach/mint_tests.rs)
  • Main already has: refusal of every % in the runtime, and a credential substring check against the raw runtime only
  • Net-new value: percent-encoded path prefixes are accepted, and the credential check runs on the decoded form
CI and Validation
  • All GitHub checks pass on ece9a9f, including Swift build and test, both Linux hands nodes, the installer units and the toolchain smoke tests.
  • cargo fmt --check and git diff --check pass locally.
  • The author reports one Rust failure, proc::tests::a_pid_that_does_not_exist_signals_nothing_and_does_not_panic. proc_tests.rs is identical on main and this branch, so the failure predates this PR. Please file it separately.
Reviewer Verdicts
Reviewer Verdict Key points
Reviewer A (architecture) CHANGES REQUESTED F1-F4; prefers one URL parser over a manual split plus a second decoded view; found no host or userinfo bypass
Reviewer B (correctness) CHANGES REQUESTED F1-F4; asks for tests for %2F, %2E%2E, %2520, %FF and a double-encoded credential
Coordinator CHANGES REQUESTED Agrees F1-F4 are hardening and consistency items (yellow), not blockers, because the runtime is operator-supplied and plain .. was already accepted on main

No external reviewer feedback on this PR.

What's Good (🟢)

5. Three Reasons We Might Not Need This PR

  1. Encoded prefixes may not be needed in practice. If deployed runtime prefixes are plain [a-z0-9-] names, keeping the old fail-closed refusal of % is simpler and safer.
  2. It adds a second hand-written URL view. A raw-plus-decoded check is harder to maintain than parsing the runtime once with a real URL parser.
  3. It is partial. The credential minimum length, the trust-root alignment and the LOW items from follow-up from #164: wss mint, percent-encoded runtime prefixes and three LOW items #168 remain open, so this should not be read as finishing the mint validation.

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.

1 participant