Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(security): close attached-flag writes through the unattended gh/glab gate
Adam Eivy1d9925a53954
diff --git a/server/lib/commandSecurity.js b/server/lib/commandSecurity.jsindex ae68bc66f5..74165330f2 100644--- a/server/lib/commandSecurity.js+++ b/server/lib/commandSecurity.js@@ -210,6 +210,23 @@ const GH_METHOD_FLAGS = new Set(['-X', '--method']);// gh/glab switch `api` to POST implicitly when a field flag is present, so a// method check alone is not enough.const GH_FIELD_FLAGS = new Set(['-f', '-F', '--field', '--raw-field', '--input']);+// Both CLIs parse flags with pflag, which also accepts a shorthand with its+// value attached (`-XPOST`, `-Fbody=@file`) and clustered after booleans+// (`-iXPOST`). Scanning a single-dash cluster: `-X` with anything but GET or+// a field shorthand rejects; another value-taking shorthand ends the scan+// (the rest is its value); an unknown letter fails closed.+const GH_API_VALUE_SHORTHANDS = new Set(['H', 'p', 'q', 't']);+const GH_API_BOOLEAN_SHORTHANDS = new Set(['i']);+const ghApiClusterWrites = (arg) => {+ const cluster = arg.slice(1);+ for (let i = 0; i < cluster.length; i += 1) {+ const flag = cluster[i];+ if (GH_API_BOOLEAN_SHORTHANDS.has(flag)) continue;+ if (flag === 'X') return cluster.slice(i + 1).replace(/^=/, '').toUpperCase() !== 'GET';+ return !GH_API_VALUE_SHORTHANDS.has(flag);+ }+ return false;+};const deny = (error) => ({ valid: false, error });@@ -274,9 +291,12 @@ function validateUnattendedGhLike(base, args) {if (method !== null && method.toUpperCase() !== 'GET') {return deny(`'${base} api' is limited to GET on the unattended lane — '${method}' is an authenticated write.`);}- if (GH_FIELD_FLAGS.has(arg) || arg.startsWith('--field=') || arg.startsWith('--raw-field=')) {+ if (GH_FIELD_FLAGS.has(arg) || /^--(?:field|raw-field|input)=/.test(arg)) {return deny(`'${base} api ${arg}' is not allowed on the unattended lane — a field flag makes the request a POST.`);}+ if (method === null && /^-[^-]/.test(arg) && arg.length > 2 && ghApiClusterWrites(arg)) {+ return deny(`'${base} api ${arg}' is not allowed on the unattended lane — a method or field shorthand with an attached value can make the request a write.`);+ }}return { valid: true };}diff --git a/server/lib/commandSecurity.test.js b/server/lib/commandSecurity.test.jsindex dc75d0dc7b..5672857a1d 100644--- a/server/lib/commandSecurity.test.js+++ b/server/lib/commandSecurity.test.js@@ -529,6 +529,14 @@ describe('commandSecurity', () => {['glab api -X POST is an authenticated write', 'glab api -X POST /projects'],['a bare gh has no read-only verb at all', 'gh'],['a methodless -X is malformed and fails closed', 'gh api -X'],+ // pflag also takes a shorthand's value attached or after clustered booleans.+ ['an attached -XPOST is an authenticated write', 'gh api -XPOST /repos/x/y/issues'],+ ['an attached -X=POST is an authenticated write', 'gh api -X=POST /repos/x/y/issues'],+ ['a -XPOST clustered after -i is an authenticated write', 'gh api -iXPOST /repos/x/y/issues'],+ ['glab api -XDELETE is an authenticated write', 'glab api -XDELETE /projects/1'],+ ['an attached -F field uploads a local file in a POST', 'gh api /repos/x/y/issues -Fbody=@/example/file'],+ ['an attached -f field makes gh api an implicit POST', 'gh api /repos/x/y/issues -ftitle=hi'],+ ['--input= sends a local file as the request body', 'gh api /repos/x/y/issues --input=/example/file'],])('rejects %s', (_label, cmd) => {expect(validateUnattendedCommand(cmd).valid).toBe(false)})@@ -539,6 +547,9 @@ describe('commandSecurity', () => {'gh issue view 1','gh api /rate_limit','gh api -X GET /rate_limit',+ 'gh api -XGET /rate_limit',+ 'gh api -i /rate_limit',+ 'gh api /repos/x/y -q.name','glab mr list','glab issue view 1',])('accepts read-only tracker command %s', (cmd) => {