# Changelog

All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.

## [4.1.0](https://github.com/Psifi-Solutions/csrf-csrf/compare/v4.0.0...v4.1.0) (2026-11-01)


### Bug Fixes

* update CSRF token validation to use timing-safe comparison ([#128](https://github.com/Psifi-Solutions/csrf-csrf/issues/128)) ([b3cd9e6](https://github.com/Psifi-Solutions/csrf-csrf/commit/b3cd9e6f7eeb0580afe2370d3f3bafcbc6ed2fa1))

## [4.0.3](https://github.com/Psifi-Solutions/csrf-csrf/compare/v4.0.2...v4.0.3) (2025-05-27)

`generateCsrfToken` will now **always** check if the existing token is valid before returning it. This validation is only derived from the request cookie, this way `GET` requests are not expected to include the CSRF token to ensure token reuse, this was a bug and not the intended/expected behavior.

If the CSRF token container in the request is somehow invalid when `generateCsrfToken` is called, this will be silently ignored and a new valid CSRF token will be generated and returned. If `validateOnReuse` is set to true, an error will be thrown instead.

### Bug Fixes

* validateOnReuse incorrectly throws ([26b3dd6](https://github.com/Psifi-Solutions/csrf-csrf/commit/26b3dd61307ad7588fdc6f20118dfc64fc039f0b))

## [4.0.2](https://github.com/Psifi-Solutions/csrf-csrf/compare/v4.0.0...v4.0.2) (2025-05-09)


### Bug Fixes

* broken type exports ([8967de6](https://github.com/Psifi-Solutions/csrf-csrf/commit/8967de6814045e88caf1a7aa4bb8730e32b4d6d2))

## [4.0.1](https://github.com/Psifi-Solutions/csrf-csrf/compare/v4.0.0...v4.0.1) (2025-05-08)


### Bug Fixes

* correctly skip CSRF token validation when validateOnReuse is false ([bcaf1c3](https://github.com/Psifi-Solutions/csrf-csrf/commit/bcaf1c3f1568cebbfd8d48c2324d5d9b8f3811eb))

## [4.0.0](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.7...v4.0.0) (2025-04-27)


### ⚠ BREAKING CHANGES

This list may not be an exhaustive list of breaking changes, for more information consult the [version 3 -> 4 upgrade guide](./UPGRADING.md#version-3---4) and the updated configuration documentation in the [README](./README.md).

* Token generation now uses `createHmac`, the format has changed significantly, see the [CSRF token format](./UPGRADING.md#csrf-token-format-has-changed) section of the upgrade guide.
* `getSessionIdentifier` is now required and must return a unique identifier per-request (and per-session) - this is an essential part of CSRF token security
* `getTokenFromRequest` renamed to `getCsrfTokenFromRequest`
* `generateToken` renamed to `generateCsrfToken`
* `overwrite` and `validateOnReuse` parameters for `generateCsrfToken` have been merged into a single object parameter which also accepts `cookieOptions`: `generateCsrfToken(req, res, options);`
* Default value for `validateOnReuse` is now `false`
* Default value for `cookieOptions.sameSite` is now `strict`
* `cookieOptions.signed` is no longer available, CSRF tokens are inherently signed, this is redundant
* `delimiter` option removed, `csrfTokenDelimiter` and `messageDelimiter` are now used for the respective purpose
* `signed` option in `cookieOptions` config option removed (redundant), csrf tokens generated by csrf-csrf are inherently signed 
* `size` config option now sets the size of the message used to construct the hmac, now defaults to `32` instead of `64`, this is combined with the return value of `getSessionIdentifier` to construct the hmac payload
* Type `CsrfTokenCookieOverrides` renamed to `CsrfTokenCookieOptions`
* Type `CsrfTokenCreator` renamed to `CsrfTokenGenerator`
* Type `doubleCsrfProtection` renamed to `DoubleCsrfProtection`
* Type `RequestMethod` renamed to `CsrfRequestMethod`
* Type `CsrfIgnoredMethods` renamed to `CsrfIgnoredRequestMethods`

### Features

* change default value of sameSite to 'strict' ([ba5973e](https://github.com/Psifi-Solutions/csrf-csrf/commit/ba5973e44ddf7fdf0baeff038855f7307a5a1cd9))
* change validateOnReuse to false by default ([5fc62a9](https://github.com/Psifi-Solutions/csrf-csrf/commit/5fc62a98b797a7e1bc81a5d98a1c0509e1de4e76))
* expose per token cookie settings ([#60](https://github.com/Psifi-Solutions/csrf-csrf/issues/60)) ([456b317](https://github.com/Psifi-Solutions/csrf-csrf/commit/456b3179eac02deeb90cd7112f7ddbd6377c9758))
* **types:** add CsrfTokenGeneratorRequestUtil type ([72fd659](https://github.com/Psifi-Solutions/csrf-csrf/commit/72fd659f7e8ee9e82e820b1da9c393c4864dc43d))
* use hmac to generate csrf tokens ([e4c5ec3](https://github.com/Psifi-Solutions/csrf-csrf/commit/e4c5ec3ec0dc801ef0fca2ef89e1e4ff79f85aad))

### [3.2.2](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.2.1...v3.2.2) (2025-04-24)


### Bug Fixes

* **types:** fix incorrect type for Request#csrfToken ([cf3dfe2](https://github.com/Psifi-Solutions/csrf-csrf/commit/cf3dfe20ccb14ac4c428dd2897ffe7420295693a)), closes [#95](https://github.com/Psifi-Solutions/csrf-csrf/issues/95)

### [3.2.1](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.2.0...v3.2.1) (2025-04-20)

No changes, just re-published the botched 3.2.0

## [3.2.0](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.1.0...v3.2.0) (2025-04-20)


### Features

* add optional skipCsrfProtection callback config option ([d3f8123](https://github.com/Psifi-Solutions/csrf-csrf/commit/d3f81230353244c937c4c597006f2d6c64a4a671))

## [3.1.0](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.7...v3.1.0) (2024-11-25)


### Features

* re-allow httpOnly override ([e6f2543](https://github.com/Psifi-Solutions/csrf-csrf/commit/e6f25431743ae415a94568db823fd47e9cd90545))
* support custom delimiter for cookie value separation ([59d84a1](https://github.com/Psifi-Solutions/csrf-csrf/commit/59d84a151b4ede65d9a5e859c47de1645c76cfa2))

### [3.0.8](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.7...v3.0.8) (2024-09-23)

* No changes, release issue on 3.0.7

## [3.0.7](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.6...v3.0.7) (2024-09-21)

* Marked >= 3.0.7 as security supported version

### Features

* support optional stateless association of token with session ([710d2f6](https://github.com/Psifi-Solutions/csrf-csrf/commit/710d2f6082f1ac8ab884b10913b1b86195f86bd2))

Added the `getSessionIdentifier` parameter to the `csrf-csrf` configuration. By providing the `getSessionIdentifier` callback, generated tokens will only be valid for the original session identifier they were generated for.

For example: (req) => req.session.id

The token will now be signed with the session id included, this means a generated CSRF token will only be valid for the session it was generated for. This also means that if you rotate your sessions (which you should) you will also need to generate a new CSRF token for the session after rotating it.

### [3.0.6](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.5...v3.0.6) (2024-05-17)

* No changes, just a bump to fix broken release

### [3.0.5](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.4...v3.0.5) (2024-05-15)


### Bug Fixes

* ensure types are correctly exported ([a07ff81](https://github.com/Psifi-Solutions/csrf-csrf/commit/a07ff815724811ae8530886d5d947b2e8112e60c))

### [3.0.4](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.3...v3.0.4) (2024-04-03)


### Features

* allow customizable error ([#58](https://github.com/Psifi-Solutions/csrf-csrf/issues/58)) ([24ec3ab](https://github.com/Psifi-Solutions/csrf-csrf/commit/24ec3abba4911c91b2c37b6ea42acbca10d5d9f6))

## [3.0.3](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.1...v3.0.3) (2023-12-16)


### Bug Fixes

* improve CommonJS TypeScript support ([a9dfbb7](https://github.com/Psifi-Solutions/csrf-csrf/commit/a9dfbb7dd85cafebac68827d9d93a4996163356f))
* remove duplicate string in union type RequestMethod ([4e9f344](https://github.com/Psifi-Solutions/csrf-csrf/commit/4e9f344ea288beaa278c7121248a297bac6ac2a3))

### [3.0.2](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.1...v3.0.2) (2023-11-05)


### Features

* support multiple secrets (backwards compatible) ([51da818](https://github.com/Psifi-Solutions/csrf-csrf/commit/51da818ef1dfb729b894457e4316e028df0b380f))


### Bug Fixes

* accept validateOnGeneration param in req.csrfToken ([0d6187a](https://github.com/Psifi-Solutions/csrf-csrf/commit/0d6187a9c31ea13b73127774ae6f01bd96baf3dc))
* picking a secret in generateTokenAndHash ([2b4f540](https://github.com/Psifi-Solutions/csrf-csrf/commit/2b4f540bb93e92440a91cc2c53265e96c84a23c1))
* typing in CsrfTokenCreator ([8f4d03f](https://github.com/Psifi-Solutions/csrf-csrf/commit/8f4d03f24adb9f13135c9b847bd87eceb08da1d0))

### [3.0.1](https://github.com/Psifi-Solutions/csrf-csrf/compare/v3.0.0...v3.0.1) (2023-09-15)

### Bug Fixes

- types for TypeScript moduleResolution ([#32](https://github.com/Psifi-Solutions/csrf-csrf/issues/32)) ([6a5cd2c](https://github.com/Psifi-Solutions/csrf-csrf/commit/6a5cd2c43e4940577856cc08a565da79c4e1348b))

## 3.0.0 (2023-08-18)

### ⚠ BREAKING CHANGES

- Previously csrf-csrf would overwrite any existing token when calling `generateToken` or `req.csrfToken`, this is no longer the case. By default these methods will now return an existing token, making token-per-session the default behaviour. To maintain previous behaviour you will need to set the `overwrite` parameter to true when calling `generateToken` or `req.csrfToken`
- `generateToken` has had the request and response parameters swapped, you will need to update your generateToken invocations to: `generateToken(req, res)`

### Features

- enable per-session token via csrf token reuse ([2f1f8cd](https://github.com/Psifi-Solutions/csrf-csrf/commit/2f1f8cd68e9d74cca38b16f75c4f37c4047d8270))
- swap generateToken request and response parameter order ([54f6c06](https://github.com/Psifi-Solutions/csrf-csrf/commit/54f6c06b975f2c1e32c6c48edaa5bc194b4d6f91))
