code review jr: store path traversal...

emit workflow_run_failed

again?
This commit is contained in:
lda
2026-06-03 04:04:24 +07:00 Verified
parent 688dcb69a9
commit 969a5704bb
8 changed files with 200 additions and 13 deletions
+41 -1
View File
@@ -1,6 +1,9 @@
from __future__ import annotations
from wf_mcp.models import AuthRecord
import pytest
from wf_mcp.connections import parse_connection_id
from wf_mcp.models import AuthRecord, CatalogSnapshot
from wf_mcp.storage import FileStore
from .test_support import local_temp_root
@@ -18,3 +21,40 @@ def test_file_store_round_trips_auth() -> None:
loaded = store.load_auth("demo.personal")
assert loaded == record
def test_parse_connection_id_rejects_path_traversal() -> None:
for connection_id in ("../personal", "demo/../../personal", ".hidden.personal"):
with pytest.raises(ValueError, match="connection id"):
parse_connection_id(connection_id)
def test_file_store_rejects_auth_connection_id_path_traversal(tmp_path) -> None:
store = FileStore(tmp_path / "store")
record = AuthRecord(
connection_id="../outside",
scheme="oauth",
payload={"token": "secret"},
)
with pytest.raises(ValueError, match="connection id"):
store.save_auth(record)
assert not (tmp_path / "outside.json").exists()
def test_file_store_rejects_catalog_connection_id_path_traversal(tmp_path) -> None:
store = FileStore(tmp_path / "store")
with pytest.raises(ValueError, match="connection id"):
store.load_catalog("../outside")
snapshot = CatalogSnapshot(
connection_id="../outside",
fetched_at_epoch_ms=0,
max_age_seconds=60,
)
with pytest.raises(ValueError, match="connection id"):
store.save_catalog(snapshot)
assert not (tmp_path / "outside.json").exists()