Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/workflow-registry-audit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ function sanitizeDiagnosticDetail(error) {
/\b((?:GH|GITHUB|ACCESS|AUTH|ID|REFRESH)?_?TOKEN)\s*=\s*[^\s,;]+/gi,
`$1=${REDACTED}`,
)
.replace(/\bgithub_pat_[A-Za-z0-9_]+\b/g, REDACTED)
.replace(/\bgh[pousr]_[A-Za-z0-9_]+\b/g, REDACTED)
.slice(0, MAX_DIAGNOSTIC_DETAIL_LENGTH);
}
Expand Down Expand Up @@ -523,4 +524,4 @@ export async function collectWorkflowRegistryAudit(input) {
}

return result;
}
}
1 change: 1 addition & 0 deletions scripts/workflow-registry-live-audit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function boundedDiagnostic(value) {
const cleaned = String(value ?? "")
.replace(/[\u0000-\u001f\u007f]/g, "")
.replace(/\bbearer\s+\S+/gi, "Bearer [REDACTED]")
.replace(/\bgithub_pat_[A-Za-z0-9_]+\b/g, "[REDACTED]")
.replace(/\bgh[pousr]_[A-Za-z0-9_]+\b/g, "[REDACTED]")
.trim();
return cleaned.length <= 2_048 ? cleaned : `${cleaned.slice(0, 2_048)}…`;
Expand Down
28 changes: 28 additions & 0 deletions test/workflow-registry-live-audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,32 @@ describe("live workflow-registry collector", () => {
http_status: 403,
}));
});

it("redacts fine-grained GitHub tokens from collection failures", async () => {
const leakedToken = "github_pat_11EXAMPLE_secretmaterial";
const ghJson = async (endpoint: string) => {
if (endpoint === "repos/ContextualWisdomLab/noema/branches/main") {
return { commit: { sha: mainSha } };
}
if (endpoint.startsWith("repos/ContextualWisdomLab/noema/git/trees/")) {
return { truncated: false, tree: [] };
}
if (endpoint.includes("/actions/workflows?")) {
throw Object.assign(new Error(`HTTP 403 token=${leakedToken}`), { status: 403 });
}
throw new Error(`unexpected endpoint ${endpoint}`);
};

const result = await collectLiveWorkflowRegistryAudit({
repository: "ContextualWisdomLab/noema",
defaultBranch: "main",
ghJson,
now: () => observedAt,
});

const detail = String(result.failures[0]?.detail ?? "");
expect(result.status).toBe("FAIL");
expect(detail).toContain("[REDACTED]");
expect(detail).not.toContain(leakedToken);
});
});
Loading