This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: go-http3-quic-early-data-anti-replay-invariant

Go 1.24 HTTP/3 QUIC 0-RTT Anti-Replay Window & Early Data Invariant

Enforces cryptographic strike registers and strict RFC 8470 idempotency fences on QUIC 0-RTT (Early Data) handshakes in Go 1.24 HTTP/3 servers. Non-idempotent HTTP verbs (POST, PUT, PATCH, DELETE) arriving via 0-RTT MUST be rejected immediately with HTTP 425 Too Early to prevent replay-induced state corruption. Safe idempotent requests MUST be evaluated against a bounded anti-replay sliding window strike register.

Prohibited Anti-Pattern: Permitting Unvalidated QUIC 0-RTT Early Data on State-Mutating Chi Handlers Exposing Endpoints to Packet Replay Attacks

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Go 1.24 HTTP/3 QUIC 0-RTT Anti-Replay Window & Early Data Invariant - Enforces cryptographic strike registers and strict RFC 8470 idempotency fences on QUIC 0-RTT (Early Data) handshakes in Go 1.24 HTTP/3 servers. Non-idempotent HTTP verbs (POST, PUT, PATCH, DELETE) arriving via 0-RTT MUST be rejected immediately with HTTP 425 Too Early to prevent replay-induced state corruption. Safe idempotent requests MUST be evaluated against a bounded anti-replay sliding window strike register.
globs: **/server/**/*.go, **/router/**/*.go, **/middleware/**/*.go, **/transport/**/*.go, **/cmd/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/go-http3-quic-early-data-anti-replay-invariant"
---

# Go 1.24 HTTP/3 QUIC 0-RTT Anti-Replay Window & Early Data Invariant

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Permitting Unvalidated QUIC 0-RTT Early Data on State-Mutating Chi Handlers Exposing Endpoints to Packet Replay Attacks

## System Constraints
You are a Principal Security Architect enforcing the Go 1.24 HTTP/3 QUIC 0-RTT Anti-Replay Window Invariant. In HTTP/3 over QUIC (RFC 9000, RFC 9114, RFC 8470), 0-RTT early data packets do not provide forward secrecy and are inherently vulnerable to on-wire replay attacks by passive-active network adversaries. You MUST ensure that any Go 1.24 HTTP/3 listener using Chi explicitly restricts early data. Mutating verbs (POST, PUT, PATCH, DELETE) MUST be failed fast with HTTP status 425 (Too Early) instructing the client to retransmit over 1-RTT. Idempotent requests must be validated against a cryptographic strike register or monotonic replay cache.

## Strict Guidelines
- Engineers MUST ALWAYS implement a Chi middleware fence that inspects whether the request arrived via QUIC 0-RTT early data.
- Engineers MUST NOT allow non-safe/mutating HTTP methods (POST, PUT, PATCH, DELETE) to execute within a 0-RTT early data context.
- Middleware MUST emit HTTP Status Code 425 ('Too Early') immediately when a mutating verb or duplicate strike token is observed in early data.
- Engineers MUST configure tls.Config.ClientSessionCache and QUIC strike registers with bounded memory TTLs to invalidate recorded ClientHello nonces across server instances.
- If a request contains header 'Early-Data: 1' or TLS state indicates EarlyData, the handler MUST verify idempotency or delegate to 1-RTT completion before mutating databases or transactional state.

## Bad vs Good Implementations
### Go 1.24 HTTP/3 Chi Router 0-RTT Replay Vulnerability vs Strike-Register Defense

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The HTTP/3 server accepts QUIC 0-RTT connections by default when session resumption is enabled, but does not check if incoming requests arrived via early data. An adversary can replay the 0-RTT Initial and 0-RTT Protected packets containing the POST /api/v1/payments payload, executing multiple credit charges before the TLS 1-RTT key exchange finalizes.
```go
package transport

import (
	"net/http"
	"github.com/go-chi/chi/v5"
	"github.com/quic-go/quic-go/http3"
)

func MountRoutes(r *chi.Mux) {
	// VULNERABILITY: Enabling 0-RTT on the HTTP/3 server without
	// guarding mutating endpoints allows network adversaries to replay
	// captured 0-RTT QUIC packets and duplicate payment transactions.
	r.Post("/api/v1/payments", func(w http.ResponseWriter, r *http.Request) {
		// Direct processing of mutating logic on early data!
		w.WriteHeader(http.StatusCreated)
		w.Write([]byte(`{"status":"charged"}`))
	})
}

func RunServer(r *chi.Mux) error {
	srv := &http3.Server{
		Addr:    ":443",
		Handler: r,
	}
	return srv.ListenAndServeTLS("cert.pem", "key.pem")
}
```

#### Production Standard (Correct)
> **Standard**: The middleware intercepts QUIC 0-RTT requests using TLS early data indicators and RFC 8470 headers. Any non-idempotent mutating verb (POST, PUT, PATCH, DELETE) arriving via 0-RTT is rejected with HTTP 425 (StatusTooEarly), forcing the client to retransmit after the full 1-RTT TLS handshake is finalized. Safe early data is fenced via an in-memory strike register.
```go
package transport

import (
	"crypto/subtle"
	"net/http"
	"sync"
	"time"
	"github.com/go-chi/chi/v5"
	"github.com/quic-go/quic-go/http3"
)

// AntiReplayRegister maintains a bounded time-window strike register
type AntiReplayRegister struct {
	mu      sync.Mutex
	strikes map[string]time.Time
	ttl     time.Duration
}

func NewAntiReplayRegister(ttl time.Duration) *AntiReplayRegister {
	return &AntiReplayRegister{
		strikes: make(map[string]time.Time),
		ttl:     ttl,
	}
}

func (reg *AntiReplayRegister) RecordOrReject(strikeToken string) bool {
	reg.mu.Lock()
	defer reg.mu.Unlock()
	now := time.Now()
	// Evict expired tokens
	for k, exp := range reg.strikes {
		if now.After(exp) {
			delete(reg.strikes, k)
		}
	}
	if _, exists := reg.strikes[strikeToken]; exists {
		return false // Replay detected!
	}
	reg.strikes[strikeToken] = now.Add(reg.ttl)
	return true
}

// EarlyDataGuard enforces RFC 8470 and RFC 9114 replay fences
func EarlyDataGuard(reg *AntiReplayRegister) func(http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			isEarly := r.TLS != nil && (r.TLS.EarlyData || r.Header.Get("Early-Data") == "1")
			if isEarly {
				// RFC 8470 Section 5.2: Mutating methods MUST NOT be processed in early data
				switch r.Method {
				case http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete:
					w.Header().Set("Retry-After", "0")
					http.Error(w, "Too Early: Retransmit over 1-RTT", http.StatusTooEarly)
					return
				}
				// For safe GET/HEAD requests in 0-RTT, enforce strike register token
				token := r.Header.Get("Idempotency-Key")
				if token != "" && !reg.RecordOrReject(token) {
					http.Error(w, "Replay Detected", http.StatusTooEarly)
					return
				}
			}
			next.ServeHTTP(w, r)
		})
	}
}

func MountSafeRoutes(r *chi.Mux, reg *AntiReplayRegister) {
	r.Use(EarlyDataGuard(reg))
	r.Post("/api/v1/payments", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusCreated)
		w.Write([]byte(`{"status":"charged"}`))
	})
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Go 1.24 HTTP/3 QUIC 0-RTT Anti-Replay Window & Early Data Invariant

Go 1.24 HTTP/3 QUIC 0-RTT Anti-Replay Window & Early Data Invariant defines an industrial-grade behavioral standard for security engineering. Enforces cryptographic strike registers and strict RFC 8470 idempotency fences on QUIC 0-RTT (Early Data) handshakes in Go 1.24 HTTP/3 servers. Non-idempotent HTTP verbs (POST, PUT, PATCH, DELETE) arriving via 0-RTT MUST be rejected immediately with HTTP 425 Too Early to prevent replay-induced state corruption. Safe idempotent requests MUST be evaluated against a bounded anti-replay sliding window strike register. 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: Permitting Unvalidated QUIC 0-RTT Early Data on State-Mutating Chi Handlers Exposing Endpoints to Packet Replay Attacks 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 DriftPermitting Unvalidated QUIC 0-RTT Early Data on State-Mutating Chi Handlers Exposing Endpoints to Packet Replay AttacksCritical
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 implement a Chi middleware fence that inspects whether the request arrived via QUIC 0-RTT early data.

Engineers MUST ALWAYS implement a Chi middleware fence that inspects whether the request arrived via QUIC 0-RTT early data.

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 allow non-safe/mutating HTTP methods (POST, PUT, PATCH, DELETE) to execute within a 0-RTT early data context.

Engineers MUST NOT allow non-safe/mutating HTTP methods (POST, PUT, PATCH, DELETE) to execute within a 0-RTT early data context.

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

Middleware MUST emit HTTP Status Code 425 ('Too Early') immediately when a mutating verb or duplicate strike token is observed in early data.

Middleware MUST emit HTTP Status Code 425 ('Too Early') immediately when a mutating verb or duplicate strike token is observed in early data.

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

Engineers MUST configure tls.Config.ClientSessionCache and QUIC strike registers with bounded memory TTLs to invalidate recorded ClientHello nonces across server instances.

Engineers MUST configure tls.Config.ClientSessionCache and QUIC strike registers with bounded memory TTLs to invalidate recorded ClientHello nonces across server instances.

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

If a request contains header 'Early-Data

If a request contains header 'Early-Data: 1' or TLS state indicates EarlyData, the handler MUST verify idempotency or delegate to 1-RTT completion before mutating databases or transactional state.

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 Go 1.24 HTTP/3 QUIC 0-RTT Anti-Replay Window & Early Data Invariant critical for AI coding assistants?

Enforces cryptographic strike registers and strict RFC 8470 idempotency fences on QUIC 0-RTT (Early Data) handshakes in Go 1.24 HTTP/3 servers. Non-idempotent HTTP verbs (POST, PUT, PATCH, DELETE) arriving via 0-RTT MUST be rejected immediately with HTTP 425 Too Early to prevent replay-induced state corruption. Safe idempotent requests MUST be evaluated against a bounded anti-replay sliding window strike register. 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 (Permitting Unvalidated QUIC 0-RTT Early Data on State-Mutating Chi Handlers Exposing Endpoints to Packet Replay Attacks) 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

Go