Skip to content

Commit 952f6aa

Browse files
committed
Allow set token config in antiCsrf service
1 parent 000c71c commit 952f6aa

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

guide/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ Anti-CSRF Config Options
345345
'default' => [
346346
'enabled' => true,
347347
'token_name' => 'csrf_token',
348+
'token_bytes_length' => 8,
349+
'generate_token_function' => 'base64_encode',
348350
'session_instance' => 'default',
349351
'request_instance' => 'default',
350352
],
@@ -361,6 +363,18 @@ token_name
361363

362364
Sets the token name. The default is ``csrf_token``.
363365

366+
token_bytes_length
367+
""""""""""""""""""
368+
369+
Sets the length of random bytes used to generate the token. The default is
370+
``8``.
371+
372+
generate_token_function
373+
"""""""""""""""""""""""
374+
375+
Sets the function to generate the token. Available values are:
376+
``base64_encode``, ``bin2hex``, ``md5``. The default is ``base64_encode``.
377+
364378
session_instance
365379
""""""""""""""""
366380

src/App.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,11 @@ protected static function setAntiCsrf(string $instance) : AntiCSRF
663663
{
664664
$config = static::config()->get('antiCsrf', $instance);
665665
static::session($config['session_instance'] ?? 'default');
666-
$service = new AntiCSRF(static::request($config['request_instance'] ?? 'default'));
666+
$service = new AntiCSRF(
667+
static::request($config['request_instance'] ?? 'default'),
668+
$config['token_bytes_length'] ?? null,
669+
$config['generate_token_function'] ?? null,
670+
);
667671
if (isset($config['token_name'])) {
668672
$service->setTokenName($config['token_name']);
669673
}

tests/configs/antiCsrf.config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
'default' => [
1212
'enabled' => false,
1313
'token_name' => 'csrf_token',
14+
'token_bytes_length' => 8,
15+
'generate_token_function' => 'base64_encode',
1416
],
1517
];

0 commit comments

Comments
 (0)