Skip to content

Commit 6ffe395

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: Minor tweaks [Security] Add `tokenSource` parameter for CSRF token validation sources
2 parents fd82b50 + 004620e commit 6ffe395

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

security/csrf.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,27 @@ array, the attribute is ignored for that request, and no CSRF validation occurs:
321321
// ... delete the object
322322
}
323323

324+
You can also choose where the CSRF token is read from using the ``tokenSource``
325+
parameter. This is a bitfield that allows you to combine different sources:
326+
327+
* ``IsCsrfTokenValid::SOURCE_PAYLOAD`` (default): request payload (POST body / json)
328+
* ``IsCsrfTokenValid::SOURCE_QUERY``: query string
329+
* ``IsCsrfTokenValid::SOURCE_HEADER``: request header
330+
331+
Example::
332+
333+
#[IsCsrfTokenValid(
334+
'delete-item',
335+
tokenKey: 'token',
336+
tokenSource: IsCsrfTokenValid::SOURCE_PAYLOAD | IsCsrfTokenValid::SOURCE_QUERY
337+
)]
338+
public function delete(Post $post): Response
339+
{
340+
// ... delete the object
341+
}
342+
343+
The token is checked against each selected source, and validation fails if none match.
344+
324345
CSRF Tokens and Compression Side-Channel Attacks
325346
------------------------------------------------
326347

0 commit comments

Comments
 (0)