8000 fix(minvmd): relay a guest control request only as rebuilt from its strict read by minimal-backporter[bot] · Pull Request #3561 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(minvmd): relay a guest control request only as rebuilt from its strict read - #3561

Merged
norrietaylor merged 2 commits into
release/0.7.xfrom
backport/3151-to-release/0.7.x
Nov 18, 2026
Merged

norrietaylor merged 2 commits into
release/0.7.xfrom
backport/3151-to-release/0.7.x

Conversation

@minimal-backporter
Copy link
Copy Markdown

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.

< 8000 input type="hidden" name="pull_request_repository_id" value="1037556932" data-targets="batch-deferred-content.inputs" autocomplete="off" />
…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)
@coderabbitai
coderabbitai Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c4542cce-49f3-48f0-af3c-bde4729fa242

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@minimal-foundry
minimal-foundry Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
Contributor

Reviewed: no findings; approval withheld, 2 threads unresolved at 0f20c7e0e02d.

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.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — advisory review

Verdict COMMENT — 3 findings, 2 inline.

Panel: 2 of 3 personas ran (correctness, security); did not complete: supply-chain.

Comment thread crates/minvmd/src/net/egress_gate.rs Outdated
/// 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 boxes dependency

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0f20c7e0e02d: box_zone_name now uses sessions::core::zone_answer::ZONE_APEX, the module path on release/0.7.x.

Comment on lines +4260 to +4263
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()?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@norrietaylor
Copy link
Copy Markdown
Member

/revise

  • boxes crate: crates/minvmd/src/net/egress_gate.rs:4154 uses boxes::core::zone_answer::ZONE_APEX. That crate doesn't exist on the line.
  • serde_json: the rebuilt-body check at lines 4260–4308 uses it, but minvmd on the line only depends on serde_json_lenient.

@minimal-foundry
minimal-foundry Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
Contributor

Round 1 of 10 is on this pull request.

branch backport/3151-to-release/0.7.x

round outcome job
1 pushed 419cf645

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.
@minimal-foundry
Copy link
Copy Markdown
Contributor

Round 1 of 10 on a /revise note, pushed as 0f20c7e0e02d.

No test: line was run.

Review threads the coder judged:

  • 👍 valid — crates/minvmd/src/net/egress_gate.rs: box_zone_name now uses sessions::core::zone_answer::ZONE_APEX, the module path on release/0.7.x.
  • 👍 valid — crates/minvmd/src/net/egress_gate.rs:4263: Added serde_json = "1" to the workspace and minvmd, so the strict parse stays strict. The lock already had serde_json 1.0.151.

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 cargo test -p minvmd run shows 4 failures in files this branch does not change (bep_attach, net::answerer, sock). They install a global trace subscriber and need one process per test. Under nextest, all 581 tests pass. I did not run just ci, the workspace-wide checks, or native-daemon-e2e.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@norrietaylor
norrietaylor enabled auto-merge (squash) November 18, 2026 21:16
@norrietaylor
norrietaylor merged commit c4d5682 into release/0.7.x Nov 18, 2026
33 checks passed
@norrietaylor
norrietaylor deleted the backport/3151-to-release/0.7.x branch November 18, 2026 21:49
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.

2 participants

0