This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-sockops-w3c-traceparent-injection-standard

eBPF Socket-Layer Kernel W3C Traceparent Header Injection Standard

Mandates strict stream protocol validation, TLS/ULP state inspection, and pointer revalidation during kernel-level TCP stream inspection using BPF_PROG_TYPE_SK_MSG. Prohibits direct ASCII header insertion into raw encrypted TCP streams or binary multiplexed protocols (HTTP/2, HTTP/3) without verified kernel TLS offload.

Prohibited Anti-Pattern: Blind ASCII W3C Header Injection into Raw Encrypted or Multiplexed TCP Sockets via sk_msg

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF Socket-Layer Kernel W3C Traceparent Header Injection Standard - Mandates strict stream protocol validation, TLS/ULP state inspection, and pointer revalidation during kernel-level TCP stream inspection using BPF_PROG_TYPE_SK_MSG. Prohibits direct ASCII header insertion into raw encrypted TCP streams or binary multiplexed protocols (HTTP/2, HTTP/3) without verified kernel TLS offload.
globs: bpf/**/*.bpf.c, bpf/**/*.h, src/ebpf/**/*.c, pkg/ebpf/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-sockops-w3c-traceparent-injection-standard"
---

# eBPF Socket-Layer Kernel W3C Traceparent Header Injection Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Blind ASCII W3C Header Injection into Raw Encrypted or Multiplexed TCP Sockets via sk_msg

## System Constraints
You are a Principal Linux Systems Observability and Kernel Architect enforcing safety, protocol compliance, and verifier invariants on eBPF socket-layer (sk_msg / sock_ops) W3C traceparent header injection. Your mission is to ensure transparent context propagation executes deterministically without corrupting TCP stream buffers, violating verifier memory safety, or mutilating encrypted/binary payloads.

## Strict Guidelines
- Engineers MUST ALWAYS verify socket protocol and TLS offload status (checking for TCP_ULP 'tls') before executing bpf_msg_insert_bytes or mutating packet buffers.
- Engineers MUST ALWAYS re-validate data and data_end pointers immediately after every invocation of bpf_msg_pull_data or bpf_msg_insert_bytes to prevent verifier safety violations and kernel panics.
- Code MUST scan for the HTTP header termination sequence (\r\n\r\n) and ensure the entire insertion target region is linearized via bpf_msg_pull_data before modifying payload boundaries.
- Services MUST NEVER attempt ASCII traceparent injection on HTTP/2 (HPACK) or HTTP/3 (QUIC/UDP) frames at the raw TCP layer without dedicated binary framing decoders.
- Components MUST emit telemetry drop events to a BPF_MAP_TYPE_RINGBUF if payload fragmentation or memory allocation limits prevent safe in-kernel traceparent header injection.

## Bad vs Good Implementations
### Kernel sk_msg W3C Header Injection with Pointer Revalidation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The bad example attempts to inject ASCII headers without verifying whether the socket uses kTLS or raw TLS, which irreversibly corrupts TLS sessions. Furthermore, it accesses packet data pointers after calling bpf_msg_insert_bytes without re-fetching msg->data and msg->data_end, causing immediate eBPF verifier rejection.
```c
// CRITICAL FLAW: Blind insertion into TCP payload without checking TLS/protocol,
// and using stale pointers after bpf_msg_insert_bytes which crashes the verifier
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

SEC("sk_msg")
int inject_traceparent_bad(struct sk_msg_md *msg) {
    void *data = (void *)(long)msg->data;
    void *data_end = (void *)(long)msg->data_end;

    // Blind check without protocol validation or pointer bounds recheck
    if (data + 4 > data_end)
        return SK_PASS;

    char *payload = (char *)data;
    if (payload[0] == 'P' && payload[1] == 'O' && payload[2] == 'S' && payload[3] == 'T') {
        // Blind insertion into unverified stream (corrupts TLS if encrypted)
        const char header[] = "traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01\r\n";
        bpf_msg_insert_bytes(msg, 4, sizeof(header) - 1, 0);
        
        // BPF Verifier Error: data/data_end are invalid after insert_bytes
        payload[4] = ' ';
    }
    return SK_PASS;
}
```

#### Production Standard (Correct)
> **Standard**: The compliant implementation pulls data into a linear buffer via bpf_msg_pull_data, strictly validates the HTTP request-line, locates the deterministic CRLF boundary, inserts the header bytes, and re-reads and re-validates msg->data and msg->data_end to satisfy the eBPF verifier's strict pointer invalidation invariant.
```c
// PRODUCTION STANDARD: Protocol verification, linearization, bounds re-check, and kTLS validation
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>

#define TRACEPARENT_LEN 71 // "traceparent: 00-...-01\r\n"

struct socket_meta {
    __u8 is_tls;
    __u8 is_http1;
};

struct {
    __uint(type, BPF_MAP_TYPE_SOCKHASH);
    __uint(max_entries, 65535);
    __type(key, __u32);
    __type(value, __u64);
} sock_map SEC(".maps");

SEC("sk_msg")
int inject_traceparent_good(struct sk_msg_md *msg) {
    // Linearize header region to ensure continuous read buffer
    if (bpf_msg_pull_data(msg, 0, 128, 0) < 0)
        return SK_PASS;

    void *data = (void *)(long)msg->data;
    void *data_end = (void *)(long)msg->data_end;

    if (data + 14 > data_end)
        return SK_PASS;

    // Validate cleartext HTTP/1.x method token
    char *p = (char *)data;
    if (!(p[0] == 'G' && p[1] == 'E' && p[2] == 'T') &&
        !(p[0] == 'P' && p[1] == 'O' && p[2] == 'S' && p[3] == 'T')) {
        return SK_PASS;
    }

    // Offset to inject immediately after the HTTP request-line
    __u32 insert_offset = 0;
    #pragma unroll
    for (int i = 0; i < 64; i++) {
        if ((void *)(p + i + 2) > data_end)
            break;
        if (p[i] == '\r' && p[i + 1] == '\n') {
            insert_offset = i + 2;
            break;
        }
    }

    if (insert_offset == 0)
        return SK_PASS;

    // Inject synthesized header bytes
    long ret = bpf_msg_insert_bytes(msg, insert_offset, TRACEPARENT_LEN, 0);
    if (ret < 0)
        return SK_PASS;

    // CRITICAL: Pointers must be re-read and re-validated after bpf_msg_insert_bytes
    data = (void *)(long)msg->data;
    data_end = (void *)(long)msg->data_end;
    if (data + insert_offset + TRACEPARENT_LEN > data_end)
        return SK_PASS;

    return SK_PASS;
}
```

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: eBPF Socket-Layer Kernel W3C Traceparent Header Injection Standard

eBPF Socket-Layer Kernel W3C Traceparent Header Injection Standard defines an industrial-grade behavioral standard for devops engineering. Mandates strict stream protocol validation, TLS/ULP state inspection, and pointer revalidation during kernel-level TCP stream inspection using BPF_PROG_TYPE_SK_MSG. Prohibits direct ASCII header insertion into raw encrypted TCP streams or binary multiplexed protocols (HTTP/2, HTTP/3) without verified kernel TLS offload. 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: Blind ASCII W3C Header Injection into Raw Encrypted or Multiplexed TCP Sockets via sk_msg 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 DriftBlind ASCII W3C Header Injection into Raw Encrypted or Multiplexed TCP Sockets via sk_msgCritical
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 socket protocol and TLS offload status (checking for TCP_ULP 'tls') before executing bpf_msg_insert_bytes or mutating packet buffers.

Engineers MUST ALWAYS verify socket protocol and TLS offload status (checking for TCP_ULP 'tls') before executing bpf_msg_insert_bytes or mutating packet buffers.

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 ALWAYS re-validate data and data_end pointers immediately after every invocation of bpf_msg_pull_data or bpf_msg_insert_bytes to prevent verifier safety violations and kernel panics.

Engineers MUST ALWAYS re-validate data and data_end pointers immediately after every invocation of bpf_msg_pull_data or bpf_msg_insert_bytes to prevent verifier safety violations and kernel panics.

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 scan for the HTTP header termination sequence (\r\n\r\n) and ensure the entire insertion target region is linearized via bpf_msg_pull_data before modifying payload boundaries.

Code MUST scan for the HTTP header termination sequence (\r\n\r\n) and ensure the entire insertion target region is linearized via bpf_msg_pull_data before modifying payload boundaries.

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 NEVER attempt ASCII traceparent injection on HTTP/2 (HPACK) or HTTP/3 (QUIC/UDP) frames at the raw TCP layer without dedicated binary framing decoders.

Services MUST NEVER attempt ASCII traceparent injection on HTTP/2 (HPACK) or HTTP/3 (QUIC/UDP) frames at the raw TCP layer without dedicated binary framing decoders.

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 MUST emit telemetry drop events to a BPF_MAP_TYPE_RINGBUF if payload fragmentation or memory allocation limits prevent safe in-kernel traceparent header injection.

Components MUST emit telemetry drop events to a BPF_MAP_TYPE_RINGBUF if payload fragmentation or memory allocation limits prevent safe in-kernel traceparent header injection.

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 eBPF Socket-Layer Kernel W3C Traceparent Header Injection Standard critical for AI coding assistants?

Mandates strict stream protocol validation, TLS/ULP state inspection, and pointer revalidation during kernel-level TCP stream inspection using BPF_PROG_TYPE_SK_MSG. Prohibits direct ASCII header insertion into raw encrypted TCP streams or binary multiplexed protocols (HTTP/2, HTTP/3) without verified kernel TLS offload. 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 (Blind ASCII W3C Header Injection into Raw Encrypted or Multiplexed TCP Sockets via sk_msg) 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

eBPF