Repository navigation
fix(ci): resolve macOS/bash 3.2 vitest failures on main #6137
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
Changes from all commits
17c3c0e
fa8448d
1ae6d21
b2efd05
3f85340
5d9cfaa
bc34519
9c0f45c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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/); | ||
| }); | ||
|
|
||
| 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(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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( | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 agentsRepository: 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.tsRepository: NVIDIA/NemoClaw Length of output: 50372 Block DNS-rebinding on Hermes endpoints. 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| const { | ||
| runOpenshell, | ||
| upsertProvider: _upsertProvider, // intentionally unused; matches inline branch | ||
|
|
||
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 | 🟡 Minor | ⚡ Quick win
Assert the “no raw value leak” claim directly.
The test name says
not-a-urlmust 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
🤖 Prompt for AI Agents
Source: Path instructions