Leakage of sensitive data in dynamic file generation

Description

Writing sensitive data to static files, such as logs, backups, or data exports, can lead to unintended data exposure. Be vigilant against instances where your code may inadvertently save sensitive information in a format that could be accessed by unauthorized parties.

Remediations

  • Do not write sensitive data directly to static files without considering the security implications. This includes personal user information like emails and addresses.
    foreach ($users as $user) {
    fputcsv($csvFile, [$user['email'], $user['address']]); // unsafe
    }
  • Do ensure that if writing sensitive data to files is a requirement, such actions are thoroughly documented. Include the file's location and the rationale for storing sensitive data in this manner, adhering to your organization's internal policies.

Associated CWE

OWASP Top 10

Configuration

To skip this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --skip-rule=php_lang_file_generation

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=php_lang_file_generation