Skip to content

fix(store): a search value that is not a uuid reports bad input - #1952

Open
AmanGIT07 wants to merge 2 commits into
mainfrom
fix-search-invalid-uuid-bad-input
Open

AmanGIT07 wants to merge 2 commits into
mainfrom
fix-search-invalid-uuid-bad-input

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Follows #1942, which fixed this for the organization users search. This applies the same treatment to the rest.

Summary

Every aggregate search binds a caller supplied id to a uuid column. A value the database cannot read as a uuid reached the handler as a raw driver error, so the API answered internal and echoed the database text. It now answers invalid argument.

Changes

  • All eleven aggregate searches run their query error through checkPostgresError and return ErrBadInput for ErrInvalidTextRepresentation, matching the shape already used in the audit repositories. Searches that wrap their error keep their own wording in the default branch.
  • The organizations search handler gains the ErrBadInput branch. The other ten handlers already had it, because repositories already answer ErrBadInput for an unsupported filter or sort.
  • org_users_repository.go moves from the inline if added in fix(store): org users search reports a value that is not a uuid as bad input #1942 to the same switch, so all eleven read alike.
  • New search_invalid_uuid_pg_test.go: one case per search against a real postgres. New organization_billing_test.go: handler cases for the mapping above.

Technical Details

checkPostgresError is not automatic, it is a function each caller invokes. None of these searches called it, so the driver error travelled untouched to the handler and errors.Is(err, ErrInvalidTextRepresentation) was false everywhere.

The mapping sits after the transaction rather than inside its closure, so it does not depend on how the transaction wrapper reports a rollback.

The organizations search takes no id. Its bad value arrives through the id filter, which compares against the organizations primary key.

Test Plan

  • go test ./internal/store/postgres/ ./internal/api/v1beta1connect/ passes
  • The eleven new cases fail on main for ten of the eleven searches; organization users already passed there because of fix(store): org users search reports a value that is not a uuid as bad input #1942
  • golangci-lint run on both packages reports no issues
  • End to end against a local server, calling each RPC with a malformed id, run against main and this branch on the same database with only the binary swapped
RPC main this branch
SearchOrganizationProjects 500 internal 400 invalid argument
SearchOrganizationServiceUserCredentials 500 internal 400 invalid argument
SearchProjectUsers 500 internal 400 invalid argument
SearchOrganizations 500 internal 400 invalid argument
SearchOrganizationUsers 400 400
SearchOrganizationPATs 400 400
SearchUserOrganizations 400 400
SearchUserProjects 400 400
SearchOrganizationServiceUsers 404 404
SearchOrganizationInvoices 404 404
SearchOrganizationTokens 404 404

Four RPCs change. Of the rest, organization PATs, user organizations and user projects validate the id as a uuid in proto so the request stops earlier, and organization service users, invoices and tokens resolve the organization before the search and answer not found. Their repositories are still covered, because the same path is reachable through a filter value.

SQL Safety

  • Values flow through ? placeholders, goqu.Ex{}, or goqu.Record{} — never fmt.Sprintf or + building a query that gets executed.
  • ToSQL() callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Never query, _, err := ….
  • No ? placeholders inside single-quoted SQL literals in goqu.L.
  • No new //nolint:forbidigo or // #nosec G20x annotations.

Every aggregate search runs its query error through checkPostgresError and
answers ErrBadInput when the database could not read a value as a uuid.
The organizations search handler gains the branch the others already had.
…d input

One case per search against postgres, plus handler cases for the
organizations search error mapping.
@vercel

vercel Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Ready Ready Preview Sep 25, 2026 11:38am UTC

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: raystack/frontier/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e3124388-d069-4f32-bcec-4f75c1d5d366

📥 Commits

Reviewing files that changed from the base of the PR and between 1a8f1dd and e4783a2.

📒 Files selected for processing (14)
  • internal/api/v1beta1connect/organization_billing.go
  • internal/api/v1beta1connect/organization_billing_test.go
  • internal/store/postgres/org_billing_repository.go
  • internal/store/postgres/org_invoices_repository.go
  • internal/store/postgres/org_pats_repository.go
  • internal/store/postgres/org_projects_repository.go
  • internal/store/postgres/org_serviceuser_credentials_repository.go
  • internal/store/postgres/org_serviceuser_repository.go
  • internal/store/postgres/org_tokens_repository.go
  • internal/store/postgres/org_users_repository.go
  • internal/store/postgres/project_users_repository.go
  • internal/store/postgres/search_invalid_uuid_pg_test.go
  • internal/store/postgres/user_orgs_repository.go
  • internal/store/postgres/user_projects_repository.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Invalid UUIDs entered in organization, project, user, billing, and related searches now return a clear invalid-input error instead of an internal server error. Other errors continue to be reported as internal errors.
  • Tests
    • Added coverage for invalid UUID handling and for successful and failed organization billing searches.

Walkthrough

Search repositories now map PostgreSQL invalid UUID errors to ErrBadInput. The billing Connect endpoint maps that error to InvalidArgument. Added tests cover repository searches and the Connect response.

Changes

Invalid UUID search handling

Layer / File(s) Summary
Map invalid UUID errors in searches
internal/store/postgres/*_repository.go, internal/store/postgres/search_invalid_uuid_pg_test.go
Search methods normalize PostgreSQL errors and return ErrBadInput for invalid text representations. A Docker-backed test suite checks invalid UUID input across ten searches.
Map billing bad input to Connect
internal/api/v1beta1connect/organization_billing.go, internal/api/v1beta1connect/organization_billing_test.go
SearchOrganizations returns Connect InvalidArgument for postgres.ErrBadInput and retains Internal for other errors. Tests cover these errors and a successful response.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: rohilsurana

Merge Risk: ⚪ Minimal · up to e4783

Malformed UUID searches receive the intended bad-input response. No actionable issue remains before merge, subject to normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to e4783

Malformed identifiers now receive an invalid-input response instead of an internal-error response. The reviewed paths show no new data access or privilege, but the assessment does not cover every caller or deployment control.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated change affects responses to malformed search input, including identifiers used by credential and token searches; the reviewed branches return an error rather than a result or a state change.

Trust Boundaries and Controls

  • observed — For SearchOrganizations, query transformation and validation precede the changed error branch. The reviewed code does not establish the endpoint’s surrounding authorization or middleware controls.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 36130478918

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.4%) to 52.47%

Details

  • Coverage increased (+0.4%) from the base build.
  • Patch coverage: 14 uncovered changes across 7 files (53 of 67 lines covered, 79.1%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
internal/store/postgres/org_invoices_repository.go 6 4 66.67%
internal/store/postgres/org_pats_repository.go 6 4 66.67%
internal/store/postgres/org_serviceuser_credentials_repository.go 6 4 66.67%
internal/store/postgres/org_serviceuser_repository.go 6 4 66.67%
internal/store/postgres/org_tokens_repository.go 6 4 66.67%
internal/store/postgres/user_orgs_repository.go 6 4 66.67%
internal/store/postgres/user_projects_repository.go 6 4 66.67%
Total (12 files) 67 53 79.1%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 41199
Covered Lines: 21617
Line Coverage: 52.47%
Coverage Strength: 17.04 hits per line

💛 - Coveralls

This branch was successfully deployed

1 active deployment
Preview — e4783a2f Deployed Sep 25, 2026 by vercel[bot]
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.

2 participants