Skip to content

Commit 513050d

Browse files
committed
fix(security): detect fine-grained GitHub tokens
Signed-off-by: Aaron Erickson <aerickson@nvidia.com>
1 parent 434134e commit 513050d

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

nemoclaw/src/security/secret-scanner.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const FAKE = {
1111
openai: "sk-" + "abc123def456ghi789jkl012mno",
1212
openaiProject: "sk-proj-" + "abc123_def456-ghi789_jkl012-mno345",
1313
github: "ghp_" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn",
14+
githubFineGrained: "github_pat_" + "ABCDEFGHIJKLMNO_PQRSTUVWXYZabc",
1415
aws: "AKIA" + "IOSFODNN7EXAMPLE",
1516
slack: "xoxb-" + "123456789-abcdefghij",
1617
slackApp: "xapp-" + "1-A0000-12345-abcdef",
@@ -54,6 +55,12 @@ describe("scanForSecrets", () => {
5455
expect(matches[0].pattern).toBe("GitHub token");
5556
});
5657

58+
it("detects an underscore-bearing fine-grained GitHub personal access token", () => {
59+
const matches = scanForSecrets(`token: ${FAKE.githubFineGrained}`);
60+
expect(matches).toHaveLength(1);
61+
expect(matches[0].pattern).toBe("GitHub token");
62+
});
63+
5764
it("detects an AWS access key", () => {
5865
const matches = scanForSecrets(`aws_access_key_id = ${FAKE.aws}`);
5966
expect(matches).toHaveLength(1);

nemoclaw/src/security/secret-scanner.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ export const HIGH_CONFIDENCE_PREFIXED_TOKEN_SPECS = [
3131
},
3232
{
3333
name: "GitHub token",
34-
prefixes: ["ghp_", "gho_", "ghu_", "ghs_", "ghr_", "github_pat_"],
34+
prefixes: ["ghp_", "gho_", "ghu_", "ghs_", "ghr_"],
3535
payloadCharacterClass: "A-Za-z0-9",
3636
minimumPayloadLength: 36,
3737
},
38+
{
39+
name: "GitHub token",
40+
prefixes: ["github_pat_"],
41+
payloadCharacterClass: "A-Za-z0-9_",
42+
minimumPayloadLength: 30,
43+
},
3844
{
3945
name: "npm token",
4046
prefixes: ["npm_"],

test/e2e/support/cloud-inference-credential-boundary.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe("cloud inference sandbox credential scan", () => {
6060
it.each([
6161
["NVIDIA", "nvapi-nemoclaw-credential-boundary-canary"],
6262
["GitHub", `ghp_${"a".repeat(36)}`],
63+
["GitHub fine-grained", `github_pat_${"a".repeat(15)}_${"b".repeat(14)}`],
6364
["npm", `npm_${"b".repeat(36)}`],
6465
])("reports only the path of a file that contains a %s credential canary", (_label, canary) => {
6566
const root = createScanRoot();

0 commit comments

Comments
 (0)