Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions test/e2e/live/cloud-inference-secret-pattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export const SANDBOX_SECRET_TOKEN_PATTERN =
"(nvapi-[A-Za-z0-9_-]{10,}|ghp_[A-Za-z0-9_-]{10,}|npm_[A-Za-z0-9]{10,})";
5 changes: 3 additions & 2 deletions test/e2e/live/cloud-inference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
parseCloudChatResponse,
type PreContractExternalProviderFailure,
} from "./cloud-inference-provider-skip.ts";
import { SANDBOX_SECRET_TOKEN_PATTERN } from "./cloud-inference-secret-pattern.ts";

const REPO_SKILL_VALIDATOR = path.join(
REPO_ROOT,
Expand Down Expand Up @@ -305,7 +306,7 @@ async function expectSandboxCredentialBoundary(
const secretScanCommand = [
"for dir in /sandbox/.openclaw /sandbox/.nemoclaw; do",
' [ -d "$dir" ] || continue',
` matches=$(grep -rIlE 'nvapi-|ghp_|npm_' "$dir")`,
` matches=$(grep -rIlE '${SANDBOX_SECRET_TOKEN_PATTERN}' "$dir")`,
" scan_status=$?",
' case "$scan_status" in',
` 0) filtered=$(printf '%s\\n' "$matches" | grep -Ev '/policies/|/plugin-runtime-deps/|/extensions/[^/]+/(dist|node_modules)/')`,
Expand All @@ -319,7 +320,7 @@ async function expectSandboxCredentialBoundary(
" write_status=$?",
' case "$write_status" in 0) ;; *) exit "$write_status" ;; esac',
" while IFS= read -r file; do",
` matching_lines=$(grep -IE 'nvapi-|ghp_|npm_' "$file")`,
` matching_lines=$(grep -IE '${SANDBOX_SECRET_TOKEN_PATTERN}' "$file")`,
" match_status=$?",
' case "$match_status" in',
` 0) printf '%s' "$matching_lines" | grep -qv 'STRIPPED'`,
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/support/cloud-inference-credential-pattern.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from "vitest";

import { SANDBOX_SECRET_TOKEN_PATTERN } from "../live/cloud-inference-secret-pattern.ts";

const credentialPattern = new RegExp(SANDBOX_SECRET_TOKEN_PATTERN, "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);
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it.each(["nvapi-", "ghp_", "npm_"])(
"rejects a nine-character payload for %s",
(prefix) => {
expect(`${prefix}${"a".repeat(9)}`).not.toMatch(credentialPattern);
},
);

it.each(["nvapi-", "ghp_", "npm_"])(
"detects a ten-character payload for %s",
(prefix) => {
expect(`${prefix}${"a".repeat(10)}`).toMatch(credentialPattern);
},
);
});
Loading