Skip to content

Commit

Permalink
Merge pull request #15293 from craftcms/feature/no-cache-csrf-on-get
Browse files Browse the repository at this point in the history
Don't cache responses if getCsrfToken is called
  • Loading branch information
brandonkelly authored Jul 4, 2024
2 parents 3c6df36 + f14c6b4 commit 427fabe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft CMS 4

## Unreleased

- Craft now sends no-cache headers for any request that calls `craft\web\Request::getCsrfToken()`. ([#15293](https://github.com/craftcms/cms/pull/15293), [#15281](https://github.com/craftcms/cms/pull/15281))

## 4.10.4 - 2024-07-02

- 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))
Expand Down
3 changes: 3 additions & 0 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,9 @@ protected function loadRawCookies(): array
*/
public function getCsrfToken($regenerate = false): string
{
// Ensure the response is not cached by the browser or static cache proxies.
Craft::$app->getResponse()->setNoCacheHeaders();

if (!isset($this->_craftCsrfToken) || $regenerate) {
$token = $this->loadCsrfToken();

Expand Down

0 comments on commit 427fabe

Please sign in to comment.