🛡️ fix: Escape People Picker Search Regex - #13169
Conversation
|
@codex review |
There was a problem hiding this comment.
Pull request overview
This PR hardens the “people picker” / principal search flow by ensuring user-supplied search terms are treated as literal text before being used in MongoDB regex queries or relevance scoring, preventing regex injection and invalid-regex failures.
Changes:
- Escapes user-provided search strings before constructing MongoDB
RegExpfilters in data-schemas search methods. - Replaces regex-based “exact match” relevance scoring with lowercase string comparisons.
- Tightens
qvalidation in the APIsearch-principalscontroller and removes internal error details from 500 responses; adds regression tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/data-schemas/src/methods/userGroup.ts | Escapes regex input for group/user/role queries; switches relevance scoring to literal string comparisons. |
| packages/data-schemas/src/methods/userGroup.spec.ts | Adds regression tests for literal handling of regex metacharacters and invalid regex syntax; updates scoring expectations. |
| packages/data-schemas/src/methods/user.ts | Escapes regex input for user search and replaces exact-regex scoring with literal comparisons. |
| packages/data-schemas/src/methods/user.methods.spec.ts | Adds regression tests ensuring regex metacharacters/invalid patterns are treated literally in user search. |
| api/server/controllers/PermissionsController.js | Validates q type/shape, uses trimmed query consistently, and stops returning internal error details on failures. |
| api/server/controllers/tests/PermissionsController.spec.js | Adds controller tests for non-string q, trimmed literal query behavior, and sanitized 500 responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (typeof rawQuery !== 'string' || rawQuery.trim().length === 0) { | ||
| return res.status(400).json({ |
| // Score results by relevance | ||
| const exactRegex = new RegExp(`^${searchPattern.trim()}$`, 'i'); | ||
| const startsWithPattern = searchPattern.trim().toLowerCase(); | ||
| const startsWithPattern = trimmedPattern.toLowerCase(); | ||
|
|
||
| const scoredUsers = users.map((user) => { | ||
| const searchableFields = [user.name, user.email, user.username].filter( |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
GitNexus: 🚀 deployedThe |
Summary
I fixed the people-picker and shared user search paths so user-supplied search text is treated as literal text before it reaches MongoDB regex queries or relevance scoring.
qonsearch-principalsand stopped returning internal error details on failures.Change Type
Testing
I validated the search fix with focused data-schemas and API controller tests, then ran package builds and lint for the touched files.
Test Configuration:
npm run build:data-providernpx jest src/methods/userGroup.spec.ts src/methods/user.methods.spec.ts --runInBandfrompackages/data-schemasnpm run build:data-schemasnpm run build:apinpx jest server/controllers/__tests__/PermissionsController.spec.js --runInBandfromapinpx eslint api/server/controllers/PermissionsController.js api/server/controllers/__tests__/PermissionsController.spec.js packages/data-schemas/src/methods/user.ts packages/data-schemas/src/methods/userGroup.ts packages/data-schemas/src/methods/user.methods.spec.ts packages/data-schemas/src/methods/userGroup.spec.tsChecklist