Mail Header Manipulation

ID

php.mail_header_manipulation

Severity

high

Resource

Injection

Language

Php

Tags

CWE:93, NIST.SP.800-53, OWASP:2021:A3, PCI-DSS:6.5.1

Description

Improper neutralization of CRLF sequences sent as SMTP header ('Mail Header Manipulation')

Rationale

Mail Header Manipulation focuses specifically on manipulating the headers of an email, such as "To", "From", "Subject", etc. This allows attackers to forge emails or modify headers in a way to facilitate attacks like spam or phishing.

If an application allows user input to alter 'From' or 'To' fields without sanitization or validation, an attacker could manipulate header fields to craft fraudulent emails

For example, consider the following PHP code snippet:

<?php
    $subject = $_GET['subject'];
    @mail( "destination@myorg.com", "[Subject: " . $subject . "]", $body ); // FLAW
?>
php

Remediation

To remediate Mail Header Manipulation vulnerabilities follow these practical steps:

  1. Input Validation and Sanitization: Rigorously validate user inputs. Ensure they conform to expected patterns and remove any potentially dangerous characters or sequences.

  2. Escape Shell Inputs: If executing mail-related shell commands is necessary, ensure all user inputs are correctly escaped to prevent injection. However, this is still risky and should be avoided if possible.

  3. Dependency Updates: Ensure that libraries and tools related to email handling in your application are up to date with the latest security patches and recommendations.

  4. Security Reviews and Automated Testing: Incorporate security reviews and SAST into your development lifecycle to identify and address Mail Command Injection vulnerabilities early.

By adopting these practices, you can mitigate the risk of Mail Content Injection in your applications and enhance the security posture of your email handling processes.

Configuration

The detector has the following configurable parameters:

  • sources, that indicates the source kinds to check.

  • neutralizations, that indicates the neutralization kinds to check.

Unless you need to change the default behavior, you typically do not need to configure this detector.