This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: envoy-gateway-in-process-wasm-ratelimit

Envoy Gateway 1.2 In-Process Wasm Rate-Limiting Guardrail

Mandates in-process Wasm filter execution via Envoy Gateway 1.2 EnvoyExtensionPolicy for pre-routing rate enforcement and high-frequency traffic shedding. Prevents worker thread starvation, network hop latency penalties, and cascading microservice exhaustion during volumetric DDoS by arbitrating requests directly within the Envoy data plane memory space.

Prohibited Anti-Pattern: Delegating L7 Volumetric Throttling to External Network Hops or Application Runtimes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Envoy Gateway 1.2 In-Process Wasm Rate-Limiting Guardrail - Mandates in-process Wasm filter execution via Envoy Gateway 1.2 EnvoyExtensionPolicy for pre-routing rate enforcement and high-frequency traffic shedding. Prevents worker thread starvation, network hop latency penalties, and cascading microservice exhaustion during volumetric DDoS by arbitrating requests directly within the Envoy data plane memory space.
globs: **/gateway/**/*.yaml, **/envoy-gateway/**/*.yaml, **/k8s/**/*.yaml, **/crds/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/envoy-gateway-in-process-wasm-ratelimit"
---

# Envoy Gateway 1.2 In-Process Wasm Rate-Limiting Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Delegating L7 Volumetric Throttling to External Network Hops or Application Runtimes

## System Constraints
You are a Principal Software Architect enforcing zero-latency, pre-routing traffic arbitration in Envoy Gateway 1.2 using in-process WebAssembly (Wasm) filters. You must ensure all edge rate-limiting and DDoS mitigation policies are evaluated directly in the Envoy data plane runtime before request routing occurs, eliminating out-of-process gRPC network hops to external rate-limit services under volumetric load.

## Strict Guidelines
- Engineers MUST ALWAYS configure Wasm-based rate limiters using Envoy Gateway 1.2 `EnvoyExtensionPolicy` targeting the appropriate `Gateway` or `HTTPRoute` via `targetRef`.
- Engineers MUST configure Wasm filters to run during the early HTTP stream lifecycle (pre-routing) before authentication and backend dispatch filters execute.
- Engineers MUST NOT rely on external gRPC RateLimitService (RLS) round-trips for initial layer-7 volumetric DDoS defense, as socket saturation induces cascading Envoy worker exhaustion.
- Wasm extensions MUST specify SHA256 checksum verification (`sha256`) for remote OCI/HTTP images to guarantee runtime supply-chain integrity.
- Code MUST configure `failClosed: false` with explicit local response generation or `failClosed: true` depending on threat tier, but NEVER leave failure behavior undefined.
- Wasm modules MUST leverage thread-safe shared data structures (`proxy_shared_data`) with compare-and-swap (CAS) semantics to track sliding windows without cross-thread lock contention.

## Bad vs Good Implementations
### Envoy Gateway 1.2 Wasm Rate Limiting Policy

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The policy pulls an unpinned Wasm artifact over plaintext HTTP without SHA256 integrity verification. It lacks execution phase pinning and resource constraints, leaving downstream services vulnerable to network latency amplification and tampering.
```yaml
# Anti-Pattern: Delegating rate limiting to external gRPC service without pre-routing Wasm defense
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
  name: unprotected-backend-policy
  namespace: ingress-system
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: orders-route
  wasm:
    - name: unpinned-filter
      code:
        type: HTTP
        http:
          # CRITICAL: Missing SHA256 verification and no resource boundaries
          url: https://internal-registry.io/filters/dynamic-limiter.wasm
      # Anti-pattern: Missing deterministic fallback and execution phase control
```

#### Production Standard (Correct)
> **Standard**: Attaches a validated, OCI-sourced Wasm filter directly to the edge Gateway listener before routing. Enforces SHA256 image immutability, fail-closed isolation, and zero-network-hop token bucket arithmetic directly in Envoy memory.
```yaml
# Production-Grade: Deterministic in-process Wasm rate limiting attached to Gateway
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
  name: edge-in-process-ratelimit
  namespace: ingress-system
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: Gateway
    name: public-edge-gateway
  wasm:
    - name: fast-in-process-token-bucket
      rootID: "rate_limiter_root"
      failClosed: true
      code:
        type: Image
        image:
          url: oci://registry.infra.internal/envoy/wasm/sliding-window:v1.2.4
          sha256: 7b84f3c0519e487fa8373b75f80bcf2e4bb25244be8d1df0cf457816086701bb
      config:
        '@type': type.googleapis.com/google.protobuf.StringValue
        value: |-
          {
            "capacity": 10000,
            "refill_rate_per_sec": 2500,
            "key_extractor": "x-forwarded-for",
            "response_status_code": 429,
            "response_body": "Edge rate limit exceeded. Drop by Envoy data plane.\n"
          }
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Envoy Gateway 1.2 In-Process Wasm Rate-Limiting Guardrail

Envoy Gateway 1.2 In-Process Wasm Rate-Limiting Guardrail defines an industrial-grade behavioral standard for devops engineering. Mandates in-process Wasm filter execution via Envoy Gateway 1.2 EnvoyExtensionPolicy for pre-routing rate enforcement and high-frequency traffic shedding. Prevents worker thread starvation, network hop latency penalties, and cascading microservice exhaustion during volumetric DDoS by arbitrating requests directly within the Envoy data plane memory space. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Delegating L7 Volumetric Throttling to External Network Hops or Application Runtimes Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftDelegating L7 Volumetric Throttling to External Network Hops or Application RuntimesCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS configure Wasm-based rate limiters using Envoy Gateway 1.2 `EnvoyExtensionPolicy` targeting the appropriate `Gateway` or `HTTPRoute` via `targetRef`.

Engineers MUST ALWAYS configure Wasm-based rate limiters using Envoy Gateway 1.2 `EnvoyExtensionPolicy` targeting the appropriate `Gateway` or `HTTPRoute` via `targetRef`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST configure Wasm filters to run during the early HTTP stream lifecycle (pre-routing) before authentication and backend dispatch filters execute.

Engineers MUST configure Wasm filters to run during the early HTTP stream lifecycle (pre-routing) before authentication and backend dispatch filters execute.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT rely on external gRPC RateLimitService (RLS) round-trips for initial layer-7 volumetric DDoS defense, as socket saturation induces cascading Envoy worker exhaustion.

Engineers MUST NOT rely on external gRPC RateLimitService (RLS) round-trips for initial layer-7 volumetric DDoS defense, as socket saturation induces cascading Envoy worker exhaustion.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Wasm extensions MUST specify SHA256 checksum verification (`sha256`) for remote OCI/HTTP images to guarantee runtime supply-chain integrity.

Wasm extensions MUST specify SHA256 checksum verification (`sha256`) for remote OCI/HTTP images to guarantee runtime supply-chain integrity.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Code MUST configure `failClosed

Code MUST configure `failClosed: false` with explicit local response generation or `failClosed: true` depending on threat tier, but NEVER leave failure behavior undefined.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Wasm modules MUST leverage thread-safe shared data structures (`proxy_shared_data`) with compare-and-swap (CAS) semantics to track sliding windows without cross-thread lock contention.

Wasm modules MUST leverage thread-safe shared data structures (`proxy_shared_data`) with compare-and-swap (CAS) semantics to track sliding windows without cross-thread lock contention.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Envoy Gateway 1.2 In-Process Wasm Rate-Limiting Guardrail critical for AI coding assistants?

Mandates in-process Wasm filter execution via Envoy Gateway 1.2 EnvoyExtensionPolicy for pre-routing rate enforcement and high-frequency traffic shedding. Prevents worker thread starvation, network hop latency penalties, and cascading microservice exhaustion during volumetric DDoS by arbitrating requests directly within the Envoy data plane memory space. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Delegating L7 Volumetric Throttling to External Network Hops or Application Runtimes) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Envoy