From bceaa0cf6d32f5f1b5eeefbbe0447b04db0eebef Mon Sep 17 00:00:00 2001 From: Julius Brussee <104168679+JuliusBrussee@users.noreply.github.com> Date: Thu, 2 Jul 2026 15:14:12 +0200 Subject: [PATCH] fix(#528): benchmarks/run.py reads only ANTHROPIC_API_KEY from .env.local MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_011kmm2umRGb5nLxdimrwweZ --- benchmarks/run.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/benchmarks/run.py b/benchmarks/run.py index 0e2951f..3a2c2c8 100644 --- a/benchmarks/run.py +++ b/benchmarks/run.py @@ -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