-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(e2e): match credential values in sandbox scan #9395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+219
−52
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c13c302
fix(e2e): match credential values in sandbox scan
ericksoa 8486538
fix(e2e): scan binary state for credentials
ericksoa 2ea0303
refactor(security): share provider token specs
ericksoa 434134e
test(e2e): document credential scan fixtures
ericksoa 513050d
fix(security): detect fine-grained GitHub tokens
ericksoa a94787c
test(e2e): contain credential scan fixtures
ericksoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { shellQuote } from "../../../src/lib/core/shell-quote.ts"; | ||
| import { HIGH_CONFIDENCE_PREFIXED_TOKEN_ERE } from "../../../nemoclaw/src/security/secret-scanner.ts"; | ||
|
|
||
| const DEFAULT_SANDBOX_STATE_DIRECTORIES = ["/sandbox/.openclaw", "/sandbox/.nemoclaw"]; | ||
|
|
||
| /** Build a path-only scan for concrete credential values in sandbox state. */ | ||
| export function buildSandboxCredentialScanCommand( | ||
| directories: readonly string[] = DEFAULT_SANDBOX_STATE_DIRECTORIES, | ||
| ): string { | ||
| const roots = directories.map((directory) => shellQuote(directory)).join(" "); | ||
| return [ | ||
| `for dir in ${roots}; do`, | ||
| ' [ -d "$dir" ] || continue', | ||
| ` matches=$(grep -rlE '${HIGH_CONFIDENCE_PREFIXED_TOKEN_ERE}' "$dir")`, | ||
| " scan_status=$?", | ||
| ' case "$scan_status" in', | ||
| ` 0) printf '%s\\n' "$matches" | grep -Ev '/policies/|/plugin-runtime-deps/|/extensions/[^/]+/(dist|node_modules)/'`, | ||
| " filter_status=$?", | ||
| ' case "$filter_status" in', | ||
| " 0|1) ;;", | ||
| ' *) exit "$filter_status" ;;', | ||
| " esac", | ||
| " ;;", | ||
| " 1) ;;", | ||
| ' *) exit "$scan_status" ;;', | ||
| " esac", | ||
| "done", | ||
| ].join("\n"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
test/e2e/support/cloud-inference-credential-boundary.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { execFileSync } from "node:child_process"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| import { afterEach, describe, expect, it } from "vitest"; | ||
|
|
||
| import { HIGH_CONFIDENCE_PREFIXED_TOKEN_SPECS } from "../../../nemoclaw/src/security/secret-scanner.ts"; | ||
| import { buildSandboxCredentialScanCommand } from "../live/cloud-inference-credential-boundary.ts"; | ||
|
|
||
| const roots: string[] = []; | ||
|
|
||
| afterEach(() => { | ||
| for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| /** Create and track an isolated sandbox-state fixture root. */ | ||
| function createScanRoot(): string { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-cloud-credential-scan-")); | ||
| roots.push(root); | ||
| return root; | ||
| } | ||
|
|
||
| /** Write one text or binary sandbox-state fixture and return its path. */ | ||
| function writeFixture(root: string, relativePath: string, body: string | Uint8Array): string { | ||
| const file = path.join(root, relativePath); | ||
| fs.mkdirSync(path.dirname(file), { recursive: true }); | ||
| fs.writeFileSync(file, body); | ||
|
ericksoa marked this conversation as resolved.
|
||
| return file; | ||
| } | ||
|
|
||
| /** Run the exact live credential scan command against a fixture root. */ | ||
| function scan(root: string): string { | ||
| return execFileSync("sh", ["-lc", buildSandboxCredentialScanCommand([root])], { | ||
| encoding: "utf8", | ||
| }); | ||
| } | ||
|
|
||
| describe("cloud inference sandbox credential scan", () => { | ||
| it("accepts npm dependency metadata that does not contain a credential value (#9363)", () => { | ||
| const root = createScanRoot(); | ||
| writeFixture( | ||
| root, | ||
| "npm/projects/openclaw-whatsapp/node_modules/thread-stream/test/ts/transpile.sh", | ||
| 'echo "${npm_config_user_agent}"\n', | ||
| ); | ||
| writeFixture( | ||
| root, | ||
| "npm/projects/openclaw-msteams/node_modules/jwks-rsa/package.json", | ||
| '{"scripts":{"release":"git tag $npm_package_version"}}\n', | ||
| ); | ||
| writeFixture(root, "configuration/token-key-path.txt", "ordinary dependency metadata\n"); | ||
|
|
||
| expect(scan(root)).toBe(""); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["NVIDIA", "nvapi-nemoclaw-credential-boundary-canary"], | ||
| ["GitHub", `ghp_${"a".repeat(36)}`], | ||
| ["GitHub fine-grained", `github_pat_${"a".repeat(15)}_${"b".repeat(14)}`], | ||
| ["npm", `npm_${"b".repeat(36)}`], | ||
| ])("reports only the path of a file that contains a %s credential canary", (_label, canary) => { | ||
| const root = createScanRoot(); | ||
| const leakedFile = writeFixture(root, "openclaw.json", `{"apiKey":"${canary}"}\n`); | ||
|
|
||
| const output = scan(root); | ||
|
|
||
| expect(output.trim()).toBe(leakedFile); | ||
| expect(output).not.toContain(canary); | ||
| }); | ||
|
|
||
| it.each( | ||
| HIGH_CONFIDENCE_PREFIXED_TOKEN_SPECS.flatMap(({ prefixes, minimumPayloadLength }) => | ||
| prefixes.map((prefix) => [prefix, minimumPayloadLength] as const), | ||
| ), | ||
| )("enforces the shared minimum payload for %s", (prefix, minimumPayloadLength) => { | ||
| const root = createScanRoot(); | ||
| writeFixture(root, "short.txt", `${prefix}${"a".repeat(minimumPayloadLength - 1)}\n`); | ||
|
|
||
| expect(scan(root)).toBe(""); | ||
|
|
||
| const detectedFile = writeFixture( | ||
| root, | ||
| "minimum.txt", | ||
| `${prefix}${"a".repeat(minimumPayloadLength)}\n`, | ||
| ); | ||
| expect(scan(root).trim()).toBe(detectedFile); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["prefixed GitHub token", `prefixghp_${"a".repeat(36)}`], | ||
| ["suffixed GitHub token", `ghp_${"a".repeat(36)}_suffix`], | ||
| ["prefixed npm token", `prefixnpm_${"b".repeat(36)}`], | ||
| ["suffixed npm token", `npm_${"b".repeat(36)}_suffix`], | ||
| ])("does not report a token embedded in a larger identifier: %s", (_label, value) => { | ||
| const root = createScanRoot(); | ||
| writeFixture(root, "embedded.txt", `${value}\n`); | ||
|
|
||
| expect(scan(root)).toBe(""); | ||
| }); | ||
|
|
||
| it("reports a credential canary in a NUL-containing file", () => { | ||
| const root = createScanRoot(); | ||
| const canary = "nvapi-nemoclaw-binary-credential-canary"; | ||
| const leakedFile = writeFixture(root, "state.bin", Buffer.from(`prefix\0${canary}\n`)); | ||
|
|
||
| const output = scan(root); | ||
|
|
||
| expect(output.trim()).toBe(leakedFile); | ||
| expect(output).not.toContain(canary); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.