fix(pairing): reject reserved clientId 'root' at all token writers

'root' is the sentinel checkScope/checkDomain/checkRate and the server
command gate use for the omnipotent caller, so a scoped token carrying it
bypasses every enforcement path. Add ReservedClientIdError + a shared
assertValidClientId; createToken/createSetupKey throw, restoreRegistry
skips-and-logs (a corrupt state file must not brick boot). /pair and /token
surface it as a named 400, and the CLI fast-fails --client root.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-08-21 15:15:11 -07:00
committed by Garry Tan
co-authored by Claude Fable 5
parent 51932eceef
commit 783504d7ea
5 changed files with 110 additions and 8 deletions
+8
View File
@@ -1225,6 +1225,14 @@ async function tunnelAgents(): Promise<number> {
* opposite of the user's intent. And `control` never rides in via --restrict:
* browser-wide destructive ops stay behind the explicit --control flag. */
function validatePairAgentFlags(args: string[]): void {
// `root` is the sentinel that bypasses all scope/domain/rate/tab enforcement;
// naming an agent that way would silently un-sandbox it. Reject client-side
// before hitting the daemon (the server rejects it too).
const client = parseFlag(args, '--client');
if (client !== undefined && client.trim().toLowerCase() === 'root') {
console.error("[browse] --client 'root' is reserved — it would bypass all scope enforcement. Choose another name.");
process.exit(1);
}
// hasFlag/parseFlag are exact-token matches, so `--restrict=read` would
// sail past every check below and silently grant FULL access.
if (args.some(a => a.startsWith('--restrict='))) {