fix(api): answer 404 for a public key outside the caller's namespace - #6925
Merged
Conversation
GetPublicKey resolves the key bounded to the caller's namespace, so a
fingerprint that belongs to another namespace resolves to no row and the
store returns ErrNoDocuments. The method handed that error back untouched,
and the route error handler maps a bare store-layer error to 500. So
GET /api/sshkeys/public-keys/{fingerprint} answered 500 where 404 belongs.
It now maps ErrNoDocuments to ErrPublicKeyNotFound, matching what
UpdatePublicKey and DeletePublicKey already do on the same read. 404 is
also the right answer for the cross-namespace case specifically: it does
not disclose that the key exists elsewhere.
Issue: shellhub-io/team#220
|
Claude finished @otavio's task in 49s —— View job Code Review CompleteReviewed 2 files across code quality, security, testing, language patterns, and architecture — no new issues found. The code looks good as-is. A few notes worth recording (not blocking):
To request another review round, comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
GET /api/sshkeys/public-keys/{fingerprint}answers 404 instead of 500 when the key belongs toanother namespace.
Why
GetPublicKeyresolves the key bounded to the caller's namespace, so a foreign fingerprintmatches no row and the store returns
ErrNoDocuments. The method returned that error untouched,and
server/api/pkg/echo/handlers/errors.gomaps a bare store-layer error to 500 — the handlerdocuments that case as one the service must fix.
UpdatePublicKeyandDeletePublicKeyalready wrapped the identical read correctly, so this wasan inconsistency inside one file rather than a design gap.
Found while auditing an enterprise report of the same defect class on the firewall rule endpoint
(shellhub-io/team#220, private).
Changes
GetPublicKeymapsErrNoDocumentstoErrPublicKeyNotFound. 404 ratherthan 403 is deliberate: it does not disclose that the key exists in another namespace.
TestGetPublicKeyspins the mapping.Audit scope
I read every namespace-scoped service path in
server/api/services. This was the only otherclient-reachable instance. Already correct: devices, sessions, tags, access policies, SSH
identities, namespaces, members, API keys — each resolves the row and wraps the error before it
mutates. The remaining raw store returns are read-backs after a successful write, where 500 is
the right answer.
Testing
Create a public key in namespace A, then
GET /api/sshkeys/public-keys/{fingerprint}withcredentials for namespace B. Expect 404, not 500.