This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-xdp-quic-anti-amplification-guardrail

XDP Stateless Token Verification for QUIC Connection Migration Anti-Amplification

Enforces stateless cryptographic token verification and strict RFC 9000 3x anti-amplification accounting directly in the eBPF/XDP driver layer prior to socket buffer allocation. Prevents asymmetric UDP reflection and amplification attacks during QUIC connection migration by dropping unauthenticated path probe floods before kernel networking stack ingress.

Prohibited Anti-Pattern: Bypassing Kernel Bypass Filters to Validate QUIC Migration Handshakes in User-Space

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: XDP Stateless Token Verification for QUIC Connection Migration Anti-Amplification - Enforces stateless cryptographic token verification and strict RFC 9000 3x anti-amplification accounting directly in the eBPF/XDP driver layer prior to socket buffer allocation. Prevents asymmetric UDP reflection and amplification attacks during QUIC connection migration by dropping unauthenticated path probe floods before kernel networking stack ingress.
globs: bpf/**/*.c, bpf/**/*.h, src/bpf/**/*.c, src/ebpf/**/*.rs, pkg/ebpf/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-xdp-quic-anti-amplification-guardrail"
---

# XDP Stateless Token Verification for QUIC Connection Migration Anti-Amplification

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Bypassing Kernel Bypass Filters to Validate QUIC Migration Handshakes in User-Space

## System Constraints
You are a Principal Software Architect and Linux Kernel/eBPF Security Specialist enforcing production-grade XDP fast-path invariants. Mandate that all QUIC connection migration packets from unverified endpoints undergo stateless cryptographic validation and RFC 9000 3x anti-amplification accounting directly within XDP drivers before socket allocation or XDP_PASS propagation.

## Strict Guidelines
- Engineers MUST ALWAYS verify cryptographic stateless migration tokens (e.g., SipHash-2-4 or AES-based HMAC embedded in the DCID) directly in the XDP ingress hook prior to returning XDP_PASS.
- Engineers MUST NOT delegate unvalidated QUIC connection migration path validation to user-space runtimes without hardware/driver-level ingress rate limiting.
- Code MUST strictly verify verifier packet bounds (data + offset <= data_end) before dereferencing any QUIC header byte or Destination Connection ID (DCID).
- Services MUST track ingress byte volume per unvalidated 4-tuple using BPF per-CPU LRU maps and enforce the RFC 9000 3x egress anti-amplification ceiling.
- Components NEVER issue PATH_RESPONSE or large response payloads to unvalidated paths if cumulative ingress on the migrated endpoint has not established proof-of-ownership.
- Programs MUST emit bpf_ringbuf or perf telemetry events immediately upon dropping spoofed migration probes to trigger fast-path edge filtering.

## Bad vs Good Implementations
### eBPF/XDP QUIC Migration Token & Anti-Amplification Guardrail

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The BPF program unconditionally passes QUIC packets to the kernel network stack (allocating sk_buff structures and socket buffers). Migrated connections with spoofed source IPs allow attackers to launch multi-gigabit asymmetric amplification attacks by forcing the QUIC user-space server to generate out-of-order PATH_RESPONSE or retransmission payloads.
```c
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <bpf/bpf_helpers.h>

// ANTI-PATTERN: Forwards all QUIC packets to socket layer regardless of migration state.
// An attacker can spoof source IP on connection migration packets, triggering large
// user-space QUIC responses (e.g., PATH_CHALLENGE / PATH_RESPONSE / MTU probes),
// turning the host into a massive UDP amplification reflector.
SEC("xdp")
int xdp_quic_ingress(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx->data;
    void *data_end = (void *)(long)ctx->data_end;
    struct ethhdr *eth = data;

    if ((void *)(eth + 1) > data_end)
        return XDP_PASS;
    if (eth->h_proto != __builtin_bswap16(ETH_P_IP))
        return XDP_PASS;

    struct iphdr *ip = (void *)(eth + 1);
    if ((void *)(ip + 1) > data_end)
        return XDP_PASS;
    if (ip->protocol != IPPROTO_UDP)
        return XDP_PASS;

    struct udphdr *udp = (void *)(ip + 1);
    if ((void *)(udp + 1) > data_end)
        return XDP_PASS;

    // Insecure pass-through: allocates sk_buff and delegates anti-amplification to user-space
    if (udp->dest == __builtin_bswap16(443)) {
        return XDP_PASS;
    }
    return XDP_PASS;
}

char _license[] SEC("license") = "GPL";
```

#### Production Standard (Correct)
> **Standard**: Validates the cryptographic token in the QUIC Destination Connection ID (DCID) directly in the XDP ingress hook. For unconfirmed or migrated endpoints, it tracks ingress byte volume using a high-performance BPF LRU map and immediately drops spoofed packets that exceed RFC 9000 anti-amplification thresholds before allocating kernel socket buffers or passing bytes to user-space.
```c
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <bpf/bpf_helpers.h>

#define QUIC_DCID_MAX_LEN 20
#define TOKEN_MAGIC 0x51554943 // 'QUIC'

struct quic_flow_key {
    __u32 saddr;
    __u16 sport;
    __u16 pad;
};

struct quic_flow_stats {
    __u64 rx_bytes;
    __u64 tx_bytes;
    __u64 last_seen_ns;
};

struct {
    __uint(type, BPF_MAP_TYPE_LRU_HASH);
    __uint(max_entries, 65536);
    __type(key, struct quic_flow_key);
    __type(value, struct quic_flow_stats);
} migration_accounting SEC(".maps");

static __always_inline __u32 verify_stateless_dcid_token(const __u8 *dcid, __u8 len) {
    if (len < 8)
        return 0;
    // Verify stateless authentication tag generated during previous validated path
    __u32 magic = *(__u32 *)dcid;
    return (magic == __builtin_bswap32(TOKEN_MAGIC)) ? 1 : 0;
}

SEC("xdp")
int xdp_quic_anti_amplification(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx->data;
    void *data_end = (void *)(long)ctx->data_end;

    struct ethhdr *eth = data;
    if ((void *)(eth + 1) > data_end)
        return XDP_DROP;
    if (eth->h_proto != __builtin_bswap16(ETH_P_IP))
        return XDP_PASS;

    struct iphdr *ip = (void *)(eth + 1);
    if ((void *)(ip + 1) > data_end)
        return XDP_DROP;
    if (ip->protocol != IPPROTO_UDP)
        return XDP_PASS;

    struct udphdr *udp = (void *)(ip + 1);
    if ((void *)(udp + 1) > data_end)
        return XDP_DROP;
    if (udp->dest != __builtin_bswap16(443))
        return XDP_PASS;

    __u8 *quic_payload = (__u8 *)(udp + 1);
    if ((void *)(quic_payload + 1) > data_end)
        return XDP_DROP;

    __u8 first_byte = *quic_payload;
    // Short header (1-RTT migration packet): Bit 7 is 0
    if ((first_byte & 0x80) == 0) {
        __u8 *dcid = quic_payload + 1;
        if ((void *)(dcid + 8) > data_end)
            return XDP_DROP;

        // Stateless verification before allowing migration
        if (!verify_stateless_dcid_token(dcid, 8)) {
            // Track unvalidated 4-tuple to enforce RFC 9000 Section 8 (3x amplification limit)
            struct quic_flow_key key = {
                .saddr = ip->saddr,
                .sport = udp->source,
                .pad = 0
            };
            __u32 pkt_len = (__u32)((long)data_end - (long)data);
            struct quic_flow_stats *stats = bpf_map_lookup_elem(&migration_accounting, &key);
            if (stats) {
                // Drop if ingress quota violates 3x anti-amplification without verified token
                if (stats->tx_bytes > (stats->rx_bytes * 3)) {
                    return XDP_DROP;
                }
                __sync_fetch_and_add(&stats->rx_bytes, pkt_len);
            } else {
                struct quic_flow_stats initial = { .rx_bytes = pkt_len, .tx_bytes = 0, .last_seen_ns = bpf_ktime_get_ns() };
                bpf_map_update_elem(&migration_accounting, &key, &initial, BPF_ANY);
            }
        }
    }
    return XDP_PASS;
}

char _license[] SEC("license") = "Dual BSD/GPL";
```

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: XDP Stateless Token Verification for QUIC Connection Migration Anti-Amplification

XDP Stateless Token Verification for QUIC Connection Migration Anti-Amplification defines an industrial-grade behavioral standard for devops engineering. Enforces stateless cryptographic token verification and strict RFC 9000 3x anti-amplification accounting directly in the eBPF/XDP driver layer prior to socket buffer allocation. Prevents asymmetric UDP reflection and amplification attacks during QUIC connection migration by dropping unauthenticated path probe floods before kernel networking stack ingress. 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: Bypassing Kernel Bypass Filters to Validate QUIC Migration Handshakes in User-Space 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 DriftBypassing Kernel Bypass Filters to Validate QUIC Migration Handshakes in User-SpaceCritical
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 verify cryptographic stateless migration tokens (e.g., SipHash-2-4 or AES-based HMAC embedded in the DCID) directly in the XDP ingress hook prior to returning XDP_PASS.

Engineers MUST ALWAYS verify cryptographic stateless migration tokens (e.g., SipHash-2-4 or AES-based HMAC embedded in the DCID) directly in the XDP ingress hook prior to returning XDP_PASS.

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 NOT delegate unvalidated QUIC connection migration path validation to user-space runtimes without hardware/driver-level ingress rate limiting.

Engineers MUST NOT delegate unvalidated QUIC connection migration path validation to user-space runtimes without hardware/driver-level ingress rate limiting.

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

Code MUST strictly verify verifier packet bounds (data + offset <= data_end) before dereferencing any QUIC header byte or Destination Connection ID (DCID).

Code MUST strictly verify verifier packet bounds (data + offset <= data_end) before dereferencing any QUIC header byte or Destination Connection ID (DCID).

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

Services MUST track ingress byte volume per unvalidated 4-tuple using BPF per-CPU LRU maps and enforce the RFC 9000 3x egress anti-amplification ceiling.

Services MUST track ingress byte volume per unvalidated 4-tuple using BPF per-CPU LRU maps and enforce the RFC 9000 3x egress anti-amplification ceiling.

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

Components NEVER issue PATH_RESPONSE or large response payloads to unvalidated paths if cumulative ingress on the migrated endpoint has not established proof-of-ownership.

Components NEVER issue PATH_RESPONSE or large response payloads to unvalidated paths if cumulative ingress on the migrated endpoint has not established proof-of-ownership.

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

Programs MUST emit bpf_ringbuf or perf telemetry events immediately upon dropping spoofed migration probes to trigger fast-path edge filtering.

Programs MUST emit bpf_ringbuf or perf telemetry events immediately upon dropping spoofed migration probes to trigger fast-path edge filtering.

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 XDP Stateless Token Verification for QUIC Connection Migration Anti-Amplification critical for AI coding assistants?

Enforces stateless cryptographic token verification and strict RFC 9000 3x anti-amplification accounting directly in the eBPF/XDP driver layer prior to socket buffer allocation. Prevents asymmetric UDP reflection and amplification attacks during QUIC connection migration by dropping unauthenticated path probe floods before kernel networking stack ingress. 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 (Bypassing Kernel Bypass Filters to Validate QUIC Migration Handshakes in User-Space) 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

XDP