# file-permissions

Rule `sonarjs/file-permissions`. File permissions should not be set to world-accessible values

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1213 by reach, #514 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/file-permissions` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2612/) |

## Code examples

### Correct: the rule accepts this

```js
const fs = require('fs');

fs.chmodSync("/tmp/fs", 0o770); // Compliant
```

```js
const fs = require('fs');
const fsPromises = fs.promises;

fsPromises.chmod("/tmp/fsPromises", 0o770); // Compliant
```

```js
const fs = require('fs');
const fsPromises = fs.promises

async function fileHandler() {
  let filehandle;
  try {
    filehandle = fsPromises.open('/tmp/fsPromises', 'r');
    filehandle.chmod(0o770); // Compliant
  } finally {
    if (filehandle !== undefined)
      filehandle.close();
  }
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/file-permissions": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/explicit-test-skip](https://lintradar.dev/rules/sonarjs/explicit-test-skip.md): Tests should be skipped explicitly
- [sonarjs/file-uploads](https://lintradar.dev/rules/sonarjs/file-uploads.md): File uploads should be restricted
- [sonarjs/existing-groups](https://lintradar.dev/rules/sonarjs/existing-groups.md): Replacement strings should reference existing regular expression groups
- [sonarjs/fixme-tag](https://lintradar.dev/rules/sonarjs/fixme-tag.md): Track uses of "FIXME" tags
- [sonarjs/encryption-secure-mode](https://lintradar.dev/rules/sonarjs/encryption-secure-mode.md): Encryption algorithms should be used with secure mode and padding scheme
- [sonarjs/for-loop-increment-sign](https://lintradar.dev/rules/sonarjs/for-loop-increment-sign.md): A "for" loop update clause should move the counter in the right direction

---

Web page: https://lintradar.dev/rules/sonarjs/file-permissions. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
