Repository navigation
fix(config): escape LIKE wildcards in registration search filter - #720
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR adds SQL LIKE wildcard escaping to the registration search filter to prevent unintended pattern matching, mirroring existing security handling in ChangesSearch Filter Wildcard Escaping
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/config/store_postgres_pgxmock_test.go (1)
1545-1595: ⚡ Quick winAdd regression coverage for backslash (
\) escaping.The implementation escapes
\too, but tests currently assert only%and_. Adding one test here closes the remaining escape-path gap.✅ Suggested test addition
+func TestPGXMock_ListAccountRegistrations_SearchEscapesBackslash(t *testing.T) { + mock := newMock(t) + store := storeWith(mock) + ctx := context.Background() + + rawSearch := `foo\bar` + escapedArg := `foo\\bar` + + rows := pgxmock.NewRows(registrationCols()). + AddRow(minimalRegRow("reg-3", `foo\bar LLC`, "foo@example.com")...) + mock.ExpectQuery(`ESCAPE`). + WithArgs("%" + escapedArg + "%"). + WillReturnRows(rows) + + filter := AccountRegistrationFilter{Search: rawSearch} + regs, err := store.ListAccountRegistrations(ctx, filter) + require.NoError(t, err) + assert.Len(t, regs, 1) + assert.Equal(t, "reg-3", regs[0].ID) + assert.NoError(t, mock.ExpectationsWereMet()) +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/config/store_postgres_pgxmock_test.go` around lines 1545 - 1595, Add a new unit test (e.g., TestPGXMock_ListAccountRegistrations_SearchEscapesBackslash) mirroring the existing percent/underscore tests that verifies backslash escaping: create mock := newMock(t), store := storeWith(mock), ctx := context.Background(), set rawSearch to include a backslash (for example "foo\\bar") and set escapedArg to the expected escaped form (e.g., `foo\\bar`), prepare rows := pgxmock.NewRows(registrationCols()).AddRow(minimalRegRow("reg-3", "foo\\bar Inc", "foo\\bar@example.com")...), set mock.ExpectQuery(`ESCAPE`).WithArgs("%"+escapedArg+"%").WillReturnRows(rows), call store.ListAccountRegistrations(ctx, AccountRegistrationFilter{Search: rawSearch}) and assert no error, one result with ID "reg-3", and mock.ExpectationsWereMet(); use the same helper symbols (newMock, storeWith, ListAccountRegistrations, AccountRegistrationFilter, minimalRegRow, registrationCols) so the test integrates with the others.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/config/store_postgres_pgxmock_test.go`:
- Around line 1545-1595: Add a new unit test (e.g.,
TestPGXMock_ListAccountRegistrations_SearchEscapesBackslash) mirroring the
existing percent/underscore tests that verifies backslash escaping: create mock
:= newMock(t), store := storeWith(mock), ctx := context.Background(), set
rawSearch to include a backslash (for example "foo\\bar") and set escapedArg to
the expected escaped form (e.g., `foo\\bar`), prepare rows :=
pgxmock.NewRows(registrationCols()).AddRow(minimalRegRow("reg-3", "foo\\bar
Inc", "foo\\bar@example.com")...), set
mock.ExpectQuery(`ESCAPE`).WithArgs("%"+escapedArg+"%").WillReturnRows(rows),
call store.ListAccountRegistrations(ctx, AccountRegistrationFilter{Search:
rawSearch}) and assert no error, one result with ID "reg-3", and
mock.ExpectationsWereMet(); use the same helper symbols (newMock, storeWith,
ListAccountRegistrations, AccountRegistrationFilter, minimalRegRow,
registrationCols) so the test integrates with the others.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fb6c3118-420f-4b4c-83ca-74dc3232a66c
📒 Files selected for processing (2)
internal/config/store_postgres_pgxmock_test.gointernal/config/store_postgres_registrations.go
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Addressed in bb34bf9. Added @coderabbitai review |
|
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Closes #719. Surfaced by the full-codebase SQL injection audit (audit found zero SQLi but one suspicious LIKE wildcard escape gap).
internal/config/store_postgres_registrations.go:101-107was bindingfilter.Searchas$N(so not SQLi), but%/_/\\were not escaped — a search like%@gmail.commatched every gmail address instead of literally containing%@gmail.com. Now mirrors the working pattern atstore_postgres.go:1974(ListCloudAccounts):strings.NewReplacerescapes the wildcards before wrapping, andESCAPE '\\'is appended to all three ILIKE clauses.Tests
TestPGXMock_ListAccountRegistrations_SearchEscapesPercent—%fooinput binds\\%footo the DB parameterTestPGXMock_ListAccountRegistrations_SearchEscapesUnderscore—foo_barinput bindsfoo\\_barESCAPESummary by CodeRabbit