fix(api): return clean 404 for malformed namespace ID in InNamespace filter#6408
Merged
Merged
Conversation
|
Claude finished @otavio's task in 4m 2s —— View job Code Review CompleteReviewed 2 files across code quality, security, testing, Go patterns, and architecture (including cross-repo impact on Key observations:
To request another review round, comment |
…filter
The InNamespace query option filters on the uuid-typed namespace_id
column with a raw, externally-supplied string. A malformed (non-UUID)
value reached Postgres and failed with SQLSTATE 22P02 ("invalid input
syntax for type uuid"), logging a misleading SQL error even though the
result is effectively not-found.
Validate the value as a UUID and return store.ErrNoDocuments early,
before the filter is appended, so callers (DeviceResolve, APIKeyResolve,
PublicKeyResolve, SessionResolve) get a clean not-found without a logged
SQL error. applyOptions already routes the error through fromSQLError,
which passes ErrNoDocuments through unchanged.
Same root cause as #6404, different code path.
Fixes: #6406
ed1beda to
4b2d46a
Compare
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.
Summary
Follow-up to #6404 / #6405. The
InNamespacequery option filters on theuuid-typednamespace_idcolumn with a raw, externally-supplied string. A malformed (non-UUID) value reached Postgres and failed withinvalid input syntax for type uuid (SQLSTATE 22P02), logging a misleading SQL error — even though the result is effectively not-found. Same root cause as #6404, different code path.Change
InNamespacenow validates the value as a UUID (via the existingpkg/uuid.Parse) and returnsstore.ErrNoDocumentsbefore appending the filter, so no doomed query is issued. This covers every resolver that scopes by namespace through this option:DeviceResolve(on the device-auth path)APIKeyResolvePublicKeyResolveSessionResolveapplyOptionsalready routes option errors throughfromSQLError, which passesstore.ErrNoDocumentsthrough unchanged, so the not-found surfaces cleanly without a logged SQL error — no changes needed inutils.go.Tests
Added a
fails with malformed (non-UUID) namespace IDsubtest to the sharedTestAPIKeyResolvesuite, which runs against both Mongo and Postgres backends to verify parity (on Mongo a non-matching string already yieldsErrNoDocuments). The full Postgres store suite passes locally.Fixes: #6406