Do not create a file with too many permissions

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

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

PREVIEWING: may/unit-testing