Skip to content
Closed
36 changes: 17 additions & 19 deletions agents/hermes/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,7 @@ seal_hermes_restart_inputs() {
HERMES_RESTART_SEALED=0
install_hermes_restart_seal_traps
if ! output="$(
"${_HERMES_GUARD_TIMEOUT[@]}" "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" seal-restart \
${_HERMES_GUARD_TIMEOUT[@]+"${_HERMES_GUARD_TIMEOUT[@]}"} "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" seal-restart \
--hermes-dir "$HERMES_DIR" \
--hash-file "$HERMES_HASH_FILE" \
--state-file "$HERMES_RESTART_SEAL_STATE" \
Expand All @@ -1814,7 +1814,7 @@ seal_hermes_restart_inputs() {
# gateway.
original_failure_code="$HERMES_RESTART_FAILURE_CODE"
if owner_output="$(
"${_HERMES_GUARD_TIMEOUT[@]}" "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" inspect-mutation-owner \
${_HERMES_GUARD_TIMEOUT[@]+"${_HERMES_GUARD_TIMEOUT[@]}"} "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" inspect-mutation-owner \
--hermes-dir "$HERMES_DIR" \
--state-file "$HERMES_RESTART_SEAL_STATE" \
--lock-token "$GATEWAY_CONTROL_NONCE" 2>&1
Expand Down Expand Up @@ -1857,7 +1857,7 @@ unseal_hermes_restart_inputs() {
HERMES_RESTART_UNSEALING=1
trap 'HERMES_RESTART_SIGNAL_PENDING=1' SIGTERM SIGINT HUP
if ! output="$(
"${_HERMES_GUARD_TIMEOUT[@]}" "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" unseal-restart \
${_HERMES_GUARD_TIMEOUT[@]+"${_HERMES_GUARD_TIMEOUT[@]}"} "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" unseal-restart \
--hermes-dir "$HERMES_DIR" \
--state-file "$HERMES_RESTART_SEAL_STATE" 2>&1
)"; then
Expand Down Expand Up @@ -1991,7 +1991,7 @@ recover_startup_hermes_mutation() {

while [ -e "$HERMES_CONFIG_MUTATION_LOCK" ] || [ -e "$HERMES_RESTART_SEAL_STATE" ]; do
if ! owner_output="$(
"${_HERMES_GUARD_TIMEOUT[@]}" "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" inspect-mutation-owner \
${_HERMES_GUARD_TIMEOUT[@]+"${_HERMES_GUARD_TIMEOUT[@]}"} "$_HERMES_PYTHON" -I "$_HERMES_RUNTIME_CONFIG_GUARD" inspect-mutation-owner \
--hermes-dir "$HERMES_DIR" \
--state-file "$HERMES_RESTART_SEAL_STATE" 2>&1
)"; then
Expand Down Expand Up @@ -2475,13 +2475,13 @@ hermes_managed_controller_is_live() {
first_start="$(gateway_control_pid_start_identity "$pid")" || return 1
first_state="$(gateway_control_pid_state "$pid")" || return 1
first_uids="$(awk '/^Uid:/ { print $2 ":" $3 ":" $4 ":" $5; exit }' "${proc_root}/${pid}/status")" || return 1
mapfile -d '' -t first_argv <"${proc_root}/${pid}/cmdline" || return 1
while IFS= read -r -d "" elem; do first_argv+=("$elem"); done <"${proc_root}/${pid}/cmdline" || return 1
hermes_managed_controller_argv_is_expected "${first_argv[@]}" || return 1

second_start="$(gateway_control_pid_start_identity "$pid")" || return 1
second_state="$(gateway_control_pid_state "$pid")" || return 1
second_uids="$(awk '/^Uid:/ { print $2 ":" $3 ":" $4 ":" $5; exit }' "${proc_root}/${pid}/status")" || return 1
mapfile -d '' -t second_argv <"${proc_root}/${pid}/cmdline" || return 1
while IFS= read -r -d "" elem; do second_argv+=("$elem"); done <"${proc_root}/${pid}/cmdline" || return 1
hermes_managed_controller_argv_is_expected "${second_argv[@]}" || return 1

[ "$first_start" = "$expected_start_identity" ] \
Expand All @@ -2499,7 +2499,6 @@ hermes_managed_gateway_exit_was_host_authorized() {
local marker dir_metadata marker_metadata
local version marker_pid marker_start_identity controller_pid controller_start_identity extra
local trailing=""
local marker_fd

case "$pid" in
'' | 0 | 1 | *[!0-9]*) return 1 ;;
Expand All @@ -2518,18 +2517,17 @@ hermes_managed_gateway_exit_was_host_authorized() {
marker_metadata="$(stat -c '%u:%g %a %h' "$marker" 2>/dev/null || true)"
[ "$marker_metadata" = "0:0 444 1" ] || return 1

exec {marker_fd}<"$marker" || return 1
if ! IFS=' ' read -r \
version marker_pid marker_start_identity controller_pid controller_start_identity extra \
<&"$marker_fd"; then
exec {marker_fd}<&-
return 1
fi
if IFS= read -r trailing <&"$marker_fd" || [ -n "$trailing" ]; then
exec {marker_fd}<&-
return 1
fi
exec {marker_fd}<&-
# bash 4.1+ named FDs ({var}<file) are not available on bash 3.2 (macOS).
# Use a grouped redirect instead — variables assigned inside {} remain in scope.
{
if ! IFS=' ' read -r \
version marker_pid marker_start_identity controller_pid controller_start_identity extra; then
return 1
fi
if IFS= read -r trailing || [ -n "$trailing" ]; then
return 1
fi
} <"$marker" || return 1

[ "$version" = "v1" ] \
&& [ "$marker_pid" = "$pid" ] \
Expand Down
3 changes: 3 additions & 0 deletions scripts/gateway-control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ set -eu
# it must not inherit command resolution from the container environment. Use a
# fixed interpreter and trusted system PATH before invoking any external tool.
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Byte-exact character class matching — macOS UTF-8 locale makes [a-f] case-
# insensitive, which would allow uppercase hex nonces to pass the [!0-9a-f] check.
export LC_ALL=C

INSTALLED_CONTROL_HELPER="/usr/local/bin/nemoclaw-gateway-control"
if [ "$0" = "$INSTALLED_CONTROL_HELPER" ]; then
Expand Down
3 changes: 3 additions & 0 deletions scripts/lib/gateway-supervisor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# The request directory is root-only. Requests are written by the host through
# the registry-scoped privileged Docker exec path; sandbox processes cannot
# submit or alter them.
# Byte-exact character class matching — macOS UTF-8 locale makes [a-f] case-
# insensitive, which would allow uppercase hex nonces to bypass the nonce check.
export LC_ALL=C

NEMOCLAW_GATEWAY_CONTROL_DIR="${NEMOCLAW_GATEWAY_CONTROL_DIR:-/run/nemoclaw/gateway-control}"
NEMOCLAW_GATEWAY_CONTROL_REQUEST="${NEMOCLAW_GATEWAY_CONTROL_DIR}/request"
Expand Down
230 changes: 230 additions & 0 deletions src/lib/onboard/inference-providers/hermes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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

import { setupHermesProviderInference } from "./hermes";

function makeDeps(overrides: Record<string, unknown> = {}) {
return {
runOpenshell: vi.fn(() => ({ status: 0, stdout: "", stderr: "" })),
upsertProvider: vi.fn(),
verifyInferenceRoute: vi.fn(),
verifyOnboardInferenceSmoke: vi.fn(),
isNonInteractive: vi.fn(() => false),
registry: { updateSandbox: vi.fn() },
hermesProviderAuth: {
isHermesProviderRegistered: vi.fn(() => true),
ensureHermesProviderApiKeyCredentials: vi.fn(() => ({})),
ensureHermesProviderOAuthCredentials: vi.fn(() => ({})),
},
getHermesToolGatewayBroker: vi.fn(() => ({
getHermesToolGatewayProviderName: vi.fn(() => "hermes-tool-gateway"),
})),
providerExistsInGateway: vi.fn(() => true),
normalizeHermesAuthMethod: vi.fn(() => "api-key"),
resolveHermesNousApiKey: vi.fn(() => null),
checkHermesProviderStoreReachable: vi.fn(() => ({ ok: true })),
hermesAuthMethodLabel: vi.fn((m: string) => m),
hermesConstants: {
HERMES_NOUS_API_KEY_CREDENTIAL_ENV: "NOUS_API_KEY",
HERMES_AUTH_METHOD_API_KEY: "api-key",
HERMES_AUTH_METHOD_OAUTH: "oauth",
},
requireValue: vi.fn((v: unknown, _msg: string) => v),
redact: vi.fn((s: string) => s),
compactText: vi.fn((s: string) => s),
...overrides,
};
}

describe("setupHermesProviderInference SSRF guard (#6072)", () => {
it("rejects loopback address", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "http://127.0.0.1:8080/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/private or internal/);
});

it("rejects cloud metadata endpoint", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "http://169.254.169.254/latest/meta-data/",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/private or internal/);
});

it("rejects private RFC-1918 range", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "http://10.0.0.1/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/private or internal/);
});

it("rejects localhost hostname", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "http://localhost:11434/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/private or internal/);
});

it("rejects .internal TLD", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "http://my-service.internal/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/private or internal/);
});

it("throws on malformed URL without leaking the raw value", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "not-a-url",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/valid URL/);
Comment on lines +127 to +141

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Assert the “no raw value leak” claim directly.

The test name says not-a-url must not leak, but Line 141 would still pass if the thrown message included the raw endpoint. Capture the error message and assert both the expected text and absence of the input value.

Suggested test tightening
   it("throws on malformed URL without leaking the raw value", async () => {
-    await expect(
-      setupHermesProviderInference(
+    let thrown: unknown;
+    try {
+      await setupHermesProviderInference(
         {
           sandboxName: "alpha",
           model: "m",
           provider: "p",
@@
           hermesToolGateways: [],
         },
         makeDeps() as never,
-      ),
-    ).rejects.toThrow(/valid URL/);
+      );
+    } catch (err) {
+      thrown = err;
+    }
+    expect(thrown).toBeInstanceOf(Error);
+    expect((thrown as Error).message).toMatch(/valid URL/);
+    expect((thrown as Error).message).not.toContain("not-a-url");
   });

As per path instructions, “Prefer observable outcomes through the public boundary over source-text, private-shape, or mock-call assertions.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("throws on malformed URL without leaking the raw value", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "not-a-url",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/valid URL/);
it("throws on malformed URL without leaking the raw value", async () => {
let thrown: unknown;
try {
await setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "not-a-url",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
);
} catch (err) {
thrown = err;
}
expect(thrown).toBeInstanceOf(Error);
expect((thrown as Error).message).toMatch(/valid URL/);
expect((thrown as Error).message).not.toContain("not-a-url");
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/onboard/inference-providers/hermes.test.ts` around lines 127 - 141,
The malformed URL test in setupHermesProviderInference only checks for the
expected “valid URL” text and can still pass if the raw endpointUrl leaks in the
error message. Update the hermes.test.ts case for setupHermesProviderInference
to capture the thrown error message and assert both that it matches the expected
validation text and that it does not contain the input value “not-a-url”. Keep
the assertion at the public boundary by inspecting the rejected error message
rather than internals.

Source: Path instructions

});

it("rejects unsupported scheme", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "ftp://example.com/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/unsupported scheme/);
});

it("rejects URL with embedded credentials", async () => {
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "https://user:secret@example.com/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
makeDeps() as never,
),
).rejects.toThrow(/credentials/);
});

it("does not call runOpenshell when endpoint is rejected", async () => {
const deps = makeDeps();
await expect(
setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "ftp://example.com/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
deps as never,
),
).rejects.toThrow();
expect(deps.runOpenshell).not.toHaveBeenCalled();
});

it("accepts a public HTTPS endpoint", async () => {
const deps = makeDeps();
await setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: "https://integrate.api.nvidia.com/v1",
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
deps as never,
);
expect(deps.runOpenshell).toHaveBeenCalled();
});

it("skips SSRF check when endpointUrl is null", async () => {
const deps = makeDeps();
await setupHermesProviderInference(
{
sandboxName: "alpha",
model: "m",
provider: "p",
endpointUrl: null,
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
},
deps as never,
);
expect(deps.runOpenshell).toHaveBeenCalled();
});
});
24 changes: 24 additions & 0 deletions src/lib/onboard/inference-providers/hermes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Extracted verbatim from onboard.setupInference (#767).

import type { HermesAuthMethod } from "../hermes-auth";
import { isPrivateHostname } from "../../private-networks";
import type { HermesDeps, SetupInferenceResult } from "./types";

export async function setupHermesProviderInference(
Expand All @@ -28,6 +29,29 @@ export async function setupHermesProviderInference(
hermesAuthMethod,
hermesToolGateways,
} = args;
if (endpointUrl) {
let parsedEndpoint: URL;
try {
parsedEndpoint = new URL(endpointUrl);
} catch {
throw new Error(`Inference endpoint URL is not a valid URL.`);
}
if (parsedEndpoint.protocol !== "http:" && parsedEndpoint.protocol !== "https:") {
throw new Error(
`Inference endpoint URL uses an unsupported scheme. Only http and https are allowed.`,
);
}
if (parsedEndpoint.username || parsedEndpoint.password) {
throw new Error(
`Inference endpoint URL must not contain credentials. Remove the username and password from the URL.`,
);
}
if (isPrivateHostname(parsedEndpoint.hostname)) {
throw new Error(
`Inference endpoint URL points to a private or internal address "${parsedEndpoint.hostname}". Use a public endpoint.`,
);
Comment on lines +49 to +52

Copy link
Copy Markdown
Contributor

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect the downstream baseUrl consumers and private-network helpers to place
# resolved-address validation at the actual network boundary.
rg -n -C4 '\bbaseUrl\b|ensureHermesProvider(ApiKey|OAuth)Credentials|isPrivateHostname|isPrivateIp' src agents

Repository: NVIDIA/NemoClaw

Length of output: 50372


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## hermes.ts\n'
sed -n '1,180p' src/lib/onboard/inference-providers/hermes.ts

printf '\n## hermes-provider-auth.ts\n'
sed -n '1,260p' src/lib/hermes-provider-auth.ts

printf '\n## private-networks.ts\n'
sed -n '1,240p' src/lib/private-networks.ts

printf '\n## sandbox/config.ts relevant section\n'
sed -n '620,710p' src/lib/sandbox/config.ts

printf '\n## look for DNS resolution / endpoint validation call sites\n'
rg -n -C3 'validateEndpointUrl|lookup|resolve.*hostname|dns\.|isPrivateHostname|isPrivateIp|baseUrl: endpointUrl|endpointUrl' src/lib/onboard src/lib/sandbox src/lib/hermes-provider-auth.ts

Repository: NVIDIA/NemoClaw

Length of output: 50372


Block DNS-rebinding on Hermes endpoints. isPrivateHostname() only rejects literal private/internal names here. endpointUrl is forwarded unchanged into ensureHermesProvider*Credentials(...) and persisted as baseUrl, so a public hostname that resolves to private space can still slip through. Reuse the DNS-pinning/isPrivateIp() check from src/lib/sandbox/config.ts before storing the URL.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/onboard/inference-providers/hermes.ts` around lines 49 - 52, The
Hermes endpoint validation in ensureHermesProvider*Credentials() only checks
isPrivateHostname() on parsedEndpoint.hostname, so a public hostname that later
resolves to private space can still be accepted. Add the same DNS-pinning or
isPrivateIp() resolution check used in src/lib/sandbox/config.ts before
persisting endpointUrl as baseUrl, and keep the existing private-hostname
rejection in Hermes as a first-pass guard.

}
}
const {
runOpenshell,
upsertProvider: _upsertProvider, // intentionally unused; matches inline branch
Expand Down
Loading
Loading