Repository navigation
fix: return 401 instead of 500 for an unauthenticated Azure DevOps webhook - #2703
Conversation
PR Summary by QodoFix Azure DevOps webhook unauthenticated requests to return 401
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
…ad of 500 for an unauthenticated Azure DevOps webhook
…ook basic auth responses
512d7c8 to
d9dce47
Compare
Code Review by Qodo
1.
|
…uotes for the missing credentials response
…ive phrasing in the docstring
|
Code review by qodo was updated up to the latest commit ee155e3 |
Closes #2702.
Description
Requests with no
Authorizationheader produce an unhandledAttributeErrorand a 500, with noWWW-Authenticatechallenge and a stack trace in the logs.Root cause
security = HTTPBasic(auto_error=False)(pr_agent/servers/azuredevops_server_webhook.py:33) suppresses FastAPI's own 401, socredentialsisNonewhen the header is absent andcredentials.usernameraises at line 86.This is not an authentication bypass — the request is still rejected, it just fails with the wrong status and no challenge header.
The fix
Reject a
Nonecredentials object with the same 401 the wrong-password branch already returns.Behaviour change
Authorizationheader →500,WWW-Authenticate: NoneAuthorizationheader →401,WWW-Authenticate: 'Basic'; correct and wrong credentials behave exactly as before (200 / 401)Verified against the real
authorizedependency through a FastAPITestClient.Files changed
Testing
pytest tests/unittest— 1748 passed, 1 skipped, 1 xfailed (unchanged frommain).github/workflows/build-and-test.yamlruns it:python:3.12.13-slimmain, no longer reproducible on this branchruff— no new findings vsmain;isort— cleanRisk / compatibility
No change to accepted or rejected credentials — only to the unauthenticated case's status code.
Checklist