/

CVE-2026-41246

Severity:

HIGH RISK

(8.1)

Code Injection in Contour Cookie Rewriting for Envoy

CVE-2026-41246

Modified

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Remote Code Execution within Shared Envoy Infrastructure

Severity:

HIGH RISK

(8.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Contour's Cookie Rewriting feature builds Lua scripts dynamically from user-controlled HTTPProxy configuration fields without proper sanitization, enabling arbitrary Lua code injection in Envoy.

An attacker with RBAC permissions to create or modify HTTPProxy resources can craft cookie rewrite values that execute arbitrary code within the shared Envoy proxy, potentially accessing xDS credentials or disrupting other tenants.

Affected context

This vulnerability occurs in Kubernetes clusters using Contour (v1.19.0 to before v1.33.4, v1.32.5, and v1.31.6) as an ingress controller with Envoy, when the Cookie Rewriting feature is enabled or available via HTTPProxy resources.

It affects configurations where:

  • HTTPProxy resources are used to define routes, and
  • Users or services have RBAC permission to create or modify HTTPProxy manifests, and
  • spec.routes[].cookieRewritePolicies[].pathRewrite.value or

spec.routes[].services[].cookieRewritePolicies[].pathRewrite.value

can be influenced by less-trusted tenants or automation.

In such contexts, untrusted configuration values are interpolated into Lua source used by Envoy's HTTP Lua filter, creating an opportunity for code injection.

Exploit preconditions

  • Attack surface: Kubernetes API via HTTPProxy CRDs interpreted by Contour, which in turn configures Envoy's HTTP Lua filter.
  • Required access: RBAC permissions that allow creating or updating HTTPProxy resources (e.g., per-namespace ingress configuration rights).
  • Trigger point: Processing of HTTP requests on the specific route whose cookie rewrite configuration contains the malicious pathRewrite.value.
  • Why exploitation is possible:
  • Contour uses Go text/template to interpolate user-supplied fields directly into Lua script templates.
  • These values are not sufficiently sanitized or escaped for Lua syntax.
  • The resulting Lua script is executed by Envoy's HTTP Lua filter for every request on the affected route.
  • Since Envoy is shared, injected Lua code can interact with shared runtime resources, including filesystem-based xDS credentials.

Why this happens

The core issue is dynamic code generation where configuration data is treated as code, aligning with CWE-94: Improper Control of Generation of Code ('Code Injection').

Contour's Cookie Rewriting feature constructs Lua scripts that implement cookie path rewriting inside Envoy.

Instead of treating the HTTPProxy fields as opaque, data-only values, these fields are inserted directly into a Lua template using Go's text/template engine.

Without robust escaping for Lua syntax and semantics, an attacker can craft values that break out of the intended string or expression context, injecting arbitrary Lua statements.

This pattern—mixing untrusted configuration values into executable script templates—creates a generic, language-agnostic code injection risk whenever the resulting script is interpreted at runtime.

Potential impact

  • Execution of arbitrary Lua code within Envoy's HTTP Lua filter context.
  • Reading of sensitive data available to Envoy, such as xDS client credentials stored on the filesystem.
  • Denial of service against the shared Envoy instance by triggering runtime errors, infinite loops, or excessive resource consumption.
  • Interference with traffic for other routes and tenants sharing the same Envoy, including potential request manipulation or logging of cross-tenant data where accessible via the Lua environment.
  • Increased blast radius if Envoy's credentials are reused for broader control plane access, potentially enabling further configuration tampering.

General mitigation guidance

Effective mitigation focuses on preventing untrusted data from becoming executable code and reducing the trust and power of shared infrastructure:

  • Eliminate direct code generation from configuration:
  • Avoid templating full Lua programs from configuration fields; instead, map configuration values to fixed, parameterized behaviors in compiled code or strictly-bounded script fragments.
  • Use robust escaping and encoding:
  • If templating cannot be avoided, rigorously escape user-controlled values for the target language (Lua in this case), treating them strictly as string literals or constants, not as code.
  • Constrain configuration expressiveness:
  • Restrict cookie rewrite values to well-defined, validated formats (e.g., simple path strings), enforcing allowlists and length limits to reduce the chance of embedding code.
  • Apply privilege minimization:
  • Run Envoy with least-privilege filesystem and credential access, ensuring Lua code has minimal ability to read sensitive files or affect the wider control plane.
  • Segment ingress infrastructure where feasible so that high-risk tenants or namespaces do not share the exact same Envoy instances with more sensitive workloads.
  • Harden RBAC around configuration:
  • Limit HTTPProxy write permissions to trusted entities and keep ingress configuration changes under review or approval workflows when possible.

How teams detect issues like this

Detection can combine configuration analysis, code inspection, and runtime safeguards:

  • Static configuration scanning:
  • Analyze HTTPProxy manifests for suspicious cookieRewritePolicies values, such as those containing Lua syntax characters, control structures, or unusually complex strings.
  • Enforce admission control policies (e.g., using ValidatingAdmissionWebhook, OPA/Gatekeeper, Kyverno) that block unsafe patterns in cookie rewrite fields.
  • Code and template review:
  • Review any templating logic that generates scripts (Lua, JavaScript, etc.) from configuration, flagging cases where user data is inserted directly into code bodies.
  • Apply static analysis rules targeting dynamic code generation patterns and missing escaping/encoding functions.
  • Runtime monitoring:
  • Monitor Envoy logs and metrics for Lua runtime errors, abnormal request handling behavior, or spikes in resource usage associated with specific routes.
  • Use security observability tools to detect unexpected filesystem access or anomalies from Envoy containers.
  • Automated tooling:
  • Integrate security-focused linters and policy engines into CI/CD to enforce safe templating practices and configuration policies before changes reach the cluster.

Sources

SourceLink
github.comgithub.com/projectcontour/contour/releases/tag/v1.31.6
github.comgithub.com/projectcontour/contour/releases/tag/v1.32.5
github.comgithub.com/projectcontour/contour/releases/tag/v1.33.4
github.comgithub.com/projectcontour/contour/security/advisories/GHSA-x4mj-7f9g-29h4
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-41246
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2461257
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-41246.json

Frequently asked

questions

Not directly by arbitrary external users. Exploitation requires the ability to define or modify HTTPProxy resources. However, once a malicious configuration is in place, the injected code is triggered by HTTP traffic to that route, which may be accessible remotely.

The attacker must have Kubernetes RBAC permissions that allow creating or updating HTTPProxy resources in a namespace managed by Contour. This is often granted to application teams or automation that controls ingress configuration.

The safest pattern is to stop generating Lua (or any other script) directly from untrusted configuration fields. Instead, keep a fixed implementation in code and treat configuration as data-only parameters that are safely escaped, validated, and bound to predefined behaviors.

Avoid dynamic code generation from user or tenant-controlled data, enforce strict validation and encoding for all configuration that influences interpreters, minimize privileges of shared infrastructure components, and adopt policy-as-code or admission control to constrain high-risk configuration fields.

Find out what's already
exploitable in your codebase.