Skip to content

Commit 694fee5

Browse files
author
Greg Bowler
committed
feature: configure csrf token sharing
closes #389
1 parent 04b319d commit 694fee5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

config.default.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ csrf_header=X-CSRF
5454
csrf_ignore_path=
5555
csrf_max_tokens=100
5656
csrf_token_length=10
57+
;Generate tokens once "per-form" or once "per-page"
58+
csrf_token_sharing=per-page

src/Middleware/RequestHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,12 @@ public function handle(
233233
$csrfTokenStore->verify($_POST);
234234
}
235235

236+
$sharing = match($this->config->getString("security.csrf_token_sharing")) {
237+
"per-page" => HTMLDocumentProtector::ONE_TOKEN_PER_PAGE,
238+
default => HTMLDocumentProtector::ONE_TOKEN_PER_FORM,
239+
};
236240
$protector = new HTMLDocumentProtector($viewModel, $csrfTokenStore);
237-
$tokens = $protector->protect(HTMLDocumentProtector::ONE_TOKEN_PER_FORM);
241+
$tokens = $protector->protect($sharing);
238242
$response = $response->withHeader($this->config->getString("security.csrf_header"), $tokens);
239243
}
240244
}

0 commit comments

Comments
 (0)