Skip to content

feat(start-wrt): note the ports a device asked to open without permission - #4658

Merged
dr-bonez merged 5 commits into
masterfrom
wrt/port-forward-request-note
Nov 11, 2026
Merged

dr-bonez merged 5 commits into
masterfrom
wrt/port-forward-request-note

Conversation

@Dominion5254

@Dominion5254 Dominion5254 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

A device without Allow automatic port forwarding that asks the router to open ports gets a silent refusal: PCP answers NOT_AUTHORIZED, UPnP returns fault 606, and nothing is logged. The device page now lists the ports such a device asked for in the last half hour, beside the toggle. It states this as a fact rather than a prompt to allow it, because port forwarding exposes the device to the internet and consoles and P2P clients ask reflexively.

  • start-core: the shared PCP/UPnP server gains a GatewayBackend::refused_mapping hook, called for a refused PCP MAP with a nonzero lifetime (with the PORT_SET size it asked for, which can exceed the 1,024 ports a grant is limited to) and for a refused UPnP AddPortMapping, AddAnyPortMapping or hostname add. Deletes and read-only queries are not requests to open anything. The default implementation ignores it, so StartTunnel is unchanged.
  • StartWRT records a request only after the PCP arrival-interface check the authorization gate already applies, so a forged source from another segment cannot put a note on a device there. A forger on the device's own segment can, the same residual exposure the permission itself accepts. Each device keeps its eight most recent port ranges, and each range drops off half an hour after the device last asked for it; granting the permission clears them. The neighbor lookup that resolves the source is cached for refused clients too, so a refusal adds no process spawn.
  • devices.list returns auto_port_forward_requests, and the device page shows them in an info note (all five locales). The DNS publishing note's bookkeeping (30-minute memory, 256-source cap) moves to a shared recent module that both notes use; the port note nests it, one entry per device holding one entry per range.
  • UPnP discovery still answers only permitted devices, so most UPnP clients without the permission never reach a port request. The note comes chiefly from PCP, which StartOS tries first. Refused IPv6 PCP requests are not recorded.

Changelog fragment minor-added-port-forward-request-note; one sentence added to the Devices page in the StartWRT book.

Verification

On 6e9b1da3e (before the rebase):

  • make start-wrt-test: startwrt-core 876 passed, uciedit 30 passed, 0 failed.
  • make start-core-test: 33 + 1335 + 3 passed, 0 failed.
  • npm run check:wrt, npm run check:i18n, npm run build:wrt, make start-wrt-rpc-bindings-check: all pass.
  • K1 bench router: refused PCP requests for a single port (8443), for a port range, and a PCP delete (not recorded); a refused UPnP AddPortMapping (fault 606) sent by hand; a forged request from another segment was not recorded, and one forged on the device's own segment was (the accepted residual above). Granting the permission cleared the note and a PCP request for 18080 then succeeded; revoking it closed the mapping. The UI showed both device-page notes, and the bench smoke test passed.
  • Not exercised: a StartOS server as the requesting client.

Rebased onto master 0b69dc3 (#4656) without conflicts; the master commits taken in change no start-wrt or start-core code. On 9dda079: make start-wrt-format-check and make start-core-format-check clean, and Prettier clean on every changed file it covers.

On e7f4f18 (review round 1: per-range expiry, requested PORT_SET size):

  • make start-wrt-test: startwrt-core 877 passed, uciedit 30 passed, 0 failed. The new requested_ranges_expire_independently_and_do_not_revive fails against the previous bookkeeping, which still listed a range asked for once half an hour earlier.
  • make start-core-test: 33 + 1335 + 3 passed, 0 failed. The 2,000-port case in a_refused_map_reports_the_ports_it_asked_for fails against the previous clamp, which reported 1,024 ports.
  • make start-wrt-format and make start-core-format: applied, no further changes.
  • K1 bench router: a refused PCP request for 2,000 ports from 5000 is listed as 5000-6999, beside 443 and 7000-7009; the DNS publishing note still records an unpermitted request. Once granted, the note clears and the same 2,000-port request succeeds with the 1,024-port grant (5000-6023). After revoking, a fresh refusal lists only its own port. Bench smoke test passed.

This and #4657 (DNS publishing proven source) both edit dns_inject.rs. They merge without conflicts in either order, and make start-wrt-test passes on a local merge of both heads (startwrt-core 879, uciedit 30, 0 failed).

Merged master 727b6c6 as 6e55556. The only conflict was i18n id 619 in all five dictionaries, which #4470 and #4611 took on master: master keeps 619–632 and this PR's note moves to 633. On 6e55556:

  • make start-wrt-test: startwrt-core 898 passed, uciedit 37 passed, 0 failed.
  • npm run check:wrt, npm run check:i18n, npm run check:i18n:wrt, and changelog.mjs check-version projects/start-wrt: all pass.

Then merged master 47d516a as 3df2172 without conflicts (released start-cli and start-tunnel changelog fragments only); Prettier clean on every changed file.

…sion

A device without "Allow automatic port forwarding" that asks the router
to open ports gets a silent refusal: PCP answers NOT_AUTHORIZED, UPnP
fault 606, and nothing is logged. The device page now lists the ports
such a device asked for in the last half hour, beside the toggle,
stated as a fact rather than a prompt to allow it: port forwarding
exposes the device to the internet, and consoles and P2P clients ask
reflexively.

The shared PCP/UPnP server gains a GatewayBackend::refused_mapping hook,
called for a refused PCP MAP with a nonzero lifetime (with its PORT_SET
size) and for a refused UPnP AddPortMapping, AddAnyPortMapping or
hostname add. Deletes and read-only queries are not requests to open
anything. The default ignores it, so StartTunnel is unchanged.

StartWRT records a request only after the PCP arrival-interface check
the authorization gate already applies: a forged source from another
segment cannot put a note on a device there. A forger on the device's
own segment can, the same residual exposure the permission itself
accepts. The neighbor lookup that resolves the source is cached for
refused clients too, so a refusal adds no process spawn. Each device
keeps its eight most recent port ranges; granting the permission clears
them.

The DNS publishing note's bookkeeping (30-minute memory, 256-source cap)
moves to a shared `recent` module both notes use.

UPnP discovery still answers only permitted devices, so most UPnP
clients without the permission never reach a port request; the note
comes chiefly from PCP, which StartOS tries first.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-white helix-white 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.

Two correctness fixes are needed before approval:

  1. [P2] Expire each requested range independently (projects/start-wrt/backend/ctrl/src/port_control.rs, note_request / requested_ports). Recent timestamps the whole device, while its value retains every range. If a device asks for 443 once and keeps asking for 8443, 443 remains in the list indefinitely. Even after the entire note expires, a later request revives the old ranges. This violates Device::auto_port_forward_requests' last-half-hour contract. The proposal reuses Recent for the eight ranges within each device, preserving the 256-device cap and DNS behavior, records the independent-expiry invariant beside the state, and adds deterministic expiry/revival coverage.

  2. [P2] Report the requested PORT_SET size, not the grant limit (shared-libs/crates/start-core/src/net/port_map/server/mod.rs, refused MAP branch). A request for 2,000 ports starting at 5000 is reported as 5000–6023 because its size is clamped to MAX_PORT_SET. The device actually asked for 5000–6999. The refusal hook promises what was requested; the successful-grant limit must not truncate that observation. The proposal preserves the original requested size and adds a case above the grant cap. Successful mapping limits are unchanged.

Reviewed PCP/UPnP refusal paths, source-interface gating, permission changes, DNS bookkeeping reuse, generated schema, device API and UI consumers. git merge-tree --write-tree origin/master HEAD succeeds for reviewed head 9dda07946fdcf05f80d9d427611a1b0db86f4c10. No builds or tests run during review; proposed coverage is unexecuted and belongs to author verification. CI was still running when inspected.

Proposed changes: 9dda079...proposal/4658

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

… docs

The proposal's field doc dropped the uppercase-MAC key that
forget_requests depends on, and recent.rs still described every entry
as a refused source now that it also holds port ranges.
@Dominion5254

Copy link
Copy Markdown
Member Author

Both adopted as proposed (8c3e624 fast-forwarded), with one follow-up commit (e7f4f18):

  • Per-range expiry: adopted. e7f4f18 runs rustfmt on note_request, restores the uppercase-MAC key in the requests field doc, and rewords the recent.rs docs, which still described every entry as a refused source. requested_ranges_expire_independently_and_do_not_revive fails on 9dda079's bookkeeping and passes now.
  • Requested PORT_SET size: adopted. The 2,000-port case fails on the old clamp (1,024) and passes now. On the K1 bench, a refused 2,000-port MAP is listed as 5000-6999, and the same request once permitted is still granted 5000-6023.
  • start-wrt-test 877 + 30, start-core-test 33 + 1335 + 3, and a merge with fix(start-wrt): count a DNS publishing request only from a proven source #4657 passes start-wrt-test (879 + 30).

@helix-white helix-white 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.

Re-review of e7f4f18. Both points from round 1 are resolved. 8c3e624 adopts the proposal as written: each port range now expires on its own, and the size reported for a large PORT_SET is no longer truncated. e7f4f18 only reformats note_request, puts back the uppercase-MAC key in the requests field doc (forget_requests relies on that key), and rewords the recent.rs docs so they no longer say every entry is a refused source. git merge-tree against origin/master merges cleanly.

Brief

When a device that lacks Allow automatic port forwarding asks the router to open ports, the router still refuses silently: PCP answers NOT_AUTHORIZED and UPnP returns fault 606. The device page now shows an info note under that toggle: "This device asked to open port(s) 3074, 27015-27030 to the internet. The router refused because automatic port forwarding is off." The note is in all five locales. It lists the ports or ranges asked for in the last half hour. The note states a fact. It does not offer an "allow" button.

Implementation diff: +193 / −36 lines in 17 files (excludes lockfiles, tests, docs, release notes, and changelog). These counts are hand-classified because several files mix tests and doc comments with code.

  • Shared PCP/UPnP server (start-core): GatewayBackend gets a new refused_mapping(peer, external_port, count) hook. Its default does nothing, so StartTunnel behaves the same. The server calls it in three cases: a refused PCP MAP with a nonzero lifetime and nonzero port, a refused UPnP AddPortMapping/AddAnyPortMapping, and a refused hostname add. Deletes and queries are not reported. For PCP, count is the PORT_SET size the device asked for, which can be larger than the 1,024-port limit on a grant. Most of the +130 lines in mod.rs are a test stub and tests. The PCP header parse moved above the authorization check with no change in behavior.
  • StartWRT: a request is recorded only if the neighbor-table entry exists, the MAC lacks the permission, and the PCP arrival interface matches that device's interface. This is the same check authorization already uses. As a result, a source forged from another segment cannot put a note on a device. A forger on the device's own segment can, which is the same exposure the permission itself already accepts. Neighbor lookups for refused clients now use the existing 10 s client cache, so a refusal does not start a new ip neigh process.
  • Limits: the router remembers at most 256 devices (stalest dropped first) and 8 ranges per device. Each range expires 30 minutes after the device last asked for it. All three numbers are chosen values, not measured ones. The 30 minutes and 256 devices match the existing DNS-publishing note. Memory is bounded at about 2,048 small entries. Granting the permission clears that device's ranges. devices.list also hides them while the permission is on. The state lives in memory only, so a router restart loses it.

Data model: devices.list's Device gets a new field, auto_port_forward_requests: string[], holding sorted strings such as "443" and "5000-5009". It is always present: empty for VPN peers and for permitted devices. API_CONTRACT.md, the generated Zod bindings, and the mock API are all updated. Nothing is persisted.

Approach: the DNS-publishing note's bookkeeping (a 30-minute memory capped at 256 sources) moves into a new generic module, recent::Recent<K, V, CAPACITY>. Both notes now use it. The port note nests one Recent per device inside the outer one, which gives the per-range expiry. This is the DNS duplication removed in this PR. Refusals in dns_inject.rs keeps its existing behavior.

Limitation: UPnP discovery still answers only permitted devices, so most UPnP clients without the permission never get as far as asking for a port. In practice the note comes from PCP, which StartOS tries first. Refused IPv6 PCP requests (pinholes) are not recorded.

Neighbors: #4657 also edits dns_inject.rs. The author reports that the two merge cleanly in either order and that make start-wrt-test passes on a merge of both heads (879 + 30).

Testing (author's evidence on e7f4f18): make start-wrt-test passed 877 + 30 tests and make start-core-test passed 33 + 1335 + 3. The new per-range expiry test and the 2,000-port PCP case both fail on the earlier code. Format checks are clean. On the K1 bench router, the author refused PCP requests for one port, a range, and 2,000 ports (listed as 5000-6999), plus a hand-sent UPnP request. A request forged from another segment was not recorded and one from the device's own segment was. Granting the permission cleared the note and let the same request get its 1,024-port grant (5000-6023). After revoking, a new refusal listed only its own port. Not exercised: a StartOS server as the requesting client, and a real UPnP client (discovery blocks it, as noted above). CI for e7f4f18 was still pending when this review was written.

I captured the screenshots below from the mock-API demo build (npm run build:wrt:demo) of e7f4f18. They are posted in a follow-up comment.

Helix-Harness: claude-code
Helix-Model: claude-opus-5-5

@helix-white

Copy link
Copy Markdown
Member

Screenshots for the approval brief above (mock-API demo build of e7f4f18):

Device page: refused port requests listed under the permission toggle

After granting the permission and saving: the note is gone

@helix-white

Copy link
Copy Markdown
Member

@Dominion5254 this PR now conflicts with master (69e0877). git merge-tree --write-tree origin/master e7f4f18d9 reports conflicts in all five StartWRT i18n dictionaries (de, en, es, fr, pl).

Cause: #4470 (69e0877, "let Edit change a Wi-Fi password") took dictionary IDs 619 and 620 for two Wi-Fi password strings. This PR also uses 619, for the port-request note.

Suggested resolution: merge origin/master into the branch, keep both of master's entries, and renumber this PR's string to 621 in all five dictionaries. Nothing else conflicts.

I'm this PR's cross-reviewer, so I haven't pushed to the branch. My approval was for e7f4f18. A merge commit that only renumbers this ID doesn't change anything I reviewed.

@helix-white

Copy link
Copy Markdown
Member

Correction to my earlier conflict note: master (367b22c) now uses dictionary IDs up to 632, so 621 is no longer free. The conflict is still only the five StartWRT i18n dictionaries. When you merge origin/master, give the port-request note the next unused ID, currently 633, in all five files.

…quest-note

# Conflicts:
#	projects/start-wrt/web/src/app/i18n/dictionaries/de.ts
#	projects/start-wrt/web/src/app/i18n/dictionaries/en.ts
#	projects/start-wrt/web/src/app/i18n/dictionaries/es.ts
#	projects/start-wrt/web/src/app/i18n/dictionaries/fr.ts
#	projects/start-wrt/web/src/app/i18n/dictionaries/pl.ts

@helix-white helix-white 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.

Re-review of 3df2172. The two new commits since my approval of e7f4f18 are merges of origin/master. Compared against its merge base, the PR's diff is identical to e7f4f18's, with one exception: the port-request note's dictionary ID changes from 619 to 633 in all five locales. Master had taken IDs 619 through 632. ID 633 appears once in each dictionary. All three Device { .. } constructions on the merged tree set auto_port_forward_requests. git merge-tree against current master (47d516a) merges cleanly.

Brief

When a device that lacks Allow automatic port forwarding asks the router to open ports, the router still refuses silently: PCP answers NOT_AUTHORIZED and UPnP returns fault 606. The device page now shows an info note under that toggle: "This device asked to open port(s) 3074, 27015-27030 to the internet. The router refused because automatic port forwarding is off." The note is in all five locales. It lists the ports or ranges asked for in the last half hour. The note states a fact. It does not offer an "allow" button.

Implementation diff: +193 / −36 lines in 17 files (excludes lockfiles, tests, docs, release notes, and changelog). These counts are hand-classified because several files mix tests and doc comments with code.

  • Shared PCP/UPnP server (start-core): GatewayBackend gets a new refused_mapping(peer, external_port, count) hook. Its default does nothing, so StartTunnel behaves the same. The server calls it in three cases: a refused PCP MAP with a nonzero lifetime and nonzero port, a refused UPnP AddPortMapping/AddAnyPortMapping, and a refused hostname add. Deletes and queries are not reported. For PCP, count is the PORT_SET size the device asked for, which can be larger than the 1,024-port limit on a grant. Most of the +130 lines in mod.rs are a test stub and tests. The PCP header parse moved above the authorization check with no change in behavior.
  • StartWRT: a request is recorded only if the neighbor-table entry exists, the MAC lacks the permission, and the PCP arrival interface matches that device's interface. This is the same check authorization already uses. As a result, a source forged from another segment cannot put a note on a device. A forger on the device's own segment can, which is the same exposure the permission itself already accepts. Neighbor lookups for refused clients now use the existing 10 s client cache, so a refusal does not start a new ip neigh process.
  • Limits: the router remembers at most 256 devices (stalest dropped first) and 8 ranges per device. Each range expires 30 minutes after the device last asked for it. All three numbers are chosen values, not measured ones. The 30 minutes and 256 devices match the existing DNS-publishing note. Memory is bounded at about 2,048 small entries. Granting the permission clears that device's ranges. devices.list also hides them while the permission is on. The state lives in memory only, so a router restart loses it.

Data model: devices.list's Device gets a new field, auto_port_forward_requests: string[], holding sorted strings such as "443" and "5000-5009". It is always present: empty for VPN peers and for permitted devices. API_CONTRACT.md, the generated Zod bindings, and the mock API are all updated. Nothing is persisted.

Approach: the DNS-publishing note's bookkeeping (a 30-minute memory capped at 256 sources) moves into a new generic module, recent::Recent<K, V, CAPACITY>. Both notes now use it. The port note nests one Recent per device inside the outer one, which gives the per-range expiry. This is the DNS duplication removed in this PR. Refusals in dns_inject.rs keeps its existing behavior.

Limitation: UPnP discovery still answers only permitted devices, so most UPnP clients without the permission never get as far as asking for a port. In practice the note comes from PCP, which StartOS tries first. Refused IPv6 PCP requests (pinholes) are not recorded.

Neighbors: #4657 also edits dns_inject.rs. The author reports that the two merge cleanly in either order and that make start-wrt-test passes on a merge of both heads (879 + 30).

Testing (author's evidence on e7f4f18): make start-wrt-test passed 877 + 30 tests and make start-core-test passed 33 + 1335 + 3. The new per-range expiry test and the 2,000-port PCP case both fail on the earlier code. Format checks are clean. On the K1 bench router, the author refused PCP requests for one port, a range, and 2,000 ports (listed as 5000-6999), plus a hand-sent UPnP request. A request forged from another segment was not recorded and one from the device's own segment was. Granting the permission cleared the note and let the same request get its 1,024-port grant (5000-6023). After revoking, a new refusal listed only its own port. Not exercised: a StartOS server as the requesting client, and a real UPnP client (discovery blocks it, as noted above). CI for 3df2172 was still pending when this review was written.

The screenshots from the e7f4f18 mock-API demo build still show the final UI, since the merges change only the dictionary ID: #4658 (comment)

Helix-Harness: claude-code
Helix-Model: claude-opus-5-5

@dr-bonez
dr-bonez merged commit a411d63 into master Nov 11, 2026
43 checks passed
@dr-bonez
dr-bonez deleted the wrt/port-forward-request-note branch November 11, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants