Skip to content

Commit f97ce71

Browse files
Potential fix for code scanning alert no. 4: Regular expression injection
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 5a5c53c commit f97ce71

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

bin/lib/logs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { spawn } from 'node:child_process';
44
import chalk from 'chalk';
5+
import _ from 'lodash';
56

67
// Log levels and their colors
78
const LOG_LEVELS = {
@@ -121,7 +122,8 @@ async function readLogsFromFile(filePath, options = {}) {
121122
}
122123

123124
if (options.filter) {
124-
const regex = new RegExp(options.filter, 'i');
125+
const safeFilter = _.escapeRegExp(options.filter);
126+
const regex = new RegExp(safeFilter, 'i');
125127
logs = logs.filter(log => regex.test(log.message) || regex.test(log.raw));
126128
}
127129

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"degit": "^2.8.4",
5454
"fs-extra": "^11.3.2",
5555
"prompts": "^2.4.2",
56-
"execa": "^9.6.0"
56+
"execa": "^9.6.0",
57+
"lodash": "^4.17.21"
5758
},
5859
"devDependencies": {
5960
"vitepress": "^1.3.3",

0 commit comments

Comments
 (0)