Repository navigation
fix(minvmd): relay a guest control request only as rebuilt from its strict read - #3561
Conversation
…trict read (#3151) * fix(minvmd): relay a guest control request only as rebuilt from its strict read The egress gate decided a guest's expose, unexpose or zone-add from a lenient parse (unknown keys ignored, repeated keys accepted, comments and trailing commas allowed) and then wrote the guest's own head and body to gvproxy. gvproxy decodes with Go's encoding/json, which matches keys without regard to case and lets a repeated key win, so a body could carry `local`/`remote` that pass the row decision beside a `LOCAL`, `REMOTE` or second `local` that gvproxy binds or dials instead (inbox#1180). The body is now read strictly before anything decides on it: the verb's own fields, once each, spelled exactly, in strict JSON, with the JSON value equal to the rebuilt body's. A body with no strict read is refused under egress-malformed-publish, answered 400, and never relayed. An admitted request is written as the daemon's own head over the rebuilt body, never the guest's bytes, so gvproxy decodes what the gate decided. The daemon's own client already writes that spelling, so honest requests relay byte for byte. The range probe's own strict check (#2749) is folded into this one. The zone a zone-add names is now required and decided as well: gvproxy files the records under it and answers every query ending in it, so a zone other than the box zone (`min.internal.`, the only one the daemon sends) is refused. Tests: every key of every shape with case-variant, escaped and repeated spellings, unknown keys, missing or mistyped fields, comments, trailing commas, concatenated bodies and every proper prefix are refused; a zone record's regexp and a zone's default address are refused; a zone-add in any zone but the box zone relays nothing; the daemon's spelling is its own canonical form; refused requests relay nothing end to end; an admitted request reaches the switch as its canonical request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: rustfmt the egress gate tests The lab prepush (job 02012) failed only on fmt: three rustfmt hunks. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * fix(minvmd): name a refused control value bounded and escaped A refused request's port or name is the guest's: a field of a body the gate would not summarize, such as a zone-add's zone name, up to the control body's 8 KiB bound. The refusal line wrote it with Display, so a newline or another control character could break the line or forge one, and a long value could flood the log. The line now names printable ASCII within 120 bytes as it is, which is every value the daemon's own client sends, and anything else escaped with Debug and cut to that bound on a char boundary, marked with the value's full length. Tests: a unit test through summarize_dns_add with a zone name carrying a newline, other control characters, a 7001-byte name and cuts inside multi-byte characters; and a gate test that the refusal line for the newline and the long name carries neither raw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: rustfmt the bounded refusal-value tests The lab prepush (job 05234) failed only on fmt; this is its fmt.patch applied whole. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * fix(minvmd): a refused value carrying =, a quote or a backslash is logged as one quoted token loggable_what wrote any printable value as it was, so a guest could put `x rule_matched="egress-control-upgrade"` in a zone name and have the refusal line show that forged field before the real one. A value with `=`, `"` or `\` now takes the escaped path and is written as one quoted token with its own quotes escaped; a cut escaped value keeps its closing quote before the length marker. The daemon's own values (ports, addresses, names) have none of those bytes and still read as before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * fix(minvmd): a cut refused value ends between escape sequences, so its closing quote is its own The escaped form was cut at a byte offset, which could fall right after a backslash; the closing quote appended after it then read as an escaped quote, and the value is the guest's to shape. The cut now stops before the bound between whole `escape_debug` sequences, so the token always ends at its own quote before the length marker. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * test(minvmd): the cut-name assertion reads the ASCII case it was written for The quotes case reused the ASCII case's binding, so the assertion that the cut keeps the name's head read the quoted value and failed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 6a0ed1b)
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
Reviewed: no findings; approval withheld, 2 threads unresolved at APPROVE withheld: 2 unresolved threads — minimal-foundry[bot] crates/minvmd/src/net/egress_gate.rs, minimal-foundry[bot] crates/minvmd/src/net/egress_gate.rs:4263. Resolving the last thread releases the approval on this head. Resolve the open threads. Resolving the last one releases the approval on this head; no new review is required. Clobber: none seen. |
| /// daemon's own client writes it (`dns_add_body`, | ||
| /// `crates/minimald/src/net/policy.rs`). | ||
| fn box_zone_name() -> String { | ||
| format!("{}.", boxes::core::zone_answer::ZONE_APEX) |
There was a problem hiding this comment.
MEDIUM · correctness · confidence 0.90 · in box_zone_name
boxes::core::zone_answer::ZONE_APEX names a crate that does not exist on this branch. Here the module is sessions::core::zone_answer (minvmd already imports it in box_registry.rs). This line does not compile. The cherry-pick came from a branch with a renamed crate. Use sessions::core::zone_answer::ZONE_APEX.
What the reviewer checked
egress_gate.rs:4154 format!("{}.", boxes::core::zone_answer::ZONE_APEX); crates/minvmd/Cargo.toml:44 sessions.workspace = true; no
boxesdependency
Hand this to an agent
Act on a code-review finding.
File: crates/minvmd/src/net/egress_gate.rs
Lines: 4154-4154
Category: correctness
Severity: medium (reviewer confidence 0.90)
Finding:
`boxes::core::zone_answer::ZONE_APEX` names a crate that does not exist on this branch. Here the module is `sessions::core::zone_answer` (minvmd already imports it in `box_registry.rs`). This line does not compile. The cherry-pick came from a branch with a renamed crate. Use `sessions::core::zone_answer::ZONE_APEX`.
First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.
👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.
There was a problem hiding this comment.
Addressed in 0f20c7e0e02d: box_zone_name now uses sessions::core::zone_answer::ZONE_APEX, the module path on release/0.7.x.
| let parsed: T = serde_json::from_slice(body).ok()?; | ||
| let canonical = serde_json::to_vec(&parsed).ok()?; | ||
| let sent: serde_json::Value = serde_json::from_slice(body).ok()?; | ||
| let rebuilt: serde_json::Value = serde_json::from_slice(&canonical).ok()?; |
There was a problem hiding this comment.
MEDIUM · correctness · confidence 0.85 · in canonical_control_body
The new code calls serde_json here, in canonical_probe_request and in tests. crates/minvmd/Cargo.toml and the workspace Cargo.toml declare only serde_json_lenient. The crate does not compile. Add serde_json to the workspace and to minvmd, or use serde_json_lenient. Note that canonical_control_body needs strict parsing, so serde_json_lenient is not a safe swap there.
What the reviewer checked
egress_gate.rs:4260 let parsed: T = serde_json::from_slice(body).ok()?; Cargo.toml:203 only serde_json_lenient
Hand this to an agent
Act on a code-review finding.
File: crates/minvmd/src/net/egress_gate.rs
Lines: 4260-4263
Category: correctness
Severity: medium (reviewer confidence 0.85)
Finding:
The new code calls `serde_json` here, in `canonical_probe_request` and in tests. `crates/minvmd/Cargo.toml` and the workspace `Cargo.toml` declare only `serde_json_lenient`. The crate does not compile. Add `serde_json` to the workspace and to minvmd, or use `serde_json_lenient`. Note that `canonical_control_body` needs strict parsing, so `serde_json_lenient` is not a safe swap there.
First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.
👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.
There was a problem hiding this comment.
Addressed in 0f20c7e0e02d: Added serde_json = "1" to the workspace and minvmd, so the strict parse stays strict. The lock already had serde_json 1.0.151.
|
/revise
|
|
Round 1 of 10 is on this pull request. branch
Updated 2026-11-18T21:04:59.337Z. |
The cherry-pick named boxes::core::zone_answer, which is sessions::core::zone_answer on this line, and used serde_json, which minvmd did not declare. Add serde_json (already in the lock) to the workspace and to minvmd.
|
Round 1 of 10 on a /revise note, pushed as No Review threads the coder judged:
On release/0.7.x, minvmd now compiles with the backported strict read of guest control bodies, and its full test suite passes, the egress gate tests included. Notes from the agent: Fixed the two compile errors from the cherry-pick. boxes::core::zone_answer::ZONE_APEX is now sessions::core::zone_answer::ZONE_APEX. serde_json = "1" is added to the workspace dependencies and to minvmd. serde_json 1.0.151 was already in Cargo.lock as a transitive dependency, so the lockfile diff is one line: serde_json in the minvmd dependency list. A plain |
There was a problem hiding this comment.
minimal-review — approval withheld
Verdict COMMENT — APPROVE withheld: 2 unresolved threads — minimal-foundry[bot] crates/minvmd/src/net/egress_gate.rs, minimal-foundry[bot] crates/minvmd/src/net/egress_gate.rs:4263. No findings.
Panel: 3 of 3 personas ran (correctness, security, supply-chain).
Backport of #3151 to
release/0.7.x.Squash-merge this PR and keep the PR title as the subject. The cherry-picked commit keeps the source subject.