Skip to content

Commit de48c55

Browse files
committed
feature #19254 Add #[IsCsrfTokenValid] attribute (yguedidi)
This PR was merged into the 7.1 branch. Discussion ---------- Add `#[IsCsrfTokenValid]` attribute closes #19251 I'm not that good at copywriting, so here an attempt to at least mention the new attribute in the doc 🙂 Commits ------- 566fdd0 IsCsrfTokenValid documentation
2 parents 66d4b5b + 566fdd0 commit de48c55

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

security/csrf.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ method to check its validity::
164164
}
165165
}
166166

167+
Alternatively you can use the
168+
:class:`Symfony\\Component\\Security\\Http\\Attribute\\IsCsrfTokenValid`
169+
attribute on the controller action::
170+
171+
use Symfony\Component\HttpFoundation\Request;
172+
use Symfony\Component\HttpFoundation\Response;
173+
use Symfony\Component\Security\Http\Attribute\IsCsrfTokenValid;
174+
// ...
175+
176+
#[IsCsrfTokenValid('delete-item', tokenKey: 'token')]
177+
public function delete(Request $request): Response
178+
{
179+
// ... do something, like deleting an object
180+
}
181+
182+
.. versionadded:: 7.1
183+
184+
The :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsCsrfTokenValid`
185+
attribute was introduced in Symfony 7.1.
186+
167187
CSRF Tokens and Compression Side-Channel Attacks
168188
------------------------------------------------
169189

0 commit comments

Comments
 (0)