mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-03 13:24:19 +01:00
The secrets check no longer reports an 11-digit GitHub Actions run id as a phone number when code names it `runId`, `RunGithubID` or passes it to a run call such as `resolveRunDetection(...)`. Why: Go and TypeScript test fixtures tripped a phone-number finding, and `gstack-post` asked for confirmation on PR bodies that quoted them. Nothing to do; every number the check reported before still reports. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/red-team#2 reader=red-team Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/outside-voice#2 reader=outside-voice Review-Finding: p2/red-team#1 reader=red-team Review-Finding: p2/adversarial-native#1 reader=adversarial-native Review-Finding: p2/adversarial-native#3 reader=adversarial-native
This commit is contained in:
1 parent
4b8c7005dc
commit
be9b34e3dc
4 files changed
+112
-1
No files matched your search
+37
-1
@@ -453,20 +453,56 @@ export function isNumericMetadataValue(span: string, match: RegExpExecArray): bo
|
||||
* owner's ruling that a run id is not a phone number; gstack-post's chained-id
|
||||
* allowlist reads the same position the same way. The same digits anywhere
|
||||
* else still report.
|
||||
*
|
||||
* Code names the run with a camelCase identifier instead (#4861), so an
|
||||
* 11-digit id also counts as the whole value of a key or assignment named by
|
||||
* a compound run identifier: Run after a lowercase letter or digit, optionally
|
||||
* followed by Id/ID or GithubId/GitHubID/ActionsId/WorkflowId (`lastRun := <id>`,
|
||||
* `RunGithubID: <id>` inside a struct, `workflowRunID = <id>`), or run/Run
|
||||
* starting the name with one of those Id endings (`runId: <id>`); or as an
|
||||
* argument of a call whose name ends in Run plus Id, Detection, Status,
|
||||
* Result, Attempt, Log, Job or Artifact, after only plain identifier
|
||||
* arguments (`resolveRunDetection(t, db, d, <id>,`). A plain `run` key is
|
||||
* left to the run-word rule above, so a quoted JSON `"run": <n>` still
|
||||
* reports. The id must end the value (a closing quote matching an opening
|
||||
* one, else the line end, a space, `,`, `;`, `)`, `}` or `]`), so
|
||||
* `runId: '<n>-<stamp>'` reports. `runner`, `brunId` and `myRunnerPhone`
|
||||
* exempt nothing, and neither does a phone word anywhere on the line within
|
||||
* 80 characters either side of the id, read as a substring of the lowercased
|
||||
* text (phone, tel, mobile, cell, fax, sms, contact, msisdn, whatsapp, call,
|
||||
* dial: `phoneRun`, `cellphoneRunId`, `user.phone.lastRun`,
|
||||
* `"phone-lastRunId"`, `resolveRunDetection(t, phone, <n>`,
|
||||
* `lastRun = <n>; // mobile`), nor a key or call whose name the
|
||||
* 80-character window cuts off, since the cut part could hold one.
|
||||
*/
|
||||
const CI_ID_POSITION_BEFORE =
|
||||
/(?:--(?:run|job)(?:-id)?(?:[ \t]+|[ \t]*=[ \t]*)|\bgh[ \t]+run[ \t]+(?:view|watch|rerun|download|cancel)[ \t]+|(?:^|[\s\/(\[<"'])actions\/runs\/|\/jobs?\/|(?:run|job)_id["']?[ \t]*[:=][ \t]*["']?)$/i;
|
||||
const CI_RUN_LIST = /(?<![\w-])runs?=\d{11,12}\/\d{1,3}(?:,\d{11,12}\/\d{1,3})*(?![\w\/])/gi;
|
||||
/** A run word with an optional ':' '#' '=' right before an 11-digit token; shared with gstack-post's chained-id allowlist. */
|
||||
export const CI_RUN_WORD_BEFORE = /\b(?:runs?|screens?|gates?|backstop|bisect|rerun|dispatch(?:ed)?|failed|passed)\s*[:#=]?\s*$/i;
|
||||
const RUN_KEY_BEFORE = /(?<![\w$])([A-Za-z_$][\w$]*)["']?[ \t]*(?::=|[:=])[ \t]*(["']?)$/;
|
||||
const RUN_CALL_BEFORE = /(?<![\w$])([A-Za-z_$][\w$]*)\((?:[ \t]*[A-Za-z_$][\w$.]*[ \t]*,)*[ \t]*$/;
|
||||
const RUN_KEY_NAME = /(?:[a-z\d]Run(?:(?:Git[Hh]ub|Actions?|Workflow)?I[Dd])?|^[rR]un(?:Git[Hh]ub|Actions?|Workflow)?I[Dd])$/;
|
||||
const RUN_CALL_NAME = /(?:^[rR]|[a-z\d]R)un(?:I[Dd]s?|Detection|Status|Results?|Attempts?|Logs?|Jobs?|Artifacts?)$/;
|
||||
const PHONE_WORD = /phone|tel|mobile|cell|fax|sms|contact|msisdn|whatsapp|call|dial/;
|
||||
function isCamelCaseRunIdPosition(before: string, after: string, truncated: boolean): boolean {
|
||||
const key = RUN_KEY_BEFORE.exec(before);
|
||||
const call = RUN_CALL_BEFORE.exec(before);
|
||||
const hit = key && RUN_KEY_NAME.test(key[1]!) ? key : call && RUN_CALL_NAME.test(call[1]!) ? call : null;
|
||||
if (!hit || (truncated && hit.index === 0)) return false;
|
||||
const quote = hit === key ? key[2]! : "";
|
||||
if (quote ? after[0] !== quote : !/^(?:$|[\s,;)}\]])/.test(after)) return false;
|
||||
return !PHONE_WORD.test((before + after).toLowerCase());
|
||||
}
|
||||
export function isCiRunIdentifier(span: string, match: RegExpExecArray): boolean {
|
||||
if (!/^\d+$/.test(span)) return false;
|
||||
const input = match.input ?? "";
|
||||
const { start } = spanBounds(match);
|
||||
const lineStart = input.lastIndexOf("\n", start - 1) + 1;
|
||||
const before = input.slice(Math.max(lineStart, start - 80), start);
|
||||
if (CI_ID_POSITION_BEFORE.test(before) || (span.length === 11 && CI_RUN_WORD_BEFORE.test(before))) return true;
|
||||
const lineEnd = input.indexOf("\n", start);
|
||||
const after = input.slice(start + span.length, Math.min(lineEnd < 0 ? input.length : lineEnd, start + span.length + 80));
|
||||
if (CI_ID_POSITION_BEFORE.test(before) || (span.length === 11 && (CI_RUN_WORD_BEFORE.test(before) || isCamelCaseRunIdPosition(before, after, start - 80 > lineStart)))) return true;
|
||||
const line = input.slice(lineStart, lineEnd < 0 ? input.length : lineEnd);
|
||||
const at = start - lineStart;
|
||||
return [...line.matchAll(CI_RUN_LIST)].some(m => m.index! < at && at + span.length <= m.index! + m[0].length);
|
||||
|
||||
Reference in new issue
Block a user