From 86afe7a005888ac2c6b5556557cf7901c40d7322 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Sat, 15 Aug 2026 17:17:22 -0700 Subject: [PATCH] Treat a malformed data source id as ErrNotFound, not a raw pg error SetDataSourceClickHouseCredentials let a non-UUID id leak Postgres's raw 22P02 (invalid_text_representation) error past the store's ErrNotFound boundary. A malformed id can never match a row either way, so it should be treated the same as "no such row" rather than exposing a database-internal error past this package's boundary. Found via a live Postgres integration test. --- enterprise/internal/rbacstore/rbacstore.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/enterprise/internal/rbacstore/rbacstore.go b/enterprise/internal/rbacstore/rbacstore.go index 03bad7c..cac0747 100644 --- a/enterprise/internal/rbacstore/rbacstore.go +++ b/enterprise/internal/rbacstore/rbacstore.go @@ -27,6 +27,7 @@ import ( "github.com/google/uuid" "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" "github.com/jackc/pgx/v5/pgxpool" ) @@ -534,6 +535,13 @@ func (s *Store) SetDataSourceClickHouseCredentials(ctx context.Context, id, user `UPDATE data_sources SET clickhouse_username = $2, clickhouse_password = $3 WHERE id = $1`, id, username, password) if err != nil { + // A malformed id (not valid UUID syntax) can never match a row + // either way -- treat it the same as "no such row" rather than + // leaking Postgres's raw 22P02 error past this store's boundary. + var pgErr *pgconn.PgError + if errors.As(err, &pgErr) && pgErr.Code == "22P02" { + return ErrNotFound + } return fmt.Errorf("rbacstore: setting data source credentials: %w", err) } if tag.RowsAffected() == 0 {