The vulnerability is a code injection flaw in the binary-parser library, occurring when the library dynamically generates parser code. The analysis of the patch commit fd24894054136e17b405fc490c4434adec5cc3b6 reveals that user-provided strings for field names and encoding types were being interpolated directly into this generated code without proper sanitization.
Two primary vulnerable points were identified and fixed:
-
Field Name Injection: Parser-defining methods (e.g., uint8, string) accept a varName parameter that is passed to the internal setNextParser method. Previously, this method directly assigned the varName, which was then used in code generation. The patch introduces sanitizeFieldName to validate the name, fixing the vulnerability within setNextParser.
-
Encoding Parameter Injection: The string method used the encoding option without validation. The patch adds a call to sanitizeEncoding at the beginning of the string method to check the encoding against an allowlist.
An attacker could exploit this by crafting a parser with a malicious field name or by using the .string() method with a malicious encoding value, leading to arbitrary code execution. The identified functions, Parser.setNextParser and Parser.string, are the precise locations where the untrusted data was processed and where the security controls were implemented.