Repository navigation
fix(e2e): detect credential values in sandbox scans #9382
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
Closed
deepujain
wants to merge
3
commits into
NVIDIA:main
from
deepujain:fix/9363-credential-boundary-scan
+83
−10
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
42 changes: 42 additions & 0 deletions
42
test/e2e/support/cloud-inference-credential-pattern.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,42 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { HIGH_CONFIDENCE_PREFIXED_TOKEN_ERE } from "../../../nemoclaw/src/security/secret-scanner.ts"; | ||
|
|
||
| const credentialPattern = new RegExp(HIGH_CONFIDENCE_PREFIXED_TOKEN_ERE, "u"); | ||
|
|
||
| describe("cloud inference credential scan", () => { | ||
| it.each([ | ||
| "/sandbox/.openclaw/extensions/example/node_modules/thread-stream/test/ts/transpile.sh", | ||
| "/sandbox/.openclaw/extensions/example/node_modules/jwks-rsa/package.json", | ||
| "package-lock entry for npm_config_cache metadata", | ||
| ])("accepts dependency text without a credential value: %s", (value) => { | ||
| expect(value).not.toMatch(credentialPattern); | ||
| }); | ||
|
|
||
| it.each([ | ||
| `NVIDIA_INFERENCE_API_KEY=nvapi-${"a".repeat(30)}`, | ||
| `GITHUB_TOKEN=ghp_${"b".repeat(36)}`, | ||
| `NPM_TOKEN=npm_${"c".repeat(36)}`, | ||
| ])("detects a credential-shaped value", (value) => { | ||
| expect(value).toMatch(credentialPattern); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| it.each([ | ||
| ["nvapi-", 20], | ||
| ["ghp_", 36], | ||
| ["npm_", 36], | ||
| ])("enforces the minimum payload for %s", (prefix, minimumPayloadLength) => { | ||
| expect(`${prefix}${"a".repeat(minimumPayloadLength - 1)}`).not.toMatch(credentialPattern); | ||
| expect(`${prefix}${"a".repeat(minimumPayloadLength)}`).toMatch(credentialPattern); | ||
| }); | ||
|
|
||
| it.each(["gho_", "ghu_", "ghs_", "ghr_", "github_pat_"])( | ||
| "detects a supported GitHub token prefix: %s", | ||
| (prefix) => { | ||
| expect(`${prefix}${"a".repeat(36)}`).toMatch(credentialPattern); | ||
| }, | ||
| ); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Align POSIX ERE boundaries with the in-process matcher.
The generated POSIX ERE has no start or end delimiter, but
SECRET_PATTERNSadds\baround the same provider patterns. The sandbox scan can therefore matchpathnpm_<payload>ornpm_<payload>_suffixinside larger identifiers whilescanForSecretsrejects the same text.Define a POSIX-compatible boundary policy for the generated alternatives. Add negative tests for embedded prefixes and suffixes. This prevents dependency and path false positives in both sandbox scan stages.
As per path instructions, “Security-sensitive code paths require extra test coverage.”
🧰 Tools
🪛 ast-grep (0.45.1)
[warning] 57-59: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(
\\b(?:${prefixes.join("|")})[${payloadCharacterClass}]{${minimumPayloadLength},}\\b,)
Note: [CWE-1333] Inefficient Regular Expression Complexity
(regexp-from-variable)
🤖 Prompt for AI Agents
Source: Path instructions