Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Glob {

// If not a glob pattern then just match the string.
if (!this.glob.includes('*')) {
this.regexp = new RegExp(`.*${this.glob}.*`, 'u')
this.regexp = new RegExp(`\\b${this.glob}\\b`, 'u')

Check failure

Code scanning / CodeQL

Regular expression injection

This regular expression is constructed from a [environment variable](1).

Copilot Autofix

AI about 1 year ago

To fix the problem, we need to sanitize the glob parameter before using it to construct a regular expression. We can use the _.escapeRegExp function from the lodash library to escape any special characters in the glob parameter. This will ensure that the user cannot insert characters which have a special meaning in regular expressions.

  1. Import the lodash library in lib/glob.js.
  2. Use the _.escapeRegExp function to sanitize the glob parameter before using it in the regular expression.
Suggested changeset 1
lib/glob.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/lib/glob.js b/lib/glob.js
--- a/lib/glob.js
+++ b/lib/glob.js
@@ -1 +1,3 @@
+const _ = require('lodash');
+
 class Glob {
@@ -6,3 +8,4 @@
     if (!this.glob.includes('*')) {
-      this.regexp = new RegExp(`\\b${this.glob}\\b`, 'u')
+      const safeGlob = _.escapeRegExp(this.glob);
+      this.regexp = new RegExp(`\\b${safeGlob}\\b`, 'u')
       return
EOF
@@ -1 +1,3 @@
const _ = require('lodash');

class Glob {
@@ -6,3 +8,4 @@
if (!this.glob.includes('*')) {
this.regexp = new RegExp(`\\b${this.glob}\\b`, 'u')
const safeGlob = _.escapeRegExp(this.glob);
this.regexp = new RegExp(`\\b${safeGlob}\\b`, 'u')
return
Copilot is powered by AI and may make mistakes. Always verify output.
return
}
this.regexptText = this.globize(this.glob)
Expand Down