-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(security): strip gateway token from descendants #8872
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
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { spawnSync } from "node:child_process"; | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { extractShellFunctionFromSource } from "./support/shell-function-extractor"; | ||
|
|
||
| const START_SCRIPT = path.resolve(import.meta.dirname, "../scripts/nemoclaw-start.sh"); | ||
|
|
||
| describe("OpenClaw gateway credential environment", () => { | ||
| it.each([ | ||
| "truncate", | ||
| "append", | ||
| ])("removes the dashboard token from a %s gateway launch (#8693)", (logMode) => { | ||
| const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-token-env-")); | ||
| const gatewayLog = path.join(tmpDir, "gateway.log"); | ||
| const source = fs.readFileSync(START_SCRIPT, "utf8"); | ||
| const launch = extractShellFunctionFromSource( | ||
| source, | ||
| "launch_openclaw_gateway_process", | ||
| ).replaceAll("/tmp/gateway.log", gatewayLog); | ||
| const script = [ | ||
| "set -euo pipefail", | ||
| launch, | ||
| "export OPENCLAW_GATEWAY_TOKEN=dashboard-secret", | ||
| `launch_openclaw_gateway_process ${logMode} sh -c 'printf "%s\\n" "\${OPENCLAW_GATEWAY_TOKEN-unset}"'`, | ||
| 'wait "$GATEWAY_PID"', | ||
| ].join("\n"); | ||
|
|
||
| try { | ||
| const result = spawnSync("bash", ["-c", script], { encoding: "utf8", timeout: 5000 }); | ||
| expect(result.status, result.stderr).toBe(0); | ||
| expect(fs.readFileSync(gatewayLog, "utf8")).toBe("unset\n"); | ||
| } finally { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects an unknown gateway log mode before launch (#8693)", () => { | ||
| const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-token-env-")); | ||
| const gatewayLog = path.join(tmpDir, "gateway.log"); | ||
| const source = fs.readFileSync(START_SCRIPT, "utf8"); | ||
| const launch = extractShellFunctionFromSource( | ||
| source, | ||
| "launch_openclaw_gateway_process", | ||
| ).replaceAll("/tmp/gateway.log", gatewayLog); | ||
| const result = spawnSync( | ||
| "bash", | ||
| ["-c", [launch, "launch_openclaw_gateway_process invalid true"].join("\n")], | ||
| { encoding: "utf8", timeout: 5000 }, | ||
| ); | ||
|
|
||
| try { | ||
| expect(result.status).toBe(1); | ||
| expect(result.stderr).toContain("invalid gateway log mode: invalid"); | ||
| expect(fs.existsSync(gatewayLog)).toBe(false); | ||
| } finally { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
| }); | ||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Test the log-mode effect.
The test uses an empty gateway log for both modes. It passes if
appendtruncates the log or iftruncateappends to it. Seed the log and assert the distinct final contents.Proposed test update
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-token-env-")); const gatewayLog = path.join(tmpDir, "gateway.log"); + fs.writeFileSync(gatewayLog, "existing\n"); const source = fs.readFileSync(START_SCRIPT, "utf8"); @@ - expect(fs.readFileSync(gatewayLog, "utf8")).toBe("unset\n"); + expect(fs.readFileSync(gatewayLog, "utf8")).toBe( + logMode === "append" ? "existing\nunset\n" : "unset\n", + );As per path instructions, “Review tests for behavioral confidence rather than implementation lock-in.”
📝 Committable suggestion
🧰 Tools
🪛 ast-grep (0.45.1)
[warning] 21-21: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFileSync(START_SCRIPT, "utf8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
(detect-non-literal-fs-filename-typescript)
[warning] 37-37: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFileSync(gatewayLog, "utf8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
(detect-non-literal-fs-filename-typescript)
🤖 Prompt for AI Agents
Source: Path instructions