Return 401 for failed internal API authentication - #1656
skyfallwastaken wants to merge 1 commit into
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-01a05ac7-ce63-713d-afa9-928ac8993ec9 Co-authored-by: Amp <amp@ampcode.com>
Greptile SummaryCentralizes internal API credential validation in the base controller and changes failed revocation authentication from an external redirect to an empty 401 response.
Confidence Score: 5/5The PR appears safe to merge with the authentication behavior consistently implemented, tested, and documented. Invalid or missing revocation credentials now terminate the callback chain with an empty 401, while matching credentials continue to the existing action. Important Files Changed
Reviews (1): Last reviewed commit: "Return 401 for failed internal API authe..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This pull request updates internal API authentication so failed auth for the revocation endpoint returns an empty 401 Unauthorized response instead of redirecting, and so missing/blank credentials are handled safely within the shared internal API base controller.
Changes:
- Centralises internal API key authentication in
Api::Internal::ApplicationController, including blank handling and constant-time digest comparison. - Updates the revocation endpoint to supply its expected key (
HKA_REVOCATION_KEY) viaexpected_api_keys. - Aligns tests and OpenAPI documentation to the new
401 Unauthorizedfailure behaviour.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
app/controllers/api/internal/application_controller.rb |
Implements shared internal auth that responds with 401 and allows controllers to provide expected keys. |
app/controllers/api/internal/revocations_controller.rb |
Removes bespoke auth and provides expected_api_keys for revocation-specific credentials. |
test/controllers/api/internal/revocations_controller_test.rb |
Adds coverage for missing secret and mismatched token scenarios; updates auth header helper. |
spec/requests/api/internal/internal_spec.rb |
Updates the rswag spec to document/auth-test 401 on failed internal authentication. |
swagger/admin/swagger.yaml |
Updates generated OpenAPI output to reflect 401 unauthorized instead of a redirect response. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
f1786c8 to
6101271
Compare
Summary of the problem
The revocation endpoint handled its credential separately from the internal API authentication policy. A missing secret could raise an exception and failed authentication redirected callers to an external page.
Describe your changes
Centralises blank handling and digest comparison in the internal API base controller while allowing each controller to supply its expected keys. The revocation controller now supplies
HKA_REVOCATION_KEYand failed authentication returns an empty 401 response. The successful revocation response remains unchanged and the documented failure response is now 401.Screenshots / Media
Not applicable because there are no visual changes.