← Back to Pull requests

aperture: don't buffer the body of an h2c upgrade request #357

Closed
unknown closed this pull request without merging on Dec 03, 2026 15:16 UTC
View on GitHub
unknown unknown commented on Dec 03, 2026 10:56 UTC
Author

On plaintext listeners (insecure: true, and the Tor listener), the x/net h2c handler reads the whole body of a request that asks to upgrade to h2c into memory before it hands the request on, so it can replay it as the first HTTP/2 stream. That happens before aperture sees the request, so the body is held in full before routing, auth and rate limits apply, bounded only by the read timeout (the Tor listener has none). x/net's own docs say to limit it.

Fix


A small handler in front of the h2c handler drops the Upgrade header from a request that asks for h2c and has a body (Content-Length above 0, or chunked). The request is then served over HTTP/1 with its body read as usual. A server may ignore an Upgrade header (RFC 9110 section 7.8), and the client gets a normal response. For example, curl --http2 -d ... against http:// now gets an HTTP/1.1 response instead of switching to h2c.

Not affected:

  • A request without a body still upgrades.

  • Prior knowledge h2c, which gRPC clients use.

  • TLS listeners.
  • Tests


  • TestH2CUpgradeWithBodyIsNotBuffered: for a body with a Content-Length, a chunked body, and Content-Length: 0 with a chunked body, the handler gets the upgrade request while most of its 1 MiB body is still held back by the client, and serves it over HTTP/1. Without the fix the handler is only called once the whole body has arrived, and the test fails.

  • TestH2CUpgradeWithoutBodyUpgrades: an upgrade request without a body gets 101 Switching Protocols and is served over HTTP/2.
  • Diff: 191 lines (+143 / -48) across 2 files Reviewer: hieblmi Review duration: 259m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 191 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.315
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #357"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.9% (MEDIUM) · Higher = larger blast radius
    35.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.2% · Safe to merge
    14.2%