---
title: Do not create a file with too many permissions
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Do not create a file with too many permissions
---

# Do not create a file with too many permissions

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `php-security/write-file-permissions`

**Language:** PHP

**Severity:** Error

**Category:** Security

**CWE**: [732](https://cwe.mitre.org/data/definitions/732.html)

**Related CWEs**:

- [276](https://cwe.mitre.org/data/definitions/276.html)
- [281](https://cwe.mitre.org/data/definitions/281.html)
- [766](https://cwe.mitre.org/data/definitions/766.html)

## Description{% #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{% #non-compliant-code-examples %}

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

## Compliant Code Examples{% #compliant-code-examples %}

```php
<?php
chmod("test", 0750);
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 