Skip to content

Commit 0d54b0c

Browse files
authored
fix(cache): improve cache key serialization (#2424)
* fix(cache): improve cache key formation. Fixes a potential parser cache poisoning attack vulnerability reported by Vsevolod Kokorin (Slonser) of Solidlab
1 parent d9dccfd commit 0d54b0c

File tree

2 files changed

+518
-15
lines changed

2 files changed

+518
-15
lines changed

lib/parsers/parser_cache.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,38 @@
33
const LRU = require('lru-cache').default;
44

55
const parserCache = new LRU({
6-
max: 15000
6+
max: 15000,
77
});
88

99
function keyFromFields(type, fields, options, config) {
10-
let res =
11-
`${type}` +
12-
`/${typeof options.nestTables}` +
13-
`/${options.nestTables}` +
14-
`/${options.rowsAsArray}` +
15-
`/${options.supportBigNumbers || config.supportBigNumbers}` +
16-
`/${options.bigNumberStrings || config.bigNumberStrings}` +
17-
`/${typeof options.typeCast}` +
18-
`/${options.timezone || config.timezone}` +
19-
`/${options.decimalNumbers}` +
20-
`/${options.dateStrings}`;
10+
const res = [
11+
type,
12+
typeof options.nestTables,
13+
options.nestTables,
14+
Boolean(options.rowsAsArray),
15+
Boolean(options.supportBigNumbers || config.supportBigNumbers),
16+
Boolean(options.bigNumberStrings || config.bigNumberStrings),
17+
typeof options.typeCast,
18+
options.timezone || config.timezone,
19+
Boolean(options.decimalNumbers),
20+
options.dateStrings,
21+
];
22+
2123
for (let i = 0; i < fields.length; ++i) {
2224
const field = fields[i];
23-
res += `/${field.name}:${field.columnType}:${field.length}:${field.schema}:${field.table}:${field.flags}:${field.characterSet}`;
25+
26+
res.push([
27+
field.name,
28+
field.columnType,
29+
field.length,
30+
field.schema,
31+
field.table,
32+
field.flags,
33+
field.characterSet,
34+
]);
2435
}
25-
return res;
36+
37+
return JSON.stringify(res, null, 0);
2638
}
2739

2840
function getParser(type, fields, options, config, compiler) {
@@ -49,5 +61,6 @@ function clearCache() {
4961
module.exports = {
5062
getParser: getParser,
5163
setMaxCache: setMaxCache,
52-
clearCache: clearCache
64+
clearCache: clearCache,
65+
_keyFromFields: keyFromFields,
5366
};

0 commit comments

Comments
 (0)