Skip to content

Commit 9593f25

Browse files
authored
fix(public-safety): reject unlabeled OpenAI and Anthropic keys (#7814)
1 parent 2ee0d48 commit 9593f25

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎loopx/contract.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ def _prefilter_fold(text: str) -> str:
143143
"sk_test_",
144144
"rk_live_",
145145
"rk_test_",
146+
"sk-proj-",
147+
"sk-svcacct-",
148+
"sk-admin-",
149+
"sk-ant-",
146150
"npm_",
147151
"pypi-",
148152
"eyj",

‎loopx/public_safe_text.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@
301301
r"\bxox[baprs]-[a-z0-9-]{10,}|"
302302
r"\baiza[a-z0-9_-]{20,}|"
303303
r"\b(?:sk|rk)_(?:live|test)_[a-z0-9]{12,}|"
304+
r"\bsk-(?:proj|svcacct|admin)-[a-z0-9_-]{20,}|"
305+
r"\bsk-ant-[a-z0-9_-]{20,}|"
304306
r"\bnpm_[a-z0-9]{20,}|"
305307
r"\bpypi-[a-z0-9_-]{20,}|"
306308
r"\beyj[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\b"

‎tests/control_plane/test_presentation_public_safety.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def test_colon_prefixed_unix_paths_keep_the_existing_boundary() -> None:
8989
"sk_live_51H8" + "aBcDeFgHiJkL",
9090
"npm_" + "a1B2c3D4e5F6g7H8i9J0",
9191
"pypi-AgEIcHlwaS5vcmc" + "AAAAAAAAAA",
92+
"sk-proj-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
93+
"sk-svcacct-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
94+
"sk-admin-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
95+
"sk-ant-api03-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
9296
"eyJhbGciOiJIUzI1NiJ9" + ".eyJzdWIiOiIxMjM0NTY3ODkwIn0" + ".SflKxwRJSMeKKF2QT4f",
9397
],
9498
)
@@ -109,9 +113,13 @@ def test_unlabeled_provider_tokens_fail_the_boundary_scan(token: str) -> None:
109113
"AWS key ids start AKIA and ASIA, then sixteen more characters",
110114
"pypi- prefix alone is not a token",
111115
"sk-proj-abcdefghijklmnop is an OpenAI project key shape",
116+
"sk-svcacct-abcdefghijklmnop is a short example",
117+
"sk-admin-abcdefghijklmnop is a short example",
118+
"sk-ant-abcdefghijklmnop is a short example",
119+
"sk-custom-" + "abcdefghijklmnopqrstuvwx",
112120
],
113121
)
114-
def test_ordinary_prose_and_unclaimed_shapes_stay_public(text: str) -> None:
122+
def test_ordinary_prose_and_short_provider_lookalikes_stay_public(text: str) -> None:
115123
assert public_safety.scan_public_boundary_text(text) == {
116124
"ok": True,
117125
"warnings": [],

‎tests/test_contract_credential_pattern_precision.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ def test_private_lark_tenant_urls_remain_blocked(tmp_path: Path, line: str) -> N
140140
# second list here: this rule gates repository publication, and a list that
141141
# recognized only some issuers certified the rest as public-safe.
142142
PROVIDER_TOKEN_SAMPLES = [
143+
"sk-proj-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
144+
"sk-svcacct-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
145+
"sk-admin-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
146+
"sk-ant-api03-" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0",
143147
"ghp_" + "16C7e42F292c6912E7710c838347Ae178B4a",
144148
"github_pat_" + "11ABCDEFG0123456789_abcdefghijklmnopqrstuvwxyz0123456789",
145149
"xoxb-" + "123456789012-abcdefghijkl",
@@ -182,6 +186,10 @@ def test_a_short_provider_lookalike_stays_clean(tmp_path: Path) -> None:
182186
PROVIDER_TOKENS_WITH_PLACEHOLDER_BODY = [
183187
"ghp_" + "dummy" + "1234567890abcdefghijklmnop",
184188
"npm_" + "example" + "1234567890abcdefghij",
189+
"sk-proj-" + "example" + "1234567890abcdefghij",
190+
"sk-svcacct-" + "example" + "1234567890abcdefghij",
191+
"sk-admin-" + "example" + "1234567890abcdefghij",
192+
"sk-ant-api03-" + "example" + "1234567890abcdefghij",
185193
]
186194

187195

‎tests/test_static_site_presentation.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ def test_package_requires_visual_and_link_validation_receipts(
211211
_package(site, tmp_path / "publish", tmp_path / "state", **{field: value})
212212

213213

214+
@pytest.mark.parametrize("prefix", ["sk-proj-", "sk-svcacct-", "sk-admin-", "sk-ant-api03-"])
215+
def test_package_rejects_unlabeled_ai_provider_tokens(tmp_path: Path, prefix: str) -> None:
216+
site = _site(tmp_path)
217+
token = prefix + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0"
218+
(site / "notes.txt").write_text(f"provider output: {token}\n", encoding="utf-8")
219+
destination = tmp_path / "publish"
220+
221+
with pytest.raises(StaticSiteContractError, match="public boundary scan failed"):
222+
_package(site, destination, tmp_path / "state")
223+
assert not destination.exists()
224+
225+
214226
def test_package_rejects_reserved_paths_symlinks_and_public_boundary_leaks(
215227
tmp_path: Path,
216228
) -> None:

0 commit comments

Comments
 (0)