mirror of
https://github.com/JuliusBrussee/caveman.git
synced 2026-08-11 13:21:09 +02:00
fix(#528): benchmarks/run.py reads only ANTHROPIC_API_KEY from .env.local
The old loader setdefault'ed EVERY key found in repo-root .env.local into os.environ. Security scanners (Hermes skill scan, issue #528) flag that as a high-severity exfiltration surface: install caveman into a profile with secrets in .env.local and the benchmark quietly pulls all of them into its process environment. The benchmark only ever needs ANTHROPIC_API_KEY (anthropic.Anthropic() reads it implicitly), so read that one key and nothing else — skip the file entirely when the var is already set. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kmm2umRGb5nLxdimrwweZ
This commit is contained in:
co-authored by
Claude Fable 5
parent
19f7b5a0c0
commit
bceaa0cf6d
+14
-5
@@ -13,14 +13,23 @@ from pathlib import Path
|
||||
|
||||
import anthropic
|
||||
|
||||
# Load .env.local from repo root if it exists
|
||||
# The only env var this benchmark needs: the anthropic SDK reads it in
|
||||
# anthropic.Anthropic(). Read it — and ONLY it — from repo-root .env.local.
|
||||
# Deliberately narrow (issue #528): the old loader setdefault'ed EVERY key in
|
||||
# .env.local into os.environ, which security scanners rightly flag as an
|
||||
# exfiltration surface. Nothing else from the file is ever read or exported.
|
||||
_API_KEY_VAR = "ANTHROPIC_API_KEY"
|
||||
|
||||
_env_file = Path(__file__).parent.parent / ".env.local"
|
||||
if _env_file.exists():
|
||||
if _API_KEY_VAR not in os.environ and _env_file.exists():
|
||||
for line in _env_file.read_text().splitlines():
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#") and "=" in line:
|
||||
key, _, value = line.partition("=")
|
||||
os.environ.setdefault(key.strip(), value.strip())
|
||||
if line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, _, value = line.partition("=")
|
||||
if key.strip() == _API_KEY_VAR:
|
||||
os.environ.setdefault(_API_KEY_VAR, value.strip())
|
||||
break
|
||||
|
||||
SCRIPT_VERSION = "1.0.0"
|
||||
SCRIPT_DIR = Path(__file__).parent
|
||||
|
||||
Reference in New Issue
Block a user