liveBook · Manning

Header sanitization

As explained in AI Agents for Offensive Security

The process of removing or masking secret values in HTTP headers while retaining non-sensitive header metadata.

Header sanitization removes sensitive response-header values before findings are persisted. It preserves header names and non-sensitive metadata, retaining evidence of what a server returned without placing reusable secrets in logs or report artifacts. section 4.3.3

Sanitize at the boundary between live collection and durable storage:

  • Inspect each header key case-insensitively. section 4.3.3
  • Replace values for Set-Cookie-prefixed headers, Authorization, and X-API-Key with [redacted]. section 4.3.3
  • Keep all other values and every original header name for operational context. section 4.3.3
Listing 4.9 Header sanitization
 
def sanitize_headers(headers: Dict[str, str]) -> Dict[str, str]:
    """Remove obviously sensitive header values before persisting."""
    redacted = {}
    for k, v in headers.items():
        lk = k.lower()
        if lk.startswith("set-cookie") or lk in {"authorization", "x-api-key"}:
            redacted[k] = "[redacted]"
        else:
            redacted[k] = v
    return redacted

A small dictionary transformation applies explicit key-based redaction before output is saved. section 4.3.3

Treat raw headers as useful live-scan observations but unsafe durable artifacts: cookies, authorization tokens, and API keys can become liabilities once written to disk. section 4.3.3

How AI Agents for Offensive Security covers it

How deep it goes
Implements explicit dictionary-level redaction rules and preserves names, without describing broader secret detection.
Examples
Redacts Set-Cookie, Authorization, and X-API-Key values as [redacted].
What it assumes
Assumes response headers have already been collected into a string dictionary.
What you can do after
Apply it via a sanitization function before persisting collected response headers.
How it connects
Connects HTTPS HEAD probing, passive reconnaissance, Artifact records, and JSONL output.

This explainer was generated by Manning's knowledge graph from the text of AI Agents for Offensive Security. The section links point to the parts of the book it draws on.