This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-inbound-baggage-scrubbing-guardrail

OpenTelemetry Inbound W3C Baggage Scrubbing and Size Partitioning Standard

Mandates strict allowlisting, key-level length validation, and cumulative payload size partitioning for incoming W3C Baggage in distributed tracing setups. Prevents cross-tenant context injection, metadata privilege escalation, and downstream HTTP 431 (Request Header Fields Too Large) outages caused by unconstrained baggage propagation across trust boundaries.

Prohibited Anti-Pattern: Blind Inbound Baggage Passthrough Causing Header Poisoning and Downgrade Overflows

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Inbound W3C Baggage Scrubbing and Size Partitioning Standard - Mandates strict allowlisting, key-level length validation, and cumulative payload size partitioning for incoming W3C Baggage in distributed tracing setups. Prevents cross-tenant context injection, metadata privilege escalation, and downstream HTTP 431 (Request Header Fields Too Large) outages caused by unconstrained baggage propagation across trust boundaries.
globs: src/telemetry/**/*.{ts,js}, src/tracing/**/*.{ts,js}, src/middleware/**/*.{ts,js}, src/instrumentation/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-inbound-baggage-scrubbing-guardrail"
---

# OpenTelemetry Inbound W3C Baggage Scrubbing and Size Partitioning Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Blind Inbound Baggage Passthrough Causing Header Poisoning and Downgrade Overflows

## System Constraints
You are a Principal Software Architect enforcing enterprise-grade OpenTelemetry propagation security. You must ensure all inbound W3C baggage headers passing through edge proxies, APIs, and microservices are explicitly scrubbed against a zero-trust allowlist, sanitized for illegal control characters, and constrained by hard-coded byte budgets before injection into active Trace Context.

## Strict Guidelines
- Services MUST NEVER configure default `W3CBaggagePropagator` directly on edge-facing or multi-tenant entry points without a scrubbing decorator.
- Engineers MUST ALWAYS enforce a strict key allowlist (exact match or pinned regex) when extracting inbound baggage.
- Services MUST drop or reject any baggage key-value pair where the key exceeds 64 bytes or the value exceeds 256 bytes.
- The cumulative byte size of all retained baggage entries in a single request context MUST NOT exceed 2048 bytes (to defend against HTTP 431 cascading failures).
- Engineers MUST NEVER permit client-supplied headers to override immutable security claims (e.g., `tenant_id`, `account_id`, `auth_subject`) extracted from verified authentication tokens.
- Custom baggage propagators MUST validate RFC 7230 and RFC 2616 token compliance, stripping non-printable ASCII or control characters.

## Bad vs Good Implementations
### Unsanitized Baggage Propagation vs. Defensive Scrubbing Propagator

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Default W3CBaggagePropagator copies arbitrary key-value pairs from the inbound HTTP baggage header into the Active Context. Untrusted upstream clients can inject spoofed routing metadata or bloat the context, crashing downstream services with HTTP 431 errors.
```typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { CompositePropagator, W3CBaggagePropagator, W3CTraceContextPropagator } from '@opentelemetry/core';

// ANTI-PATTERN: Default propagator blindly propagates untrusted external baggage.
// Allows external attackers to inject tenant spoofing keys and saturate downstream headers (>8KB).
export const otelSdk = new NodeSDK({
  textMapPropagator: new CompositePropagator({
    propagators: [
      new W3CTraceContextPropagator(),
      new W3CBaggagePropagator(),
    ],
  }),
});
```

#### Production Standard (Correct)
> **Standard**: Decorates the standard propagator with an allowlist filter and strict byte partition limits (key, value, and cumulative total). Eliminates header bloat attacks and stops untrusted baggage keys from entering downstream trace workflows.
```typescript
import { Context, TextMapGetter, TextMapPropagator, TextMapSetter, baggageEntryMetadataSymbol, propagation } from '@opentelemetry/api';
import { W3CBaggagePropagator } from '@opentelemetry/core';

const ALLOWED_BAGGAGE_KEYS = new Set(['traffic.tier', 'feature_flags.canary', 'region.origin']);
const MAX_KEY_BYTES = 64;
const MAX_VALUE_BYTES = 256;
const MAX_TOTAL_BYTES = 2048;

export class SanitizedBaggagePropagator implements TextMapPropagator {
  private readonly delegate = new W3CBaggagePropagator();

  inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
    this.delegate.inject(context, carrier, setter);
  }

  extract(context: Context, carrier: unknown, getter: TextMapGetter): Context {
    const rawContext = this.delegate.extract(context, carrier, getter);
    const incomingBaggage = propagation.getBaggage(rawContext);
    if (!incomingBaggage) return context;

    let sanitizedBaggage = propagation.createBaggage();
    let cumulativeBytes = 0;

    for (const entry of incomingBaggage.getAllEntries()) {
      const [key, value] = entry;
      const keyBytes = Buffer.byteLength(key, 'utf8');
      const valBytes = Buffer.byteLength(value.value, 'utf8');

      if (!ALLOWED_BAGGAGE_KEYS.has(key)) continue;
      if (keyBytes > MAX_KEY_BYTES || valBytes > MAX_VALUE_BYTES) continue;
      if (cumulativeBytes + keyBytes + valBytes > MAX_TOTAL_BYTES) break;

      sanitizedBaggage = sanitizedBaggage.setEntry(key, value);
      cumulativeBytes += (keyBytes + valBytes);
    }

    return propagation.setBaggage(context, sanitizedBaggage);
  }

  fields(): string[] {
    return this.delegate.fields();
  }
}
```

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: OpenTelemetry Inbound W3C Baggage Scrubbing and Size Partitioning Standard

OpenTelemetry Inbound W3C Baggage Scrubbing and Size Partitioning Standard defines an industrial-grade behavioral standard for devops engineering. Mandates strict allowlisting, key-level length validation, and cumulative payload size partitioning for incoming W3C Baggage in distributed tracing setups. Prevents cross-tenant context injection, metadata privilege escalation, and downstream HTTP 431 (Request Header Fields Too Large) outages caused by unconstrained baggage propagation across trust boundaries. 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 Inbound Baggage Passthrough Causing Header Poisoning and Downgrade Overflows 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 Inbound Baggage Passthrough Causing Header Poisoning and Downgrade OverflowsCritical
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

Services MUST NEVER configure default `W3CBaggagePropagator` directly on edge-facing or multi-tenant entry points without a scrubbing decorator.

Services MUST NEVER configure default `W3CBaggagePropagator` directly on edge-facing or multi-tenant entry points without a scrubbing decorator.

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 enforce a strict key allowlist (exact match or pinned regex) when extracting inbound baggage.

Engineers MUST ALWAYS enforce a strict key allowlist (exact match or pinned regex) when extracting inbound baggage.

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

Services MUST drop or reject any baggage key-value pair where the key exceeds 64 bytes or the value exceeds 256 bytes.

Services MUST drop or reject any baggage key-value pair where the key exceeds 64 bytes or the value exceeds 256 bytes.

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

The cumulative byte size of all retained baggage entries in a single request context MUST NOT exceed 2048 bytes (to defend against HTTP 431 cascading failures).

The cumulative byte size of all retained baggage entries in a single request context MUST NOT exceed 2048 bytes (to defend against HTTP 431 cascading failures).

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

Engineers MUST NEVER permit client-supplied headers to override immutable security claims (e.g., `tenant_id`, `account_id`, `auth_subject`) extracted from verified authentication tokens.

Engineers MUST NEVER permit client-supplied headers to override immutable security claims (e.g., `tenant_id`, `account_id`, `auth_subject`) extracted from verified authentication tokens.

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

Custom baggage propagators MUST validate RFC 7230 and RFC 2616 token compliance, stripping non-printable ASCII or control characters.

Custom baggage propagators MUST validate RFC 7230 and RFC 2616 token compliance, stripping non-printable ASCII or control characters.

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 OpenTelemetry Inbound W3C Baggage Scrubbing and Size Partitioning Standard critical for AI coding assistants?

Mandates strict allowlisting, key-level length validation, and cumulative payload size partitioning for incoming W3C Baggage in distributed tracing setups. Prevents cross-tenant context injection, metadata privilege escalation, and downstream HTTP 431 (Request Header Fields Too Large) outages caused by unconstrained baggage propagation across trust boundaries. 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 Inbound Baggage Passthrough Causing Header Poisoning and Downgrade Overflows) 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

OpenTelemetry