This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: go-chi-http3-zero-rtt-replay-guardrail

Go 1.24+ Chi HTTP/3 0-RTT Early-Data Anti-Replay Guardrail

Enforces RFC 8470 early-data verification and rejection on state-mutating HTTP methods over QUIC/HTTP/3 in Go Chi routers to prevent 0-RTT replay vulnerabilities. Rejects unsafe requests arriving in 0-RTT early data with HTTP 425 Too Early before executing any business logic. Ensures non-idempotent operations cannot be replayed across networks by eavesdroppers capturing initial QUIC flights.

Prohibited Anti-Pattern: Allowing State-Mutating Handlers to Process QUIC 0-RTT Early Data Without HTTP 425 Rejection

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Go 1.24+ Chi HTTP/3 0-RTT Early-Data Anti-Replay Guardrail - Enforces RFC 8470 early-data verification and rejection on state-mutating HTTP methods over QUIC/HTTP/3 in Go Chi routers to prevent 0-RTT replay vulnerabilities. Rejects unsafe requests arriving in 0-RTT early data with HTTP 425 Too Early before executing any business logic. Ensures non-idempotent operations cannot be replayed across networks by eavesdroppers capturing initial QUIC flights.
globs: **/*.go, cmd/**/*.go, internal/**/*.go, pkg/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/go-chi-http3-zero-rtt-replay-guardrail"
---

# Go 1.24+ Chi HTTP/3 0-RTT Early-Data Anti-Replay Guardrail

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Allowing State-Mutating Handlers to Process QUIC 0-RTT Early Data Without HTTP 425 Rejection

## System Constraints
You are a Principal Backend Security Architect enforcing Go 1.24+ Chi HTTP/3 0-RTT Anti-Replay Mitigation. Mandate that all state-altering requests (POST, PUT, PATCH, DELETE) received during QUIC 0-RTT early data negotiation are systematically rejected with HTTP 425 (Too Early) or isolated exclusively to safe, idempotent endpoints. Ensure strict adherence to RFC 8470 and defense-in-depth idempotency key verification.

## Strict Guidelines
- Engineers MUST ALWAYS mount an RFC 8470 compliant anti-replay middleware on Chi routers handling HTTP/3 traffic prior to any business route handlers.
- Engineers MUST reject any unsafe HTTP method (POST, PUT, PATCH, DELETE) with HTTP 425 (Too Early) if the request is marked as early data (via RFC 8470 'Early-Data' header or QUIC early-data context).
- Code SHOULD enforce distributed idempotency keys (e.g., Redis SETNX with atomic TTL) for all state-mutating operations as defense-in-depth against replay bypasses.
- Services MUST NOT enable 0-RTT early data on TLS/QUIC listeners without strict router-level segregation between read-only public routes and mutating API endpoints.
- Components NEVER execute financial transactions, inventory mutations, database writes, or user state changes from requests evaluated during 0-RTT early data.

## Bad vs Good Implementations
### HTTP/3 0-RTT Early Data Anti-Replay Middleware for Chi

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The handler processes state-altering POST requests regardless of whether the request arrived via QUIC 0-RTT early data. In HTTP/3, TLS 1.3 0-RTT early data can be captured by an on-path attacker and replayed to the server, resulting in duplicated orders or unauthorized duplicate transactions.
```go
package server

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

// VULNERABLE: Chi router accepts 0-RTT early data on mutating routes without validation.
// Attackers can capture the initial QUIC packet and replay non-idempotent requests
// (e.g., fund transfers, checkout) repeatedly.
func SetupVulnerableRouter() http.Handler {
	r := chi.NewRouter()

	r.Post("/api/v1/orders/checkout", func(w http.ResponseWriter, r *http.Request) {
		// Flaw: Early-data is processed immediately, causing duplicate checkout on replay
		w.WriteHeader(http.StatusOK)
		w.Write([]byte(`{"status":"order_placed"}`))
	})

	return r
}
```

#### Production Standard (Correct)
> **Standard**: The AntiReplayZeroRTT middleware intercepts incoming requests and verifies if RFC 8470 Early-Data is present. If an unsafe HTTP method (POST, PUT, DELETE, PATCH) is received during the 0-RTT phase, it immediately responds with HTTP 425 Too Early and halts execution, forcing the QUIC client to complete the 1-RTT handshake before retrying.
```go
package server

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

// AntiReplayZeroRTT enforces RFC 8470 protection against 0-RTT replay attacks.
func AntiReplayZeroRTT(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		isEarlyData := r.Header.Get("Early-Data") == "1"
		
		// Reject non-safe methods received before TLS handshake confirmation
		if isEarlyData {
			switch strings.ToUpper(r.Method) {
			case http.MethodGet, http.MethodHead, http.MethodOptions:
				// Safe, idempotent methods are allowed in early data
				next.ServeHTTP(w, r)
				return
			default:
				// RFC 8470: Respond with 425 (Too Early) instructing client to retry after handshake
				w.Header().Set("Retry-After", "0")
				http.Error(w, "Too Early: 0-RTT rejected for state-mutating methods", http.StatusTooEarly)
				return
			}
		}

		next.ServeHTTP(w, r)
	})
}

func SetupProtectedRouter() http.Handler {
	r := chi.NewRouter()
	r.Use(AntiReplayZeroRTT)

	r.Post("/api/v1/orders/checkout", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Write([]byte(`{"status":"order_placed"}`))
	})

	return r
}
```

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: Go 1.24+ Chi HTTP/3 0-RTT Early-Data Anti-Replay Guardrail

Go 1.24+ Chi HTTP/3 0-RTT Early-Data Anti-Replay Guardrail defines an industrial-grade behavioral standard for backend engineering. Enforces RFC 8470 early-data verification and rejection on state-mutating HTTP methods over QUIC/HTTP/3 in Go Chi routers to prevent 0-RTT replay vulnerabilities. Rejects unsafe requests arriving in 0-RTT early data with HTTP 425 Too Early before executing any business logic. Ensures non-idempotent operations cannot be replayed across networks by eavesdroppers capturing initial QUIC flights. 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: Allowing State-Mutating Handlers to Process QUIC 0-RTT Early Data Without HTTP 425 Rejection 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 DriftAllowing State-Mutating Handlers to Process QUIC 0-RTT Early Data Without HTTP 425 RejectionCritical
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 mount an RFC 8470 compliant anti-replay middleware on Chi routers handling HTTP/3 traffic prior to any business route handlers.

Engineers MUST ALWAYS mount an RFC 8470 compliant anti-replay middleware on Chi routers handling HTTP/3 traffic prior to any business route handlers.

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 reject any unsafe HTTP method (POST, PUT, PATCH, DELETE) with HTTP 425 (Too Early) if the request is marked as early data (via RFC 8470 'Early-Data' header or QUIC early-data context).

Engineers MUST reject any unsafe HTTP method (POST, PUT, PATCH, DELETE) with HTTP 425 (Too Early) if the request is marked as early data (via RFC 8470 'Early-Data' header or QUIC 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

Code SHOULD enforce distributed idempotency keys (e.g., Redis SETNX with atomic TTL) for all state-mutating operations as defense-in-depth against replay bypasses.

Code SHOULD enforce distributed idempotency keys (e.g., Redis SETNX with atomic TTL) for all state-mutating operations as defense-in-depth against replay bypasses.

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 NOT enable 0-RTT early data on TLS/QUIC listeners without strict router-level segregation between read-only public routes and mutating API endpoints.

Services MUST NOT enable 0-RTT early data on TLS/QUIC listeners without strict router-level segregation between read-only public routes and mutating API endpoints.

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 execute financial transactions, inventory mutations, database writes, or user state changes from requests evaluated during 0-RTT early data.

Components NEVER execute financial transactions, inventory mutations, database writes, or user state changes from requests evaluated during 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.
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+ Chi HTTP/3 0-RTT Early-Data Anti-Replay Guardrail critical for AI coding assistants?

Enforces RFC 8470 early-data verification and rejection on state-mutating HTTP methods over QUIC/HTTP/3 in Go Chi routers to prevent 0-RTT replay vulnerabilities. Rejects unsafe requests arriving in 0-RTT early data with HTTP 425 Too Early before executing any business logic. Ensures non-idempotent operations cannot be replayed across networks by eavesdroppers capturing initial QUIC flights. 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 (Allowing State-Mutating Handlers to Process QUIC 0-RTT Early Data Without HTTP 425 Rejection) 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