Public: anyone can read this; the crew can change it.

A device address written as IPv4-mapped IPv6 is refused like the IPv4 address it is #15050

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

validateDeviceUrl (src/core/devices.ts) now reads the host's bytes with addressBytes from src/kernel/cidr.ts before deciding anything. If the host is an IPv4-mapped IPv6 address, the IPv4 address it carries is what gets checked: never-allowed, loopback-only-behind-the-switch, private-network-or-refused.

Notes

shipped production is serving it deploy 15342fb

opened this

validateDeviceUrl (src/core/devices.ts) now reads the host's bytes with addressBytes from src/kernel/cidr.ts before deciding anything. If the host is an IPv4-mapped IPv6 address, the IPv4 address it carries is what gets checked: never-allowed, loopback-only-behind-the-switch, private-network-or-refused.

Before this, [::ffff:169.254.169.254], [::ffff:0.0.0.0] and [::ffff:127.0.0.1] could be saved as printers. The URL parser rewrites them as [::ffff:a9fe:a9fe], [::ffff:0:0] and [::ffff:7f00:1], so the checks that compare strings (169.254., 0.0.0.0, 127.) never matched. isPrivateHost then took them in as private-network addresses. The loopback one also got past the FORGE_DEVICES_ALLOW_LOOPBACK switch.

I used addressBytes rather than isPublicAddress from src/apps/egress.ts. isPublicAddress only says public or not, and it can't tell loopback apart from metadata or the unspecified address. Devices need those three kept apart.

Tests in test/devices.test.ts:

  • Refused forms: each address in dotted, short hex and full hex spelling, checked with the loopback switch off. All are refused.
  • Switch on: mapped loopback is let in, and mapped metadata and the unspecified address are still refused.
  • Still accepted: a mapped private printer, [::ffff:192.168.1.161].

Both refusal tests fail with the old src/core/devices.ts. devices, keys-devices and tui-devices pass, the gate changed nothing, and tsc --noEmit is clean.

Not done here: IPv6 link-local fe80::/10 is still accepted as a private-network address, as it was before. The issue doesn't ask for it to change.

To try it: bun test test/devices.test.ts, or declare ipp://[::ffff:169.254.169.254]/ipp/print on /settings/devices and see it refused as a public address.

🤖 Generated with Claude Code

Closes #15036

commented

validateDeviceUrl (src/core/devices.ts) now reads the host's bytes with addressBytes from src/kernel/cidr.ts before deciding anything. If the host is an IPv4-mapped IPv6 address, the IPv4 address it carries is what gets checked: never-allowed, loopback-only-behind-the-switch, private-network-or-refused.

Before this, [::ffff:169.254.169.254], [::ffff:0.0.0.0] and [::ffff:127.0.0.1] could be saved as printers. The URL parser rewrites them as [::ffff:a9fe:a9fe], [::ffff:0:0] and [::ffff:7f00:1], so the checks that compare strings (169.254., 0.0.0.0, 127.) never matched. isPrivateHost then took them in as private-network addresses. The loopback one also got past the FORGE_DEVICES_ALLOW_LOOPBACK switch.

I used addressBytes rather than isPublicAddress from src/apps/egress.ts. isPublicAddress only says public or not, and it can't tell loopback apart from metadata or the unspecified address. Devices need those three kept apart.

Tests in test/devices.test.ts:

  • Refused forms: each address in dotted, short hex and full hex spelling, checked with the loopback switch off. All are refused.
  • Switch on: mapped loopback is let in, and mapped metadata and the unspecified address are still refused.
  • Still accepted: a mapped private printer, [::ffff:192.168.1.161].

Both refusal tests fail with the old src/core/devices.ts. devices, keys-devices and tui-devices pass, the gate changed nothing, and tsc --noEmit is clean.

Not done here: IPv6 link-local fe80::/10 is still accepted as a private-network address, as it was before. The issue doesn't ask for it to change.

To try it: bun test test/devices.test.ts, or declare ipp://[::ffff:169.254.169.254]/ipp/print on /settings/devices and see it refused as a public address.

🤖 Generated with Claude Code

Approved

Approved. The device URL is now judged by parsed bytes: addressBytes unwraps ::ffff:a.b.c.d to the IPv4 it carries, so metadata, unspecified and loopback meet the same refusals (loopback behind the switch). Small, no new dependency, no dead code, and the tests cover dotted, short-hex and full-hex forms, the loopback switch and a still-accepted mapped private printer. No UI change here, so nothing for the phone/keyboard/JS-off pass.

Two things I would do next: (1) judge the other IPv4-carrying IPv6 forms (NAT64 64:ff9b::/96, IPv4-compatible ::a.b.c.d) and fe80::/10 link-local, which is still accepted as private; (2) share one literal-judging helper with the egress check so the two cannot drift again.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs