Skip to content

Commit 15f8999

Browse files
committed
fix: escape string literals in scanDiff for regEx based search
1 parent 0b64e7f commit 15f8999

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,4 @@ website/.docusaurus
269269

270270
# Jetbrains IDE
271271
.idea
272+
.vscode/settings.json

package-lock.json

Lines changed: 14 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"cors": "^2.8.5",
5656
"diff2html": "^3.4.52",
5757
"env-paths": "^3.0.0",
58+
"escape-string-regexp": "^5.0.0",
5859
"express": "^4.21.2",
5960
"express-http-proxy": "^2.1.2",
6061
"express-rate-limit": "^8.1.0",
@@ -101,8 +102,8 @@
101102
"@types/node": "^22.18.10",
102103
"@types/react-dom": "^17.0.26",
103104
"@types/react-html-parser": "^2.0.7",
104-
"@types/validator": "^13.15.3",
105105
"@types/sinon": "^17.0.4",
106+
"@types/validator": "^13.15.3",
106107
"@types/yargs": "^17.0.33",
107108
"@vitejs/plugin-react": "^4.7.0",
108109
"chai": "^4.5.0",

src/proxy/processors/push-action/scanDiff.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Action, Step } from '../../actions';
22
import { getCommitConfig, getPrivateOrganizations } from '../../../config';
33
import parseDiff, { File } from 'parse-diff';
4+
import escapeStringRegexp from 'escape-string-regexp';
45

56
const commitConfig = getCommitConfig();
67
const privateOrganizations = getPrivateOrganizations();
@@ -75,10 +76,11 @@ const combineMatches = (organization: string) => {
7576
: Object.entries(commitConfig?.diff?.block?.providers ?? []);
7677

7778
// Combine all matches (literals, patterns)
79+
7880
const combinedMatches = [
7981
...blockedLiterals.map((literal) => ({
8082
type: BLOCK_TYPE.LITERAL,
81-
match: new RegExp(literal, 'gi'),
83+
match: new RegExp(escapeStringRegexp(literal), 'gi'), //TODO: swap out escapeStringRegexp() for RegExp.escape() when we require node 24
8284
})),
8385
...blockedPatterns.map((pattern) => ({
8486
type: BLOCK_TYPE.PATTERN,

test/processors/scanDiff.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ index 8b97e49..de18d43 100644
5353
Project to test gitproxy
5454
+AKIAIOSFODNN7EXAMPLE
5555
+AKIAIOSFODNN8EXAMPLE
56-
+blockedTestLiteral
56+
+emdedded_blocked.Te$t.Literal?
5757
`;
5858
};
5959
describe('Scan commit diff...', async () => {
6060
privateOrganizations[0] = 'private-org-test';
6161
commitConfig.diff = {
6262
block: {
63-
literals: ['blockedTestLiteral'],
63+
//n.b. the example literal includes special chars that would be interpreted as RegEx if not escaped properly
64+
literals: ['blocked.Te$t.Literal?'],
6465
patterns: [],
6566
providers: {
6667
'AWS (Amazon Web Services) Access Key ID':

0 commit comments

Comments
 (0)