🔒 [security fix] Fix Solr Query Injection in solrHelper.ts#772
🔒 [security fix] Fix Solr Query Injection in solrHelper.ts#772dt2patel wants to merge 2 commits into
Conversation
Introduced `escapeSolrQuery` utility to sanitize user-provided inputs
before interpolating them into Solr queries and filters.
- Escapes Solr special characters: + - ! ( ) { } [ ] ^ " ~ * ? : / \ | &
- Applied to `queryString` and all filter parameters in `prepareOrderQuery`.
- Handles non-string inputs gracefully.
Co-authored-by: dt2patel <60128132+dt2patel@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b4337ce49d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
There was a problem hiding this comment.
Code Review
This pull request introduces a escapeSolrQuery utility in src/utils/solrHelper.ts to sanitize parameters used in Solr queries. While this improves security, several issues were identified: applying the escape function to '-fulfillmentStatus' will break complex expressions passed from other modules, and the keys in params.filters remain vulnerable to injection. Additionally, the utility's implementation incorrectly handles falsy values like 0 or false by converting them to empty strings, which should be corrected to preserve their string representations.
|
|
||
| if (params['-fulfillmentStatus']) { | ||
| payload.json.filter.push(`-fulfillmentStatus: ${params['-fulfillmentStatus']}`) | ||
| payload.json.filter.push(`-fulfillmentStatus: ${escapeSolrQuery(params['-fulfillmentStatus'])}`) |
There was a problem hiding this comment.
Applying escapeSolrQuery to the '-fulfillmentStatus' parameter will break existing functionality. In src/store/modules/order/actions.ts, this parameter is passed as a complex Solr expression (Cancelled OR Rejected OR Completed). Escaping the parentheses will cause Solr to treat them as literal characters, leading to incorrect filtering. This utility should only be applied to values that are intended to be single terms, or the application should be refactored to separate structural syntax from user-provided values.
There was a problem hiding this comment.
I have reviewed the changes. I also fixed two ESLint 'no-useless-escape' errors in the escapeSolrQuery regex that were causing the CI build to fail. The functionality remains the same, and all Solr special characters are still correctly escaped.
There was a problem hiding this comment.
@jules Applying escapeSolrQuery to the '-fulfillmentStatus' parameter will break existing functionality. In src/store/modules/order/actions.ts, this parameter is passed as a complex Solr expression (Cancelled OR Rejected OR Completed). Escaping the parentheses will cause Solr to treat them as literal characters, leading to incorrect filtering. This utility should only be applied to values that are intended to be single terms, or the application should be refactored to separate structural syntax from user-provided values.
| @@ -1,3 +1,8 @@ | |||
| const escapeSolrQuery = (query: any) => { | |||
| if (typeof query !== 'string') query = query ? String(query) : '' | |||
There was a problem hiding this comment.
The current implementation of escapeSolrQuery incorrectly converts falsy values like 0 or false to an empty string. This can lead to incorrect Solr queries when filtering by these values. Using nullish coalescing and toString() ensures that 0 and false are correctly preserved as strings while handling null and undefined.
| if (typeof query !== 'string') query = query ? String(query) : '' | |
| query = (query ?? '').toString(); |
There was a problem hiding this comment.
@jules The current implementation of escapeSolrQuery incorrectly converts falsy values like 0 or false to an empty string. This can lead to incorrect Solr queries when filtering by these values. Using nullish coalescing and toString() ensures that 0 and false are correctly preserved as strings while handling null and undefined.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
🎯 What: The vulnerability fixed was a Solr Query Injection in the
prepareOrderQueryfunction. User-provided search strings were being directly interpolated into the query without escaping, allowing attackers to manipulate the query logic.*,),() to break out of the intended query structure, potentially accessing unauthorized data or causing denial of service.🛡️ Solution: Implemented an
escapeSolrQueryfunction that escapes all Solr special characters using a regular expression. This function is now applied to all user-controlled parameters before they are added to the Solr payload.PR created automatically by Jules for task 12865436110145679296 started by @dt2patel