Skip to content

Commit 1504625

Browse files
committed
fix(evaluation): 阻止扩展配置泄露凭据
1 parent a597237 commit 1504625

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

examples/optimization/eval_optimize_loop/artifact_writer.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,25 @@
3535
]
3636

3737
_INPUT_COPY_DISABLED = "artifacts.copy_input_files=false"
38-
_SENSITIVE_CONFIG_KEYS = {"apikey", "authorization", "baseurl"}
38+
_SENSITIVE_CONFIG_KEYS = {
39+
"accesstoken",
40+
"apikey",
41+
"auth",
42+
"authorization",
43+
"authtoken",
44+
"baseurl",
45+
"bearertoken",
46+
"clientsecret",
47+
"credential",
48+
"credentials",
49+
"password",
50+
"passwd",
51+
"privatekey",
52+
"secret",
53+
"secretkey",
54+
"token",
55+
"xapikey",
56+
}
3957
_APPROVED_SENSITIVE_VALUES = {
4058
"",
4159
"${TRPC_AGENT_API_KEY}",

tests/evaluation/test_eval_optimize_loop_stage5_artifacts.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,21 @@ async def test_publish_rejects_input_hash_drift(tmp_path):
161161
assert list(run_dir.glob(".report.tmp-*")) == []
162162

163163

164+
@pytest.mark.parametrize(
165+
"sensitive_key",
166+
["api_key", "access_token", "client_secret", "password", "x-api-key"],
167+
)
164168
@pytest.mark.asyncio
165169
async def test_publish_rejects_plaintext_secret_in_optimizer_config_without_leaking_it(
166-
tmp_path,
170+
tmp_path, sensitive_key
167171
):
168172
root = _copy_example(tmp_path)
169173
optimizer_path = root / "optimizer.json"
170174
payload = json.loads(optimizer_path.read_text(encoding="utf-8"))
171175
secret = "sk-real-sentinel-secret-must-not-be-copied"
172-
payload["optimize"]["algorithm"]["reflection_lm"]["api_key"] = secret
176+
payload["optimize"]["algorithm"]["reflection_lm"]["extra_fields"] = {
177+
sensitive_key: secret
178+
}
173179
optimizer_path.write_text(
174180
json.dumps(payload, ensure_ascii=False, indent=2) + "\n",
175181
encoding="utf-8",

0 commit comments

Comments
 (0)