Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agentic_security/routes/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ async def verify(
info: LLMInfo, secrets: InMemorySecrets = Depends(get_in_memory_secrets)
) -> dict[str, int | str | float]:
logger.info("verify: checking LLM spec connectivity")
spec = LLMSpec.from_string(info.spec)
try:
spec = LLMSpec.from_string(info.spec)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it's incorrect error handling for this situation LLMSpec.from_string

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion, want to make sure I address the right thing. Looking again at from_string(): it already wraps any exception, bad input or an internal bug in parse_http_spec alike, into InvalidHTTPSpecError. Moving the call inside the try means that branch now returns a clean 400 with no logger call, where the generic except Exception branch below it does call logger.exception. So a genuine internal bug hiding inside parse_http_spec would now return a quiet 400 instead of the loud 500 it produced before, with no server-side trace either way.

Is that the concern, or did you have something else in mind, maybe the status code itself, or a different split between parse errors and verify() errors? Happy to add the missing log line if that is it, or take a different direction if I am off base.

r = await spec.verify()
except InvalidHTTPSpecError as e:
logger.warning("verify: invalid HTTP spec: %s", e)
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/routes/test_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from fastapi.testclient import TestClient

from agentic_security.app import app

client = TestClient(app)


def test_verify_relative_url_returns_400_not_500():
"""A relative-URL spec should fail parsing with a clean 400, not an
uncaught 500. See https://github.com/msoedov/agentic_security/issues/149.
"""
spec = "POST /chat HTTP/2\nHost: promptairlines.com\nContent-Type: application/json\n\n{}"
response = client.post("/verify", json={"spec": spec})
assert response.status_code == 400
assert "Failed to parse HTTP spec" in response.json()["detail"]