The vulnerability CVE-2026-4800 in lodash's _.template function stems from insufficient input validation and an insecure object merging strategy. Specifically, the template function (exposed as _.template) was susceptible to code injection when processing untrusted input as key names within the options.imports parameter. This was due to the absence of a validation mechanism similar to the one introduced for the variable option in a previous fix (CVE-2021-23337).
Furthermore, the use of assignInWith to merge imports contributed to the vulnerability. assignInWith copies inherited enumerable properties, which meant that if Object.prototype was polluted, malicious properties could be inadvertently included in the imports object and passed to the Function() constructor, leading to arbitrary code execution.
The identified patch (commit 879aaa93132d78c2f8d20c60279da9f8b21576d6) directly addresses these issues by:
- Replacing
assignInWith with assignWith to prevent prototype pollution from affecting the imports object. assignWith only copies own enumerable properties, thus mitigating the risk from inherited malicious properties.
- Introducing explicit validation for
importsKeys using reForbiddenIdentifierChars. This check prevents key names containing characters like (, ), =, {, }, [, ], /, or whitespace, which could be used to inject code into the Function() constructor. If such characters are detected, an INVALID_TEMPL_IMPORTS_ERROR_TEXT error is thrown, preventing the malicious input from being processed.
Therefore, the template function is the core vulnerable component, as it directly processes the untrusted options.imports and previously lacked the necessary sanitization and secure merging logic.