fix: address critical security and code review findings in Phase 3
- Wire ImportOrchestrator into review_api start_import via BackgroundTasks - Sanitize docstrings in generated tool code to prevent code injection - Add Literal["read", "write"] validation for access_type - Add regex validation for agent_group - Validate URL scheme (http/https only) in ImportRequest - Validate LLM output fields (clamp confidence, validate access_type) - Use dataclasses.replace instead of manual reconstruction in importer - Expand SSRF blocked networks (Carrier-Grade NAT, IPv4-mapped IPv6, etc.) - Make _BLOCKED_NETWORKS immutable tuple - Use yaml.safe_dump instead of yaml.dump - Fix _to_snake_case for empty strings and Python keywords
This commit is contained in:
@@ -81,6 +81,11 @@ class TestImportEndpoint:
|
||||
response = client.post("/api/openapi/import", json={})
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_post_import_invalid_scheme_returns_422(self, client) -> None:
|
||||
"""POST /import with non-http URL returns 422."""
|
||||
response = client.post("/api/openapi/import", json={"url": "ftp://evil.com/spec"})
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_post_import_returns_pending_status(self, client) -> None:
|
||||
"""Newly created job has pending status."""
|
||||
response = client.post("/api/openapi/import", json={"url": _SAMPLE_URL})
|
||||
@@ -165,6 +170,22 @@ class TestUpdateClassificationEndpoint:
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_update_invalid_access_type_returns_422(self, client, job_with_classifications) -> None:
|
||||
"""PUT /classifications/0 with invalid access_type returns 422."""
|
||||
response = client.put(
|
||||
f"/api/openapi/jobs/{job_with_classifications}/classifications/0",
|
||||
json={"access_type": "admin", "needs_interrupt": True, "agent_group": "x"},
|
||||
)
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_update_invalid_agent_group_returns_422(self, client, job_with_classifications) -> None:
|
||||
"""PUT /classifications/0 with invalid agent_group returns 422."""
|
||||
response = client.put(
|
||||
f"/api/openapi/jobs/{job_with_classifications}/classifications/0",
|
||||
json={"access_type": "read", "needs_interrupt": False, "agent_group": "evil group!"},
|
||||
)
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_update_out_of_range_index_returns_404(self, client, job_with_classifications) -> None:
|
||||
"""PUT /classifications/999 returns 404 for out-of-range index."""
|
||||
response = client.put(
|
||||
|
||||
Reference in New Issue
Block a user