Visitar URL original
fix(lib): validate localhost port ranges for zero end and inverted ranges by Ayush7614 · Pull Request #1860 · nolabs-ai/nono · GitHub
Skip to content

fix(lib): validate localhost port ranges for zero end and inverted ranges - #1860

Merged
SequeI merged 1 commit into
nolabs-ai:mainfrom
Ayush7614:fix/capability-port-range-validation-1856
Sep 11, 2026
Merged

SequeI merged 1 commit into
nolabs-ai:mainfrom
Ayush7614:fix/capability-port-range-validation-1856

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

Linked Issue

Closes #1856

Summary

CapabilitySet::allow_localhost_port_range(start, end) validated only start==0. This allowed:

  • allow_localhost_port_range(5000, 4000) — inverted, expands to zero Landlock rules on Linux (for port in start..=end empty) and counts a phantom port on macOS via saturating_sub.
  • allow_localhost_port_range(100, 0) — end==0 has no defined meaning (macOS wildcard is allow_localhost_port(0)).

Fix adds validation for end==0 and end<start in both builder (crates/nono/src/capability.rs:1204) and mutable (crates/nono/src/capability.rs:1401) paths.

Agent Disclosure

Generated by AI assistant (Muse Spark via OpenCode). Compared capability.rs:1204, sandbox/linux.rs:912, and sandbox/macos.rs:561 to identify silent misconfiguration. Verified no duplicate open issue. No NEP required — validation tightening only, no new capability type, no breaking change for valid inputs.

Test Plan

  • cargo test -p nono -- test_localhost_port_range --nocapture — 7 passed (including 4 new: rejects_zero_end, rejects_inverted, accepts_single_port_range, accepts_valid_ranges)
  • cargo test -p nono — 822 passed, 0 failed
  • cargo clippy -p nono -- -D warnings -D clippy::unwrap_used — clean
  • cargo fmt --check — clean

Checklist

…nges

allow_localhost_port_range only checked start==0, so
allow_localhost_port_range(5000, 4000) silently succeeded but
expanded to zero Landlock rules on Linux and counted a phantom
port on macOS. Similarly, end==0 was accepted though port 0 has
no meaning in a range (macOS wildcard is via allow_localhost_port(0)).

Add validation for end==0 and end<start in both the builder
(allow_localhost_port_range) and mutable (add_localhost_port_range)
paths. Add tests for inverted, zero-end, single-port, and valid
multi-range cases.

Closes nolabs-ai#1856

Signed-off-by: Ayush7614 <ayushknj3@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

PR Review Summary

Size

Metric Value
Lines added +78
Lines removed -3
Total changed 81
Classification Medium (50–300 lines)

Affected crates

  • crates/nono (core library) — careful review required. This is the security-critical sandbox primitive. A bug here bypasses OS-level isolation for every downstream user.

Blast radius — Contained

This PR touches: source code


Updated automatically on each push to this PR.

@nogent-nolabs-ai nogent-nolabs-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nogent code review

No issues found; the port range validation is correct and well-tested.

Findings: none flagged in scope.

Automated code + security review. CI already covers clippy, rustfmt, tests, cargo-audit and commit-lint.

@SequeI SequeI left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@SequeI
SequeI merged commit 00ebd08 into nolabs-ai:main Sep 11, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working nono size/medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(lib): allow_localhost_port_range accepts inverted and zero-end ranges, silently misconfigures sandbox

2 participants