Sc header injection

From ersinkoc/security-check · View interactive version

Sc header injection is an AI agent skill from the GitHub repository ersinkoc/security-check. HTTP Header Injection and Response Splitting detection via CRLF injection in headers

How to use this skill

Skill file

SC: HTTP Header Injection / Response Splitting

Purpose

Detects HTTP header injection vulnerabilities where user-controlled input is placed into HTTP response headers without CRLF character sanitization, enabling response splitting, cookie injection, cache poisoning, and XSS via injected headers. Also covers Host header injection used in password reset poisoning.

Activation

Called by sc-orchestrator during Phase 2 when HTTP response handling is detected.

Phase 1: Discovery

File Patterns to Search

**/*.py, **/*.js, **/*.ts, **/*.go, **/*.php, **/*.java, **/*.cs,
**/controllers/*, **/routes/*, **/handlers/*, **/middleware/*,
**/*redirect*, **/*header*, **/*cookie*, **/*response*

Keyword Patterns to Search

# Setting response headers with potential user input
"res.setHeader(", "res.header(", "response.addHeader(",
"response.setHeader(", "w.Header().Set(", "header(",
"Response.Headers.Add(", "Response.Cookies.Append(",
"Set-Cookie", "Location:", "Content-Disposition",

# Redirect with user input
"res.redirect(", "response.sendRedirect(", "redirect(",
"HttpResponse(.*status=302", "http.Redirect(",
"Response.Redirect("

# Host header usage
"request.getHeader(\"Host\")", "req.headers.host", "req.Host",
"$_SERVER['HTTP_HOST']", "request.META['HTTP_HOST']"

Vulnerability Pattern: CRLF in Headers

// VULNERABLE: User input in Set-Cookie header
app.get('/lang', (req, res) => {
  res.setHeader('Set-Cookie', `lang=${req.query.lang}`);
  // Attack: ?lang=en%0d%0aSet-Cookie:%20admin=true
  // Injects additional header
});

// SAFE: Validate/encode header values
app.get('/lang', (req, res) => {
  const lang = req.query.lang.replace(/[\r\n]/g, '');
  res.setHeader('Set-Cookie', `lang=${encodeURIComponent(lang)}`);
});

Host Header Injection

# VULNERABLE: Using Host header for password reset URL
def password_reset(request):
    host = request.META['HTTP_HOST']  # Attacker-controlled!
    reset_url = f"https://{host}/reset?token={token}"
    send_email(user.email, f"Reset here: {reset_url}")

# SAFE: Use configured server name
def password_reset(request):
    reset_url = f"https://{settings.ALLOWED_HOSTS[0]}/reset?token={token}"

Content-Disposition Injection

// VULNERABLE: User filename in Content-Disposition
func download(w http.ResponseWriter, r *http.Request) {
    filename := r.URL.Query().Get("file")
    w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filename))
    // Attack: ?file=test%0d%0aContent-Type:%20text/html%0d%0a%0d%0a<script>alert(1)</script>
}

// SAFE: Sanitize filename
filename = strings.Map(func(r rune) rune {
    if r == '\r' || r == '\n' || r == '"' { return -1 }
    return r
}, filename)
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))

Phase 2: Verification

Modern Framework Protections

Most modern HTTP libraries and frameworks reject CRLF characters in header values:

However: Some configurations, proxies, or older versions may not enforce this.

Sanitization Check

  1. Are \r and \n stripped from user input before header insertion?
  2. Is the value URL-encoded or otherwise escaped?
  3. Does the HTTP framework/server reject CRLF in headers?

Severity Classification

Output Format

Finding: HDR-{NNN}

Common False Positives

  1. Modern frameworks — Node.js 14+, Go, ASP.NET Core, Tomcat 7+ reject CRLF automatically
  2. Static header values — headers set from constants or configuration, not user input
  3. Content-Type headers — typically set by framework based on response type, not user input
  4. Framework redirect methods — res.redirect() in Express URL-encodes the location
  5. Reverse proxy normalization — nginx/Apache strip malformed headers before they reach the app
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.