# insecure-cookie

Rule `sonarjs/insecure-cookie`. Cookies should have the "secure" flag

- 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: #1227 by reach, #528 by growth

## Linters

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

## Code examples

### Correct: the rule accepts this

```js
let session = cookieSession({
  secure: true,// Compliant
});  // Compliant
```

```js
const express = require('express');
const session = require('express-session');

let app = express();
app.use(session({
  cookie:
  {
    secure: true // Compliant
  }
}));
```

```js
let cookies = new Cookies(req, res, { keys: keys });

cookies.set('LastVisit', new Date().toISOString(), {
  secure: true // Compliant
}); // Compliant
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/insecure-cookie": "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/index-of-compare-to-positive-number](https://lintradar.dev/rules/sonarjs/index-of-compare-to-positive-number.md): "indexOf" checks should not be for positive numbers
- [sonarjs/insecure-jwt-token](https://lintradar.dev/rules/sonarjs/insecure-jwt-token.md): JWT should be signed and verified with strong cipher algorithms
- [sonarjs/inconsistent-function-call](https://lintradar.dev/rules/sonarjs/inconsistent-function-call.md): Functions should be called consistently with or without "new"
- [sonarjs/inverted-assertion-arguments](https://lintradar.dev/rules/sonarjs/inverted-assertion-arguments.md): Assertion arguments should be passed in the correct order
- [sonarjs/in-operator-type-error](https://lintradar.dev/rules/sonarjs/in-operator-type-error.md): "in" should not be used with primitive types
- [sonarjs/jsx-no-leaked-render](https://lintradar.dev/rules/sonarjs/jsx-no-leaked-render.md): React components should not render non-boolean condition values

---

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