Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(maker-core): scan gh auth credential flags without quadratic retries
zqchris465fec92dd7d
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex ca5fed0414..bb68b703f3 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -4685,6 +4685,36 @@ describe('删除也是写通道:普通 rm / mv 源 / cmd del(第四十八批评});describe('shellCommandReadsCredentials — 只认凭证那一部分红线', () => {+ it.each([800, 3200, 6400, 24000])('scans repeated gh auth heads in under a second (%i repetitions)', (count) => {+ const command = 'gh auth a '.repeat(count);+ const start = performance.now();+ expect(shellCommandReadsCredentials(command, roots)).toBe(false);+ expect(performance.now() - start).toBeLessThan(1000);+ });++ it('keeps token flags at the end of long auth segments without repeated backtracking', () => {+ const prefix = 'gh auth a '.repeat(24000);+ for (const flag of ['--show-token', '--show-token=true', '-t', '-wt=true', '-tw']) {+ expect(shellCommandReadsCredentials(prefix + flag, roots), flag).toBe(true);+ }+ const invalidCluster = 'gh auth status -' + 't'.repeat(240000) + '-';+ const start = performance.now();+ expect(shellCommandReadsCredentials(invalidCluster, roots)).toBe(false);+ expect(performance.now() - start).toBeLessThan(1000);+ });++ it('does not carry auth context into another command segment', () => {+ for (const separator of [';', '|', '&', '\n']) {+ expect(shellCommandReadsCredentials(`gh auth status${separator}echo --show-token`, roots)).toBe(false);+ expect(shellCommandReadsCredentials(`gh auth status${separator}/usr/bin/gh auth status --hostname github.com -wt`, roots)).toBe(true);+ }+ for (const command of ['gh auth a gh auth\nstatus -t', 'gh auth gh auth\nstatus --show-token']) {+ expect(shellCommandReadsCredentials(command, roots), command).toBe(true);+ }+ expect(shellCommandReadsCredentials('./gh auth status --show-token', roots)).toBe(true);+ expect(shellCommandReadsCredentials('notgh auth status --show-token', roots)).toBe(false);+ });+it('读凭证 / 密钥文件、钥匙串、令牌与云 metadata 都算', () => {for (const command of ['cat ~/.ssh/id_rsa',diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex f848e21fa5..02b150593a 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -1577,43 +1577,50 @@ function stripDataLiterals(command: string): string {);}+type CommandScanPattern = Pick<RegExp, 'test'>;++function ghAuthShowsToken(command: string): boolean {+ // A slash also establishes a command boundary for /usr/bin/gh and ./gh.+ // Avoid rescanning an arbitrary path prefix from every shell separator.+ const heads = /(?:^|[\s|&;(\/])gh\s+auth\s+[a-z][\w-]*/g;+ const boundary = /[|;&\n]/g;+ // Sticky: scan the suffix only from the first auth head in each segment.+ // Keep --show-token[=value], -t/-wt/-tw[=value] and separator boundaries.+ // The lookahead makes the short-option letter run linear even for a long+ // cluster containing many t's followed by an invalid trailing '-'.+ const flags = /[^|;&\n]*?\s(?:--show-token(?:$|[\s=|&;)])|-(?=[a-zA-Z]*t)[a-zA-Z]+(?:=[^\s|;&]*)?(?![\w-]))/y;+ let scannedUntil = -1;+ let head: RegExpExecArray | null;+ while ((head = heads.exec(command))) {+ const argsStart = heads.lastIndex;+ // Preserve overlapping heads and heads whose whitespace spans a newline.+ // Only a head ending beyond the already-scanned segment needs another scan.+ heads.lastIndex = head.index + 1;+ if (argsStart <= scannedUntil) continue;+ flags.lastIndex = argsStart;+ if (flags.test(command)) return true;+ boundary.lastIndex = argsStart;+ scannedUntil = boundary.exec(command)?.index ?? command.length;+ }+ return false;+}+/*** 读取或打出可复用凭证的确定性红线(ALWAYS_ASK_PATTERNS 的子集)。单独成表:供应商分享的受邀者* 任务在完全访问下也要确认这一类(shellCommandReadsCredentials)。*/-const CREDENTIAL_ALWAYS_ASK_PATTERNS: readonly RegExp[] = [- // `--show-token` = 把**可复用的凭证**打进 stdout,从而进模型上下文与会话记录。等同于- // 读凭证文件,按凭证同级作**确定性必问** —— 只把它挡在 gh 只读白名单外还不够:落灰区- // 意味着可能被轻量审阅器静默放行(`gh auth status` 看起来就是一条状态查询)。- // 覆盖 `--show-token` / `--show-token=true` 两种形态(review 二轮 P1)。- // **必须限定在 `gh auth` 命令位**:这个字符串出现在别处只是普通文本或参数,- // `echo --show-token`、`grep -rn -- --show-token src` 原本是直接放行的,不限定就被打成- // 硬弹窗 —— 正是本 PR 要消灭的那类误报(review 报)。命令位写法与下面的短选项一致。- // 首尾边界要**对称**:命令位允许分隔符开头(`ls;gh auth …`),flag 后面同样可以紧跟- // `;` `|` `&` `)` 而不带空格 —— 只补开头是把同一条边界修了一半(review 报)。- /(?:^|[\s|&;(])(?:\S*\/)?gh\s+auth\s+[a-z][\w-]*[^|;&\n]*?\s--show-token(?:$|[\s=|&;)])/,- // 短选项形态:`gh auth status -t` 与含 `t` 的簇写(`-wt`/`-tw`)是同一个 flag,只把它挡在- // gh 只读白名单外不够 —— 落灰区就可能被轻量审阅器静默放行(review 三轮 P1)。`-t` 本身- // 在别的命令里含义完全不同(`docker -t`、`tar -t`),所以**限定在 `gh auth` 命令位**上匹配。- // `(?:\S*\/)?` 让绝对/相对路径调用同样命中(`/usr/bin/gh auth status -t`,review 四轮 P1)——- // 只匹配裸 `gh` 等于给一个换写法就绕过的口子。- // 子命令与 `-t` 之间允许**任意**中间参数:`gh auth status --hostname github.com -t` 是- // 合法组合,原来只允许非选项 token 会漏(review 报)。用 `[^|;&\n]*?` 限定在同一段内。- // 结尾的 `(?:=[^\s|;&]*)?` 覆盖 `-t=true` 这类**带等号的 truthy 布尔值** —— gh 照常接受,- // 而原来的 `(?![\w=-])` 把等号形态排除在外,令牌仍会被打进模型上下文(review 报)。- // 命令位判据用 `(?:^|[\s|&;(])` 而不是 `(?:^|\s)`:分隔符后可以不带空格- // (`ls;gh auth token`、`ls&&gh auth token`、`(gh auth token)`),而分段之后不会再重扫- // 确定性红线 —— 只认空白等于给一个删空格就绕过的口子(review 报)。与 ALWAYS_ASK_PATTERNS 里 `su`- // 那条的边界写法一致。- /(?:^|[\s|&;(])(?:\S*\/)?gh\s+auth\s+[a-z][\w-]*[^|;&\n]*?\s-[a-zA-Z]*t[a-zA-Z]*(?:=[^\s|;&]*)?(?![\w-])/,- // `gh auth token` 直接把令牌打到 stdout,与 `--show-token` 同级(同族一次收完)。- /(?:^|[\s|&;(])(?:\S*\/)?gh\s+auth\s+token\b/,+const CREDENTIAL_ALWAYS_ASK_PATTERNS: readonly CommandScanPattern[] = [+ // Token flags belong to gh auth only: echo/grep --show-token and docker -t+ // must not become credential prompts. Use the same scanner in both gates.+ { test: ghAuthShowsToken },+ // `gh auth token` directly prints a reusable credential.+ /(?:^|[\s|&;(\/])gh\s+auth\s+token\b/,...SENSITIVE_CREDENTIAL_PATH_PATTERNS, // 凭证/密钥路径(见上)/\bsecurity\s+(?:find|dump|export|add)-/, // macOS keychain/\$\{?[A-Za-z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|APIKEY|_PAT)[A-Za-z0-9_]*\}?/i, // 敏感环境变量展开(echo "$API_KEY" 等)];-const ALWAYS_ASK_PATTERNS: readonly RegExp[] = [+const ALWAYS_ASK_PATTERNS: readonly CommandScanPattern[] = [/\b(?:sudo|doas|runuser)\b/, // 提权(runuser 名字独特,直接词界)...CREDENTIAL_ALWAYS_ASK_PATTERNS, // 凭证文件、钥匙串、令牌(见上)// 裸 `su`(切换到其它用户/root)同属提权,但 "su" 常出现在无关文本里 → 只在命令位(段首/分隔符后,或@@ -6527,7 +6534,7 @@ function fetchesCloudMetadata(quotesOnly: string): boolean {return false;}-function matchesAnyVariant(patterns: readonly RegExp[], variants: ReturnType<typeof deterministicScanVariants>): boolean {+function matchesAnyVariant(patterns: readonly CommandScanPattern[], variants: ReturnType<typeof deterministicScanVariants>): boolean {const texts = Object.values(variants);return patterns.some((re) => texts.some((text) => re.test(text)));}