Skip to content

fix(ra-rpc): keep caller-supplied text from forging log lines - #1401

Merged
kvinwang merged 1 commit into
nextfrom
fix/ra-rpc-log-lines
Sep 25, 2026
Merged

kvinwang merged 1 commit into
nextfrom
fix/ra-rpc-log-lines

Conversation

@kvinwang

Copy link
Copy Markdown
Collaborator

Problem

The shared pRPC layer writes caller-controlled text into service logs verbatim:

  • dispatch_prpc logs dispatching request: {path}, where path is the <method> route segment. Rocket percent-decodes it, so POST /prpc/Info%0A<forged line> puts a raw newline into the gateway's (or any service's) log. On the gateway that listener is public.
  • rpc error: and error handling prpc: log the error chain. fix(ra-rpc): bound the error text a failed call returns, and return it in the caller's representation #1234 bounded it to 2 KiB, but line breaks survive. On the VMM, a GuestApi call relays the guest agent's {"error": "..."} body (http-client server_error_message) as the VMM's own error. A tenant's guest can therefore write complete, well-formed lines into the host VMM log, which it does not trust.

dstack_types::sanitize_for_log already handles this case on the guest-to-host health-reporting path (gateway/src/proxy/health_check.rs). The RPC log sites did not use it.

Fix

Add ra_rpc::log_text: bound_error_text followed by sanitize_for_log, which blanks control characters, Unicode line/paragraph separators and bidi controls. The three log sites in ra-rpc use it. Reply bodies are unchanged: they are JSON- or protobuf-encoded, so callers still get the full bounded message.

One visible effect: the multi-line {err:?} "Caused by:" block is now logged on one line.

Verification

  • New unit test logged_text_stays_on_one_line covers \n, \r, U+2028 and ESC, and checks that bounding still applies.
  • cargo test -p ra-rpc --all-features: all pass (22 + 4 + 10)
  • cargo clippy -p ra-rpc --all-features -- -D warnings --allow unused_variables, cargo fmt --all -- --check: clean
  • cargo check -p dstack-vmm -p dstack-gateway: ok

@kvinwang
kvinwang merged commit 7762d7a into next Sep 25, 2026
11 checks passed
@kvinwang
kvinwang deleted the fix/ra-rpc-log-lines branch September 25, 2026 00:52
kvinwang added a commit that referenced this pull request Sep 25, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
source-c pushed a commit to silicon-foundation/dstack that referenced this pull request Oct 4, 2026
The prpc routes record the percent-decoded method segment as a span
field, and the span prefixes every event of the request, so
POST /prpc/Info%0A<text> still started a log line with <text> after

Signed-off-by: Kevin Wang <wy721@qq.com>
Dstack-TEE#1401. Record it through log_text, like the dispatch and error lines.
kvinwang added a commit that referenced this pull request Nov 8, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 8, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 10, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 11, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 11, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 16, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
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