# content-length

Rule `sonarjs/content-length`. HTTP request content length should be limited

- 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: #1196 by reach, #497 by growth

## Linters

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

## Code examples

### Correct: the rule accepts this

```js
const form = new Formidable();
form.maxFileSize = 8000000; // Compliant: 8MB
```

```js
let diskUpload = multer({
  storage: diskStorage,
  limits: {
     fileSize: 8000000 // Compliant: 8MB
  }
});
```

```js
let jsonParser = bodyParser.json(); // Compliant, when the limit is not defined, the default value is set to 100kb
let urlencodedParser = bodyParser.urlencoded({ extended: false, limit: "2mb" }); // Compliant
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/content-length": "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/constructor-for-side-effects](https://lintradar.dev/rules/sonarjs/constructor-for-side-effects.md): Objects should not be created to be dropped immediately without being used
- [sonarjs/content-security-policy](https://lintradar.dev/rules/sonarjs/content-security-policy.md): Content security policy fetch directives should not be disabled
- [sonarjs/concise-regex](https://lintradar.dev/rules/sonarjs/concise-regex.md): Regular expression quantifiers and character classes should be used concisely
- [sonarjs/cookie-no-httponly](https://lintradar.dev/rules/sonarjs/cookie-no-httponly.md): Cookies should have the "HttpOnly" flag
- [sonarjs/comma-or-logical-or-case](https://lintradar.dev/rules/sonarjs/comma-or-logical-or-case.md): Comma and logical OR operators should not be used in switch cases
- [sonarjs/cors](https://lintradar.dev/rules/sonarjs/cors.md): Cross-Origin Resource Sharing (CORS) policy should be restricted to trusted origins

---

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