Skip to content

Commit

Permalink
Merge pull request #15281 from craftcms/feature/no-cache-csrf
Browse files Browse the repository at this point in the history
Ensure response is not cached when generating a CSRF token
  • Loading branch information
brandonkelly authored Jul 2, 2024
2 parents 63c9cf4 + 8ec36b0 commit 0e1a998
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Craft now sends no-cache headers for any request that generates a CSRF token. ([#15281](https://github.com/craftcms/cms/pull/15281), [verbb/formie#1963](https://github.com/verbb/formie/issues/1963))
- Fixed a JavaScript error that occurred when creating a new custom element source, preventing the Default Sort and Default Table Columns fields from showing up.
- Fixed a bug where the control panel was getting asynchronous CSRF inputs if the `asyncCsrfInputs` config setting was enabled.
- Fixed a bug where Craft’s Twig implementation wasn’t respecting sandboxing rules for object properties. ([#15278](https://github.com/craftcms/cms/issues/15278))
Expand Down
3 changes: 3 additions & 0 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,9 @@ public function resolve(): array
*/
protected function generateCsrfToken(): string
{
// Ensure the response is not cached by the browser or static cache proxies.
Craft::$app->getResponse()->setNoCacheHeaders();

$existingToken = $this->loadCsrfToken();

// They have an existing CSRF token.
Expand Down

0 comments on commit 0e1a998

Please sign in to comment.