File tree Expand file tree Collapse file tree
user_guide_src/source/libraries Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
6884Tokens may be either regenerated on every submission (default) or
6985kept the same throughout the life of the CSRF cookie. The default
7086regeneration of tokens provides stricter security, but may result
You can’t perform that action at this time.
0 commit comments