Skip to content

Commit 58cbf81

Browse files
fix: escape every regexp metacharacter in the handler map name
The name was escaped for `$` and `.` alone, so one carrying a bracket or a backslash would have been read as regexp syntax rather than matched literally. The three globals it is called with are unaffected; CodeQL reports the gap.
1 parent 6c6884f commit 58cbf81

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎lib/util/handlerKeys.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
/** @type {Map<string, RegExp>} */
1212
const assignmentCache = new Map();
1313

14+
// Every character the regexp grammar gives a meaning to, so a global naming one is
15+
// matched literally rather than reinterpreted — a lone `\` included.
16+
const REGEXP_META = /[.*+?^${}()|[\]\\]/g;
17+
1418
/**
1519
* Matches an assignment onto a handler map, as the modules installing one emit it.
1620
* @param {string} handlers the handler map global
@@ -20,7 +24,7 @@ const assignmentRegExp = (handlers) => {
2024
const cached = assignmentCache.get(handlers);
2125
if (cached !== undefined) return cached;
2226
const regExp = new RegExp(
23-
`${handlers.replace(/[$.]/g, "\\$&")}\\.([\\w$]+)\\s*=`,
27+
`${handlers.replace(REGEXP_META, "\\$&")}\\.([\\w$]+)\\s*=`,
2428
"g"
2529
);
2630
assignmentCache.set(handlers, regExp);

0 commit comments

Comments
 (0)