The vulnerability exists because Envoy Gateway's controller validates Lua scripts from EnvoyExtensionPolicy resources by executing them directly, without proper sandboxing. The core of the issue is in the internal/gatewayapi/luavalidator/LuaValidator.runLua function, which, before the patch, would run user-provided Lua code using gopher-lua's DoString method in a default, unrestricted environment. This gave the script access to standard Lua libraries capable of interacting with the underlying operating system, such as io.open and os.execute.
An attacker with permissions to create or edit EnvoyExtensionPolicy resources could submit a script designed to read sensitive files from the controller's filesystem, like the Kubernetes service account token located at /var/run/secrets/kubernetes.io/serviceaccount/token. The script's output or errors, which could contain the stolen token, would then be reflected in the status of the EnvoyExtensionPolicy resource, delivering the credentials to the attacker.
The patch addresses this by implementing a Lua sandbox. A new file, security.lua, is introduced, which explicitly disables dangerous functions (os.execute, io.popen, etc.) and wraps filesystem and environment variable functions (io.open, os.getenv, etc.) to check for access to critical paths and variables. The runLua function was modified to execute this security.lua script before running any user-provided code, effectively creating a sandboxed environment. Additionally, resource limits (execution time, stack size) were added to the Lua state to prevent denial-of-service attacks. The vulnerable function is runLua, and Validate is its public-facing entry point within the validator.