Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(api): reject newline path parameters

Haozhe Wub9a82655bd77
diff --git a/agent/api_server.py b/agent/api_server.py
index 914bbe2c4..11a99a9b7 100644
--- a/agent/api_server.py
+++ b/agent/api_server.py
@@ -890,7 +890,7 @@ def _validate_path_param(value: str, kind: str) -> None:
HTTPException: 400 when ``value`` does not match the safe character
class, mirroring the existing ``_SHADOW_ID_RE`` check.
"""
- if not _SAFE_PATH_PARAM_RE.match(value or ""):
+ if not _SAFE_PATH_PARAM_RE.fullmatch(value or ""):
raise HTTPException(status_code=400, detail=f"invalid {kind}")
diff --git a/agent/tests/test_security_auth_api.py b/agent/tests/test_security_auth_api.py
index 45229eb62..1bd633b6d 100644
--- a/agent/tests/test_security_auth_api.py
+++ b/agent/tests/test_security_auth_api.py
@@ -199,6 +199,9 @@ def test_validate_path_param_accepts_known_good_values(value: str) -> None:
"foo\\bar",
"foo bar",
"foo.bar", # dot is not in the safe class
+ "foo\n",
+ "foo\r",
+ "foo\t",
"foo\x00bar",
"A" * 129,
],
@@ -226,6 +229,13 @@ def test_get_run_pine_rejects_traversal_run_id() -> None:
assert response.json()["detail"] == "invalid run_id"
+def test_get_run_pine_rejects_url_encoded_newline_run_id() -> None:
+ response = _local_client().get("/runs/foo%0A/pine")
+
+ assert response.status_code == 400
+ assert response.json()["detail"] == "invalid run_id"
+
+
def test_get_run_result_rejects_traversal_run_id() -> None:
response = _local_client().get("/runs/foo.bar")