Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use IsCsrfTokenValid Attribute #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
seb-jean wants to merge 1 commit into symfony:main
base: main
Choose a base branch
Loading
from seb-jean:iscsrftokenvalid-attribute
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: Use IsCsrfTokenValid Attribute
  • Loading branch information
seb-jean committed Feb 21, 2025
commit 340cee0b45866e04151b92a10d6463b8a2df2bcc
11 changes: 3 additions & 8 deletions src/Controller/Admin/BlogController.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Requirement\Requirement;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
use Symfony\Component\Security\Http\Attribute\IsCsrfTokenValid;
use Symfony\Component\Security\Http\Attribute\IsGranted;

/**
Expand Down Expand Up @@ -159,15 +160,9 @@ public function edit(Request $request, Post $post, EntityManagerInterface $entit
*/
#[Route('/{id:post}/delete', name: 'admin_post_delete', requirements: ['id' => Requirement::POSITIVE_INT], methods: ['POST'])]
#[IsGranted('delete', subject: 'post')]
public function delete(Request $request, Post $post, EntityManagerInterface $entityManager): Response
#[IsCsrfTokenValid('delete', tokenKey: 'token')]
public function delete(Post $post, EntityManagerInterface $entityManager): Response
{
/** @var string|null $token */
$token = $request->getPayload()->get('token');

if (!$this->isCsrfTokenValid('delete', $token)) {
return $this->redirectToRoute('admin_post_index', [], Response::HTTP_SEE_OTHER);
}

// Delete the tags associated with this blog post. This is done automatically
// by Doctrine, except for SQLite (the database used in this application)
// because foreign key support is not enabled by default in SQLite
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /