compute guard: line-scoped allow entries; allow MindKeychain.jsx's two OAuth endpoints only
Allow entries may carry matches: (regexes); then only matching lines are allowed, so an allowed file can't smuggle in a new call. windy-pro #609 MindKeychain.jsx: openrouter.ai/auth? and /api/v1/auth/keys (BYOK key acquisition via OAuth PKCE, no inference; successor of the MindPanel allow, ADR-064). An inference call in the same file still flags (tested). Orchestrator-approved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -191,3 +191,32 @@ def test_a_commit_not_fetched_yet_is_skipped_not_an_error(tmp_path, monkeypatch)
|
||||
(tmp_path / "windy-chat.git").symlink_to(bare)
|
||||
assert cg.check("windy-chat", "f" * 40, "main", True) is None # pushed after the fetch
|
||||
assert [f.kind for f in cg.check("windy-chat", sha, "main", True)] == ["provider SDK"]
|
||||
|
||||
|
||||
KEYCHAIN = "src/client/web/src/pages/panels/MindKeychain.jsx"
|
||||
|
||||
|
||||
def test_scoped_allow_admits_only_the_oauth_endpoints():
|
||||
ok = [
|
||||
" window.location.href = `https://openrouter.ai/auth?callback_url=${encodeURIComponent(callback)}`",
|
||||
" const res = await fetch('https://openrouter.ai/api/v1/auth/keys', {",
|
||||
]
|
||||
for line in ok:
|
||||
assert cg.allowed("windy-pro", KEYCHAIN, ALLOW, line)
|
||||
# an inference call smuggled into the same file still flags
|
||||
assert not cg.allowed("windy-pro", KEYCHAIN, ALLOW,
|
||||
" await fetch('https://openrouter.ai/api/v1/chat/completions', {")
|
||||
# a scoped entry never allows a line it can't see
|
||||
assert not cg.allowed("windy-pro", KEYCHAIN, ALLOW)
|
||||
|
||||
|
||||
def test_scoped_allow_in_a_real_diff():
|
||||
diff = f"""--- /dev/null
|
||||
+++ b/{KEYCHAIN}
|
||||
@@ -0,0 +1,3 @@
|
||||
+ window.location.href = `https://openrouter.ai/auth?callback_url=x`
|
||||
+ const res = await fetch('https://openrouter.ai/api/v1/auth/keys', {{
|
||||
+ await fetch('https://openrouter.ai/api/v1/chat/completions', {{
|
||||
"""
|
||||
fs = cg.parse_added("windy-pro", diff, ALLOW)
|
||||
assert [(f.line, f.match) for f in fs] == [(3, "openrouter.ai")]
|
||||
|
||||
Reference in New Issue
Block a user