Repository navigation
fix(sessions): validate egress DNS hosts and flag host-bit CIDRs - #1926
Conversation
Reject an allow_dns_hosts entry that is not a valid DNS hostname at launch, naming the offending string, instead of storing it verbatim as an allow rule that can never match the DNS gate. The check runs on both own-address and host-address boxes. Keep host-bit CIDRs valid, but print a one-line notice at activation naming the normalized network so the user knows how the range is read. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/review |
|
Approved: no findings at Nothing to do. Clobber: none: |
|
[inbox-patch:clobber] This PR would revert recently merged workSimulating this merge shows it undoing commits that landed on the base branch within the last 3 day(s):
Before merging, restore the reverted region to its state on the base branch. The rest of this PR is unaffected. If a listed commit is one this PR intends to supersede, say so and merge — this check reports, it does not block. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Warning Review limit reached
This review includes 4 billable files and costs up to $1.00. Or wait 23 minutes for your next included review. View limit detailsLimit details: You’ve used all 2 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (4)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughNew session policies validate configured egress DNS hostnames. Session activation reports declared subnet entries when IPv4 normalization masks host bits. ChangesEgress Policy Handling
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to New sessions validate DNS hosts, while IPv4 subnet notices report masked values. No actionable merge risk remains after normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
A rabbit checks each hostname string, Comment |
The egress rules compile only IPv4 subnets, so an IPv6 entry is never read as the masked network the notice named. normalized_cidr now returns None for IPv6 prefixes.
|
/review |
validate_policy re-runs on every launch, so a stored session whose allow_dns_hosts predates the check would stop attaching after an upgrade. The hostname check moves to validate_new_policy, which only the create path calls. The length limit now applies after the trailing dot is stripped, and the error says wildcards and raw IDNs are not accepted.
|
/review |
The acceptance test called validate_policy, which no longer consults is_valid_dns_host, so it never exercised the new check's accept path.
|
/review |
The empty-egress-value test assumed a hostname has no syntax to check, so an empty entry stood as typed. Hostnames are now validated when a session is created, so the empty value is refused with a typed error naming the entry, the same as the CIDR dimensions. It still never becomes an empty (deny-all) list.
|
/review |
RFC 1035 labels cannot begin or end with a hyphen, so no query name can match such an entry; it would be stored as an allow rule that admits nothing.
|
/review |
Routing-Key: inbox-route/I_kwDOSUhdos8AAAABU21Ymg
Summary
min session activateaccepted egress values that can never match anything:--allow-dns-hosts 'not a host'was stored verbatim as an allow rule that admits no name.--deny-subnets 10.0.0.1/8(host bits set) was accepted without telling the user how the range is read.Changes
crates/sessions/src/lib.rsPolicyError::InvalidDnsHost { host }.EgressPolicy::first_invalid_dns_hostand wire it intovalidate_policyso anallow_dns_hostsentry that is not a valid DNS hostname (empty, whitespace, label >63 bytes or empty, total >253, characters outside[A-Za-z0-9-_.]) is rejected at launch on both own-address and host-address paths. One trailing dot is tolerated, matching the DNS gate's normalization.normalized_cidrhelper next tois_valid_cidrthat returns the masked prefix (10.0.0.1/8→10.0.0.0/8) orNonewhen already normalized.crates/minimal/src/cmd/session.rs--deny-subnets 10.0.0.1/8 is read as 10.0.0.0/8.Verification
cargo test -p sessions --locked: 550 passed, 0 failed (includes new testsinvalid_egress_dns_host_is_rejected,valid_egress_dns_hosts_are_accepted,normalized_cidr_masks_host_bits).cargo build -p minimal --locked: succeeds.cargo fmt --all --check: clean.Note:
cargo clippy --workspace --locked -- -D warningsfails on a pre-existing lint incrates/args/src/lib.rs(clippy::needless_borrows_for_generic_args, only present in the sandbox's clippy 1.99.0, not the pinned 1.97.0); it is unrelated to this change.Summary by CodeRabbit