Skip to content
Merged
56 changes: 55 additions & 1 deletion agents/langchain-deepagents-code/dcode-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ run_dcode() {
# ends in a credential keyword (_KEY, _TOKEN, _SECRET, _PASSWORD,
# _PASSWD, _PASS, _CREDENTIAL) and the value is at least 10 chars (mirroring
# CONTEXT_PATTERNS minimum length).
# * OTLP endpoint variables (OTEL_EXPORTER_OTLP_ENDPOINT and its _TRACES_
# variant) carry a collector URL, not a credential, so the documented
# `--observability` flow can set one. is_safe_otlp_endpoint_url accepts
# ONLY a strict scheme://host[:port][/path] ASCII URL and refuses userinfo,
# query, fragment, percent-encoding, controls, non-ASCII, and oversized
# inputs (a value that cannot smuggle a credential in any field); the
# is_secret_shaped_value scan still runs first. The `_HEADERS` variants
# remain under the name-context refusal because they do carry auth material.
# * Managed messaging values (SLACK_BOT_TOKEN, SLACK_APP_TOKEN,
# TELEGRAM_BOT_TOKEN, DISCORD_BOT_TOKEN) are allowed only when the value
# matches the platform-specific token shape AND does not embed a
Expand Down Expand Up @@ -327,7 +335,7 @@ has_credential_name_context() {
LANGSMITH_RUNS_ENDPOINTS | LANGCHAIN_RUNS_ENDPOINTS)
return 0
;;
OTEL_EXPORTER_OTLP_ENDPOINT | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | OTEL_EXPORTER_OTLP_HEADERS | OTEL_EXPORTER_OTLP_TRACES_HEADERS)
OTEL_EXPORTER_OTLP_HEADERS | OTEL_EXPORTER_OTLP_TRACES_HEADERS)
return 0
;;
*_API_KEY | *_KEY | *_TOKEN | *_SECRET | *_PASSWORD | *_PASSWD | *_PASS | *_CREDENTIAL | *-API-KEY | *-KEY | *-TOKEN | *-SECRET | *-PASSWORD | *-PASSWD | *-PASS | *-CREDENTIAL)
Expand All @@ -351,6 +359,38 @@ is_allowed_openshell_runtime_value() {
[ "$name" = "OPENSHELL_TLS_KEY" ] && [ "$value" = "$OPENSHELL_TLS_KEY_PATH" ]
}

# OTLP endpoint variables carry the collector URL, not a credential. The
# documented `--observability` flow sets one (e.g.
# http://host.openshell.internal:4318), so a clean bare http(s) URL must be
# accepted rather than refused on length like a credential-named var. The
# `_HEADERS` variants (which do carry auth material) stay under the generic
# name-context refusal; only the `_ENDPOINT` variants get this URL allowance.
is_otlp_endpoint_name() {
case "$1" in
OTEL_EXPORTER_OTLP_ENDPOINT | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) return 0 ;;
esac
return 1
}

# Accept ONLY a single credential-free URL of the form scheme://host[:port][/path]
# built from a strict ASCII allowlist. This rejects userinfo (@), query (?),
# fragment (#), percent-encoding (%), C0 controls, DEL, non-ASCII bytes,
# backslashes, whitespace, and every other delimiter, so no encoded or
# structured field can smuggle a credential past the is_secret_shaped_value scan
# that runs first. The charset is identical to the managed Python runtime's
# _SAFE_OTLP_ENDPOINT_URL so the wrapper and runtime classify a value the same
# way (#6538 review: the prior predicate was fail-open on encoded/query cases and
# disagreed with Python on VT/FF).
is_safe_otlp_endpoint_url() {
local value="$1"
# Force byte-wise ASCII matching: under a UTF-8 locale `[[ =~ ]]` collation can
# fold non-ASCII bytes into [A-Za-z0-9] ranges, which would accept hosts the
# Python runtime (ASCII code-point matching) rejects. LC_ALL=C keeps parity.
local LC_ALL=C
[ "${#value}" -le 2048 ] || return 1
[[ "$value" =~ ^https?://[A-Za-z0-9.-]+(:[0-9]+)?(/[A-Za-z0-9._/-]*)?$ ]]
}

is_dynamic_dotenv_value() {
local value="$1"
case "$value" in
Expand Down Expand Up @@ -445,6 +485,14 @@ assert_no_secret_runtime_env() {
if is_secret_shaped_value "$value"; then
refuse_secret_env "runtime environment variable" "$name"
fi
if is_otlp_endpoint_name "$name"; then
# An empty value is treated as unset (matches the length check it
# replaces and the managed Python runtime), so only scan a set value.
if [ -n "$value" ] && ! is_safe_otlp_endpoint_url "$value"; then
refuse_secret_env "runtime environment variable" "$name"
fi
continue
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if has_credential_name_context "$name" && [ ${#value} -ge 10 ] && ! is_allowed_openshell_runtime_value "$name" "$value"; then
refuse_secret_env "runtime environment variable" "$name"
fi
Expand Down Expand Up @@ -508,6 +556,12 @@ assert_no_secret_env_file() {
if is_secret_shaped_value "$value"; then
refuse_secret_env "$env_file" "$key"
fi
if is_otlp_endpoint_name "$key"; then
if [ -n "$value" ] && ! is_safe_otlp_endpoint_url "$value"; then
refuse_secret_env "$env_file" "$key"
fi
continue
fi
if has_credential_name_context "$key" && [ ${#value} -ge 10 ]; then
refuse_secret_env "$env_file" "$key"
fi
Expand Down
43 changes: 41 additions & 2 deletions agents/langchain-deepagents-code/managed-dcode-runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,27 @@
_CREDENTIAL_ENV_NAMES = {
"LANGSMITH_RUNS_ENDPOINTS",
"LANGCHAIN_RUNS_ENDPOINTS",
"OTEL_EXPORTER_OTLP_ENDPOINT",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
"OTEL_EXPORTER_OTLP_HEADERS",
"OTEL_EXPORTER_OTLP_TRACES_HEADERS",
}
# OTLP endpoint variables carry the collector URL, not a credential. The
# documented `--observability` flow sets one (e.g.
# http://host.openshell.internal:4318), so a clean bare http(s) URL is allowed;
# a value with userinfo or a structured key-bearing blob is still refused. The
# `_HEADERS` variants stay in _CREDENTIAL_ENV_NAMES because they carry auth
# material. Mirrors dcode-wrapper.sh is_otlp_endpoint_name (#6466).
_OTLP_ENDPOINT_ENV_NAMES = {
"OTEL_EXPORTER_OTLP_ENDPOINT",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
}
# A credential-free OTLP collector URL: scheme://host[:port][/path] from a
# strict ASCII allowlist. No userinfo, query, fragment, percent-encoding,
# controls, non-ASCII, or backslashes can appear, so no encoded or structured
# field can smuggle a credential. The charset matches the Bash wrapper's
# is_safe_otlp_endpoint_url for cross-runtime parity (#6538 review).
_SAFE_OTLP_ENDPOINT_URL = re.compile(
r"https?://[A-Za-z0-9.-]+(?::[0-9]+)?(?:/[A-Za-z0-9._/-]*)?"
)
# Python's \s also includes control separators that ECMAScript excludes, so
# spell out the canonical whitespace set for cross-runtime parity.
_ECMASCRIPT_NON_WHITESPACE_SECRET_CHAR = (
Expand Down Expand Up @@ -232,6 +248,20 @@ def _is_managed_value(name: str, value: str) -> bool:
return False


def _is_safe_otlp_endpoint_url(value: str) -> bool:
"""Accept ONLY a strict scheme://host[:port][/path] ASCII URL.

Rejects userinfo, query, fragment, percent-encoding, C0 controls, DEL,
non-ASCII bytes, backslashes, whitespace, and oversized inputs, so no
encoded or structured field can smuggle a credential past the
_contains_secret_shape scan that runs first. The charset matches the Bash
wrapper's is_safe_otlp_endpoint_url for cross-runtime parity (#6538 review).
"""
if len(value) > 2048:
return False
return _SAFE_OTLP_ENDPOINT_URL.fullmatch(value) is not None


def _assert_safe_environment() -> None:
for name, value in os.environ.items():
if _OPENSHELL_ENV_PLACEHOLDER_PREFIX in value:
Expand All @@ -256,6 +286,15 @@ def _assert_safe_environment() -> None:
f"runtime environment variable {name} contains a credential; "
"use NemoClaw credential handling"
)
if (
name.upper() in _OTLP_ENDPOINT_ENV_NAMES
and value
and not _is_safe_otlp_endpoint_url(value)
):
raise RuntimeError(
f"runtime environment variable {name} contains a credential; "
"use NemoClaw credential handling"
)


def _assert_safe_auth_state() -> None:
Expand Down
47 changes: 46 additions & 1 deletion test/langchain-deepagents-code-direct-module-patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ check("disabled", False)
["SLACK_BOT_TOKEN", "xoxb-sk-abcdefghijklmnopqrstuv"],
["LANGSMITH_RUNS_ENDPOINTS", '{"https://trace.example":"opaque-key-value"}'],
["LANGCHAIN_RUNS_ENDPOINTS", '{"https://trace.example":"opaque-key-value"}'],
["OTEL_EXPORTER_OTLP_ENDPOINT", "https://collector.example/v1/traces"],
// A plain OTLP endpoint URL is allowed (#6466); credential-bearing forms
// (embedded userinfo, structured key blob) are still refused.
["OTEL_EXPORTER_OTLP_ENDPOINT", "http://token@collector.example:4318"],
["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", '{"https://trace.example":"opaque-key-value"}'],
["OTEL_EXPORTER_OTLP_HEADERS", "authorization=opaque-value"],
]) {
const result = spawnSync("python3", ["-m", "deepagents_code"], {
Expand All @@ -352,6 +355,48 @@ check("disabled", False)
}
});

it("allows plain OTLP endpoint URLs in the direct-module runtime (#6466)", () => {
const tempDir = createPackageFixture();
patchFixture(tempDir);
for (const name of ["OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"]) {
for (const value of [
"http://host.openshell.internal:4318",
"https://collector.example/v1/traces",
]) {
const result = spawnSync("python3", ["-m", "deepagents_code"], {
env: { PATH: process.env.PATH, PYTHONPATH: tempDir, [name]: value },
encoding: "utf8",
});
expect(result.status, `${name}=${value} was rejected: ${result.stderr}`).toBe(0);
expect(result.stdout).toContain("managed-posture-ok");
}
}
});

it("rejects fail-open OTLP endpoint values in the direct-module runtime (#6538)", () => {
const tempDir = createPackageFixture();
patchFixture(tempDir);
for (const name of ["OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"]) {
for (const value of [
"http://host:4318?x=sk%2Dabcdefghijklmnop",
"http://host:4318?apikey=opaquevalue12345",
"http://user%40host:4318",
"http://a;http://b@evil:4318",
"http://host:4318#fragment",
"http://héllo:4318",
"http://",
`http://host:4318/p${"a".repeat(3000)}`,
]) {
const result = spawnSync("python3", ["-m", "deepagents_code"], {
env: { PATH: process.env.PATH, PYTHONPATH: tempDir, [name]: value },
encoding: "utf8",
});
expect(result.status, `${name}=${value} was allowed`).not.toBe(0);
expect(result.stderr).toContain(`runtime environment variable ${name}`);
}
}
});

it("allows only scoped managed credential-shaped runtime values", () => {
const tempDir = createPackageFixture();
patchFixture(tempDir);
Expand Down
60 changes: 60 additions & 0 deletions test/langchain-deepagents-code-image-credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,66 @@ describe("LangChain Deep Agents Code image credential boundary", () => {
}
});

it("allows plain OTLP endpoint URLs but rejects credential-bearing endpoint values (#6466)", () => {
// Regression for #6466: a plain OTLP collector URL is not a credential and
// must pass the guard (the documented `--observability` flow sets one),
// while anything that is not a strict scheme://host[:port][/path] ASCII URL
// is refused. The #6538 review hardened this against fail-open cases:
// percent-encoded tokens, opaque query credentials, encoded/parser-
// differential userinfo, hostless URLs, and non-ASCII hosts.
const endpointNames = ["OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"];
const plainUrls = [
"http://host.openshell.internal:4318",
"http://host.openshell.internal:4318/v1/traces",
"https://collector.example.com:4318",
];
const credentialBearing = [
"http://token@example.com:4318",
"http://user:pass@host:4318",
'{"https://trace.example":"opaque-key-value"}',
"http://host:4318?x=sk%2Dabcdefghijklmnop",
"http://host:4318?apikey=opaquevalue12345",
"http://user%40host:4318",
"http://a;http://b@evil:4318",
"http://host:4318#fragment",
"http://héllo:4318",
"http://",
];

for (const name of endpointNames) {
for (const url of plainUrls) {
const runtimeDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-otlp-ok-"));
const runtimeFixture = makeWrapperFixture(runtimeDir);
const runtimeResult = runWrapper(runtimeFixture.wrapperPath, ["-n", "hi"], { [name]: url });
expect(runtimeResult.status, `${name}=${url}`).toBe(0);
expect(fs.existsSync(runtimeFixture.ranMarker)).toBe(true);

const dotenvDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-otlp-ok-dotenv-"));
const dotenvFixture = makeWrapperFixture(dotenvDir);
fs.writeFileSync(dotenvFixture.envFile, `${name}=${url}\n`, "utf8");
const dotenvResult = runWrapper(dotenvFixture.wrapperPath, ["-n", "hi"], {});
expect(dotenvResult.status, `${name}=${url} (dotenv)`).toBe(0);
expect(fs.existsSync(dotenvFixture.ranMarker)).toBe(true);
}

for (const value of credentialBearing) {
const rejectDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-otlp-bad-"));
const rejectFixture = makeWrapperFixture(rejectDir);
const result = runWrapper(rejectFixture.wrapperPath, ["-n", "hi"], { [name]: value });
expect(result.status, `${name}=${value}`).not.toBe(0);
expect(result.stderr).toContain(name);
expect(fs.existsSync(rejectFixture.ranMarker)).toBe(false);
}

// An empty value is treated as unset, not a credential.
const emptyDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-otlp-empty-"));
const emptyFixture = makeWrapperFixture(emptyDir);
const emptyResult = runWrapper(emptyFixture.wrapperPath, ["-n", "hi"], { [name]: "" });
expect(emptyResult.status, `${name}= (empty)`).toBe(0);
expect(fs.existsSync(emptyFixture.ranMarker)).toBe(true);
}
});

it("rejects mismatched, malformed, wrapped, and raw credential placeholders", () => {
const invalidCases = [
{ name: "MODEL_NAME", value: "openshell:resolve:env:OTHER_NAME" },
Expand Down
Loading