# encryption-secure-mode

Rule `sonarjs/encryption-secure-mode`. Encryption algorithms should be used with secure mode and padding scheme

- 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: #1210 by reach, #511 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
crypto.createCipheriv("AES-128-CBC", key, iv); // Noncompliant: CBC with PKCS5/7 (set by default) is vulnerable to oracle padding attacks
crypto.createCipheriv("AES-128-ECB", key, ""); // Noncompliant: ECB doesn't provide serious message confidentiality
```

### Correct: the rule accepts this

```js
crypto.createCipheriv("AES-256-GCM", key, iv);
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/encryption-secure-mode": "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/empty-string-repetition](https://lintradar.dev/rules/sonarjs/empty-string-repetition.md): Repeated patterns in regular expressions should not match the empty string
- [sonarjs/existing-groups](https://lintradar.dev/rules/sonarjs/existing-groups.md): Replacement strings should reference existing regular expression groups
- [sonarjs/dynamically-constructed-templates](https://lintradar.dev/rules/sonarjs/dynamically-constructed-templates.md): Templates should not be constructed dynamically
- [sonarjs/explicit-test-skip](https://lintradar.dev/rules/sonarjs/explicit-test-skip.md): Tests should be skipped explicitly
- [sonarjs/duplicates-in-character-class](https://lintradar.dev/rules/sonarjs/duplicates-in-character-class.md): Character classes in regular expressions should not contain the same character twice
- [sonarjs/file-permissions](https://lintradar.dev/rules/sonarjs/file-permissions.md): File permissions should not be set to world-accessible values

---

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