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

The operator guard treats a trailing-dot hostname as the host it names #14976

Merged opened this

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

Merged

The operator guard now treats git.example. as git.example. Before this change, an origin connected as https://git.example.

Notes

shipped production is serving it deploy 6b7374e

opened this

The operator guard now treats git.example. as git.example. Before this change, an origin connected as https://git.example. passed every check that the plain hostname's rules set up (#14954, from the deepsec report in #14771). Admin accounts and accounts that can push to protected repositories got through, and denied() said a protected repository wasn't protected.

The fix, in src/origins/operator.ts: a new normalHost() lowercases a hostname and removes one trailing dot. hostnameOf() and operatorHosts() both go through it. guarded, denied, checkCredential and writesPaused (which goes through guarded) all compare hostnames using those two functions, so they now see one spelling of each host. Push rules written as host.:owner/name get normalized the same way, because splitHost uses hostnameOf. The origin broker compares hosts with these same two functions, so it stays consistent too.

The test: test/origin-guard-trailing-dot.test.ts. I ran it before the fix to confirm the bypass: all 6 cases failed, and both the admin case and the push case came back passed. After the fix they all pass. It covers:

  • the hostname normalizing itself
  • the operator's variables written with a trailing dot
  • guarded and denied on a dotted origin
  • checkCredential refusing an administrator (admin_account)
  • checkCredential refusing an account that can push, under both an exact rule and a wildcard rule (can_push)

Not done: operatorClientId in src/origins/oauth.ts still compares hostnames on its own. With a dotted URL it doesn't find the operator's registered client id, so the person is asked to paste one. That makes sign-in less convenient but doesn't let anything past the guard, and the issue limits the change to operator.ts, so I left it alone.

Checks: scripts/gate.ts --fix and tsc --noEmit are clean. scripts/fast.ts said the change reaches 2382 test files, too many to run here, so I ran the 7 suites that cover the guard, the broker and operator sign-in: 66 pass, 0 fail. The forge's full check runs on this push.

To try it: bun test test/origin-guard-trailing-dot.test.ts. With the change to src/origins/operator.ts reverted, all 6 cases fail.

🤖 Generated with Claude Code

Closes #14954

commented

The operator guard now treats git.example. as git.example. Before this change, an origin connected as https://git.example. passed every check that the plain hostname's rules set up (#14954, from the deepsec report in #14771). Admin accounts and accounts that can push to protected repositories got through, and denied() said a protected repository wasn't protected.

The fix, in src/origins/operator.ts: a new normalHost() lowercases a hostname and removes one trailing dot. hostnameOf() and operatorHosts() both go through it. guarded, denied, checkCredential and writesPaused (which goes through guarded) all compare hostnames using those two functions, so they now see one spelling of each host. Push rules written as host.:owner/name get normalized the same way, because splitHost uses hostnameOf. The origin broker compares hosts with these same two functions, so it stays consistent too.

The test: test/origin-guard-trailing-dot.test.ts. I ran it before the fix to confirm the bypass: all 6 cases failed, and both the admin case and the push case came back passed. After the fix they all pass. It covers:

  • the hostname normalizing itself
  • the operator's variables written with a trailing dot
  • guarded and denied on a dotted origin
  • checkCredential refusing an administrator (admin_account)
  • checkCredential refusing an account that can push, under both an exact rule and a wildcard rule (can_push)

Not done: operatorClientId in src/origins/oauth.ts still compares hostnames on its own. With a dotted URL it doesn't find the operator's registered client id, so the person is asked to paste one. That makes sign-in less convenient but doesn't let anything past the guard, and the issue limits the change to operator.ts, so I left it alone.

Checks: scripts/gate.ts --fix and tsc --noEmit are clean. scripts/fast.ts said the change reaches 2382 test files, too many to run here, so I ran the 7 suites that cover the guard, the broker and operator sign-in: 66 pass, 0 fail. The forge's full check runs on this push.

To try it: bun test test/origin-guard-trailing-dot.test.ts. With the change to src/origins/operator.ts reverted, all 6 cases fail.

🤖 Generated with Claude Code

Approved

Approved. normalHost() lowercases and strips one trailing dot; hostnameOf() and operatorHosts() both use it, so guarded, denied, checkCredential and writesPaused see one spelling. Tests cover the admin and can_push bypasses and fail without the fix. No new dependency, no web surface, nothing dead. Next: (1) add a direct writesPaused test with a dotted host, since box 1 names it and it is currently covered only through guarded; (2) normalize the remaining hand-rolled host compares (oauth.ts:863 operatorClientId, origin_fetch.ts:43) so sign-in works with a dotted URL.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs