The vulnerability lies in the insecure construction of Lua scripts that are executed by the Envoy proxy. The analysis of the patches revealed two key functions, cookieRewriteConfig and FilterMisdirectedRequests, that were responsible for this insecure script generation.
The primary vulnerability, as described in the advisory, is within the cookieRewriteConfig function located in internal/envoy/v3/route.go. This function used Go's text/template to generate Lua code for cookie rewriting. User-controlled values for cookie path and domain rewriting were interpolated directly into the Lua script without proper escaping. The patch for this function introduced a luaStringEscape function to sanitize the user input before it is embedded into the template, thus preventing the Lua injection.
A similar issue was found in the FilterMisdirectedRequests function in internal/envoy/v3/listener.go. This function also generated a Lua script and used fmt.Sprintf to inject a hostname into the script. This was also an injection vector. The patch for this function removed the dynamic string formatting altogether, opting for a static script that retrieves the necessary information at runtime in a safe way.
Both of these functions, when exploited, could lead to arbitrary code execution in the context of the Envoy proxy, allowing an attacker to access sensitive information or cause a denial of service. Therefore, both cookieRewriteConfig and FilterMisdirectedRequests are considered vulnerable functions that would appear in a runtime profile during exploitation.