Do not create a file with too many permissions

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: php-security/write-file-permissions

Language: PHP

Severity: Error

Category: Security

CWE: 732

Description

This rule helps you prevent unauthorized access to your files. Granting too many permissions can expose your files to malicious activities such as unauthorized modifications, data theft, or even deletion.

The PHP chmod() function is used to change the permissions of a file. It takes two arguments: the file name and the permissions. Permissions are represented as octal numbers, where each digit represents different permissions for the owner, group, and others.

To adhere to this rule, avoid setting permissions higher than 0750. This means the owner can read, write, and execute the file, the group can read and execute, and others have no permissions. For example, chmod("test", 0750);. Be sure to only grant write permissions when necessary and restrict access for others as much as possible to ensure the security of your files.

Non-Compliant Code Examples

<?php
chmod("test", 0770);

Compliant Code Examples

<?php
chmod("test", 0750);
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis