Skip to content

fix(api): return clean 404 for malformed namespace ID in InNamespace filter#6408

Merged
gustavosbarreto merged 1 commit into
masterfrom
fix/6406-innamespace-malformed-uuid
Jun 5, 2026
Merged

fix(api): return clean 404 for malformed namespace ID in InNamespace filter#6408
gustavosbarreto merged 1 commit into
masterfrom
fix/6406-innamespace-malformed-uuid

Conversation

@otavio
Copy link
Copy Markdown
Member

@otavio otavio commented Jun 3, 2026

Summary

Follow-up to #6404 / #6405. 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 invalid 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

InNamespace now validates the value as a UUID (via the existing pkg/uuid.Parse) and returns store.ErrNoDocuments before 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)
  • APIKeyResolve
  • PublicKeyResolve
  • SessionResolve

applyOptions already routes option errors through fromSQLError, which passes store.ErrNoDocuments through unchanged, so the not-found surfaces cleanly without a logged SQL error — no changes needed in utils.go.

Tests

Added a fails with malformed (non-UUID) namespace ID subtest to the shared TestAPIKeyResolve suite, which runs against both Mongo and Postgres backends to verify parity (on Mongo a non-matching string already yields ErrNoDocuments). The full Postgres store suite passes locally.

Fixes: #6406

@otavio otavio requested a review from a team as a code owner June 3, 2026 19:40
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Claude finished @otavio's task in 4m 2s —— View job


Code Review Complete

Reviewed 2 files across code quality, security, testing, Go patterns, and architecture (including cross-repo impact on cloud/) — no issues found. The code looks good as-is.

Key observations:

  • The UUID validation guard in InNamespace correctly returns store.ErrNoDocuments before issuing a doomed query, and the error passes cleanly through fromSQLError (default case) unchanged.
  • The QueryOptions interface contract is preserved — no signature or behavioral breaking changes for cloud/ consumers.
  • The shared-suite test exercises the observable contract (ErrNoDocuments for malformed namespace IDs) on both Mongo and Postgres backends. On Postgres, reverting the fix would cause the test to fail (raw SQLSTATE 22P02 ≠ ErrNoDocuments), so the coverage is meaningful.
  • The change is security-positive: it prevents Postgres type-error messages from propagating and leaking column type information.

To request another review round, comment /review.

…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
@otavio otavio force-pushed the fix/6406-innamespace-malformed-uuid branch from ed1beda to 4b2d46a Compare June 3, 2026 20:04
@gustavosbarreto gustavosbarreto merged commit a4b059b into master Jun 5, 2026
11 checks passed
@gustavosbarreto gustavosbarreto deleted the fix/6406-innamespace-malformed-uuid branch June 5, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed namespace ID via InNamespace query option logs a Postgres uuid error (22P02)

2 participants