Skip to content

Commit fb28d1b

Browse files
fix: withhold every Claude setting from build checks, not a fixed list
build_env() removed the ANTHROPIC_* and CLAUDE_CODE_* names on the default allowlist, but one added through fix_agent.extra_env — ANTHROPIC_CUSTOM_HEADERS, which can carry auth — still reached the build. Match by prefix instead. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 2cb9ccb commit fb28d1b

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎plugins/security-engineer/skills/run/agent_env.py‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
})
5151

5252
# Allowed for the model subprocess, which needs them to reach Claude; withheld
53-
# from build checks, which run repository code and need none of them.
54-
_MODEL_ONLY = frozenset(n for n in _ALLOW
55-
if n.startswith(("ANTHROPIC_", "CLAUDE_CODE_")))
53+
# from build checks, which run repository code and need none of them. A prefix,
54+
# so one added through extra_env is withheld too.
55+
_MODEL_ONLY_PREFIXES = ("ANTHROPIC_", "CLAUDE_CODE_")
5656

5757
# Names fix_agent.extra_env may never add back. The literal four are the ones
5858
# this change exists to withhold; the pattern catches the shape of the rest, so
@@ -92,7 +92,5 @@ def build_env(extra: list | None = None) -> dict:
9292
agent_env() without Claude's credentials. fix_agent.extra_env still applies,
9393
so a private registry an operator opted into reaches the build that needs it.
9494
"""
95-
env = agent_env(extra)
96-
for name in _MODEL_ONLY:
97-
env.pop(name, None)
98-
return env
95+
return {k: v for k, v in agent_env(extra).items()
96+
if not k.startswith(_MODEL_ONLY_PREFIXES)}

‎plugins/security-engineer/skills/run/tests/test_untrusted.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import orchestrator
2424
import package_identity
2525
import validator
26-
from agent_env import agent_env
26+
from agent_env import agent_env, build_env
2727
from orchestrator import AlertTask, _build_prompt_context, _invoke_fix_agent
2828
from pipelines import get_pipeline
2929
from pipelines.base import FixPlan
@@ -385,6 +385,12 @@ def test_build_check_keeps_path_and_extra_env(self):
385385
self.assertIn("PATH", seen)
386386
self.assertIn("AWS_REGION", seen)
387387

388+
def test_extra_env_cannot_hand_a_build_claude_settings(self):
389+
"""ANTHROPIC_CUSTOM_HEADERS can carry auth; opting it in is for the model."""
390+
with patch.dict(os.environ, {"ANTHROPIC_CUSTOM_HEADERS": "x"}):
391+
self.assertNotIn("ANTHROPIC_CUSTOM_HEADERS",
392+
build_env(["ANTHROPIC_CUSTOM_HEADERS"]))
393+
388394
def test_python_syntax_check_does_not_import_from_the_tree(self):
389395
"""`python3 -m py_compile` puts cwd first on sys.path, so a committed
390396
py_compile.py ran instead of the stdlib one, with the full environment."""

0 commit comments

Comments
 (0)