What are the potential security implications of setting custom HTTP headers in PHP?

Setting custom HTTP headers in PHP can potentially introduce security vulnerabilities if not properly sanitized. Attackers could inject malicious code into the headers, leading to cross-site scripting (XSS) attacks or other security exploits. To mitigate this risk, always validate and sanitize user input before setting custom headers.

// Sanitize user input before setting custom headers
$customHeader = filter_var($_POST['custom_header'], FILTER_SANITIZE_STRING);

header("Custom-Header: " . $customHeader);