Skip to content

Commit fbe3008

Browse files
committed
[ci skip] Add info about json request and http header for csrf
1 parent 5025c33 commit fbe3008

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

user_guide_src/source/libraries/security.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ hidden input field for you::
6565
// Generates: <input type="hidden" name="{csrf_token}" value="{csrf_hash}" />
6666
<?= csrf_field() ?>
6767

68+
When sending a JSON request the CSRF token can also be passed as one of the parameters.
69+
The next way to pass the CSRF token is a special Http header that's name is available by
70+
``csrf_header()`` function.
71+
72+
Additionally, you can use the ``csrf_meta()`` method to generate this handy
73+
meta tag for you::
74+
75+
// Generates: <meta name="{csrf_header}" content="{csrf_hash}" />
76+
<?= csrf_meta() ?>
77+
78+
The order of checking the avability of the CSRF token is as follows:
79+
80+
- ``$_POST`` array
81+
- Http header
82+
- ``php://input`` (JSON request) - bare in mind that this approach is the slowest one since we have to decode JSON and then encode it again
83+
6884
Tokens may be either regenerated on every submission (default) or
6985
kept the same throughout the life of the CSRF cookie. The default
7086
regeneration of tokens provides stricter security, but may result

0 commit comments

Comments
 (0)