Skip to content

Commit

Permalink
Make CSRF tokens better named (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 authored Sep 16, 2024
1 parent 5aec5d8 commit e6a8ebb
Show file tree
Hide file tree
Showing 42 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function requests(Request $request): Response
#[IsGranted('ROLE_ADMIN')]
public function accept(Magazine $magazine, User $user, Request $request): Response
{
$this->validateCsrf('admin_magazine_ownership_requests_accept', $request->request->get('token'));
$this->validateCsrf('admin_magazine_ownership_requests_accept', $request->getPayload()->get('token'));

$this->manager->acceptOwnershipRequest($magazine, $user, $this->getUserOrThrow());

Expand All @@ -42,7 +42,7 @@ public function accept(Magazine $magazine, User $user, Request $request): Respon
#[IsGranted('ROLE_ADMIN')]
public function reject(Magazine $magazine, User $user, Request $request): Response
{
$this->validateCsrf('admin_magazine_ownership_requests_reject', $request->request->get('token'));
$this->validateCsrf('admin_magazine_ownership_requests_reject', $request->getPayload()->get('token'));

$this->manager->toggleOwnershipRequest($magazine, $user);

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Admin/AdminModeratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function moderators(Request $request): Response
#[IsGranted('ROLE_ADMIN')]
public function removeModerator(User $user, Request $request): Response
{
$this->validateCsrf('remove_moderator', $request->request->get('token'));
$this->validateCsrf('remove_moderator', $request->getPayload()->get('token'));

$this->manager->removeModerator($user);

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/BoostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
#[IsGranted('ROLE_USER')]
public function __invoke(VotableInterface $subject, Request $request): Response
{
$this->validateCsrf('boost', $request->request->get('token'));
$this->validateCsrf('boost', $request->getPayload()->get('token'));

$this->manager->vote(VotableInterface::VOTE_UP, $subject, $this->getUserOrThrow());

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Domain/DomainBlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
#[IsGranted('ROLE_USER')]
public function block(Domain $domain, Request $request): Response
{
$this->validateCsrf('block', $request->request->get('token'));
$this->validateCsrf('block', $request->getPayload()->get('token'));

$this->manager->block($domain, $this->getUserOrThrow());

Expand All @@ -36,7 +36,7 @@ public function block(Domain $domain, Request $request): Response
#[IsGranted('ROLE_USER')]
public function unblock(Domain $domain, Request $request): Response
{
$this->validateCsrf('block', $request->request->get('token'));
$this->validateCsrf('block', $request->getPayload()->get('token'));

$this->manager->unblock($domain, $this->getUserOrThrow());

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Domain/DomainSubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
#[IsGranted('ROLE_USER')]
public function subscribe(Domain $domain, Request $request): Response
{
$this->validateCsrf('subscribe', $request->request->get('token'));
$this->validateCsrf('subscribe', $request->getPayload()->get('token'));

$this->manager->subscribe($domain, $this->getUserOrThrow());

Expand All @@ -36,7 +36,7 @@ public function subscribe(Domain $domain, Request $request): Response
#[IsGranted('ROLE_USER')]
public function unsubscribe(Domain $domain, Request $request): Response
{
$this->validateCsrf('subscribe', $request->request->get('token'));
$this->validateCsrf('subscribe', $request->getPayload()->get('token'));

$this->manager->unsubscribe($domain, $this->getUserOrThrow());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(
EntryComment $comment,
Request $request
): Response {
$this->validateCsrf('change_adult', $request->request->get('token'));
$this->validateCsrf('change_adult', $request->getPayload()->get('token'));

$comment->isAdult = 'on' === $request->get('adult');

Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Entry/Comment/EntryCommentDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function delete(
EntryComment $comment,
Request $request
): Response {
$this->validateCsrf('entry_comment_delete', $request->request->get('token'));
$this->validateCsrf('entry_comment_delete', $request->getPayload()->get('token'));

$this->manager->delete($this->getUserOrThrow(), $comment);

Expand All @@ -50,7 +50,7 @@ public function restore(
EntryComment $comment,
Request $request
): Response {
$this->validateCsrf('entry_comment_restore', $request->request->get('token'));
$this->validateCsrf('entry_comment_restore', $request->getPayload()->get('token'));

$this->manager->restore($this->getUserOrThrow(), $comment);

Expand All @@ -68,7 +68,7 @@ public function purge(
EntryComment $comment,
Request $request
): Response {
$this->validateCsrf('entry_comment_purge', $request->request->get('token'));
$this->validateCsrf('entry_comment_purge', $request->getPayload()->get('token'));

$this->manager->purge($this->getUserOrThrow(), $comment);

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Entry/EntryChangeAdultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke(
Entry $entry,
Request $request
): Response {
$this->validateCsrf('change_adult', $request->request->get('token'));
$this->validateCsrf('change_adult', $request->getPayload()->get('token'));

$entry->isAdult = 'on' === $request->get('adult');

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Entry/EntryChangeMagazineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __invoke(
Entry $entry,
Request $request
): Response {
$this->validateCsrf('change_magazine', $request->request->get('token'));
$this->validateCsrf('change_magazine', $request->getPayload()->get('token'));

$newMagazine = $this->repository->findOneByName($request->get('change_magazine')['new_magazine']);

Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Entry/EntryDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function delete(
Entry $entry,
Request $request
): Response {
$this->validateCsrf('entry_delete', $request->request->get('token'));
$this->validateCsrf('entry_delete', $request->getPayload()->get('token'));

$this->manager->delete($this->getUserOrThrow(), $entry);

Expand All @@ -50,7 +50,7 @@ public function restore(
Entry $entry,
Request $request
): Response {
$this->validateCsrf('entry_restore', $request->request->get('token'));
$this->validateCsrf('entry_restore', $request->getPayload()->get('token'));

$this->manager->restore($this->getUserOrThrow(), $entry);

Expand All @@ -66,7 +66,7 @@ public function purge(
Entry $entry,
Request $request
): Response {
$this->validateCsrf('entry_purge', $request->request->get('token'));
$this->validateCsrf('entry_purge', $request->getPayload()->get('token'));

$this->manager->purge($this->getUserOrThrow(), $entry);

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Entry/EntryPinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __invoke(
Entry $entry,
Request $request
): Response {
$this->validateCsrf('entry_pin', $request->request->get('token'));
$this->validateCsrf('entry_pin', $request->getPayload()->get('token'));

$entry = $this->manager->pin($entry, $this->getUserOrThrow());

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/FavouriteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(private readonly GenerateHtmlClassService $classServ
#[IsGranted('ROLE_USER')]
public function __invoke(FavouriteInterface $subject, Request $request, FavouriteManager $manager): Response
{
$this->validateCsrf('favourite', $request->request->get('token'));
$this->validateCsrf('up_vote', $request->getPayload()->get('token'));

$manager->toggle($this->getUserOrThrow(), $subject);

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Magazine/MagazineBlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(private readonly MagazineManager $manager)
#[IsGranted('block', subject: 'magazine')]
public function block(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('block', $request->request->get('token'));
$this->validateCsrf('block', $request->getPayload()->get('token'));

$this->manager->block($magazine, $this->getUserOrThrow());

Expand All @@ -37,7 +37,7 @@ public function block(Magazine $magazine, Request $request): Response
#[IsGranted('block', subject: 'magazine')]
public function unblock(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('block', $request->request->get('token'));
$this->validateCsrf('block', $request->getPayload()->get('token'));

$this->manager->unblock($magazine, $this->getUserOrThrow());

Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Magazine/MagazineDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(private readonly MagazineManager $manager)
#[IsGranted('delete', subject: 'magazine')]
public function delete(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_delete', $request->request->get('token'));
$this->validateCsrf('magazine_delete', $request->getPayload()->get('token'));

$this->manager->delete($magazine);

Expand All @@ -32,7 +32,7 @@ public function delete(Magazine $magazine, Request $request): Response
#[IsGranted('delete', subject: 'magazine')]
public function restore(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_restore', $request->request->get('token'));
$this->validateCsrf('magazine_restore', $request->getPayload()->get('token'));

$this->manager->restore($magazine);

Expand All @@ -43,7 +43,7 @@ public function restore(Magazine $magazine, Request $request): Response
#[IsGranted('purge', subject: 'magazine')]
public function purge(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_purge', $request->request->get('token'));
$this->validateCsrf('magazine_purge', $request->getPayload()->get('token'));

$this->manager->purge($magazine);

Expand All @@ -54,7 +54,7 @@ public function purge(Magazine $magazine, Request $request): Response
#[IsGranted('purge', subject: 'magazine')]
public function purgeContent(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_purge_content', $request->request->get('token'));
$this->validateCsrf('magazine_purge_content', $request->getPayload()->get('token'));

$this->manager->purge($magazine, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __invoke(Magazine $magazine, Request $request): Response
throw new AccessDeniedException();
}

$this->validateCsrf('moderator_request', $request->request->get('token'));
$this->validateCsrf('moderator_request', $request->getPayload()->get('token'));

$this->manager->toggleModeratorRequest($magazine, $this->getUserOrThrow());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function toggle(Magazine $magazine, Request $request): Response
throw new AccessDeniedException();
}

$this->validateCsrf('magazine_ownership_request', $request->request->get('token'));
$this->validateCsrf('magazine_ownership_request', $request->getPayload()->get('token'));

$this->manager->toggleOwnershipRequest($magazine, $this->getUserOrThrow());

Expand All @@ -37,7 +37,7 @@ public function toggle(Magazine $magazine, Request $request): Response
#[IsGranted('ROLE_ADMIN')]
public function accept(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_ownership_request', $request->request->get('token'));
$this->validateCsrf('magazine_ownership_request', $request->getPayload()->get('token'));

$user = $this->getUserOrThrow();
$this->manager->acceptOwnershipRequest($magazine, $user, $user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(private readonly MagazineManager $manager)
#[IsGranted('ROLE_ADMIN')]
public function __invoke(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_remove_subscriptions', $request->request->get('token'));
$this->validateCsrf('magazine_remove_subscriptions', $request->getPayload()->get('token'));

$this->manager->removeSubscriptions($magazine);

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Magazine/MagazineSubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(private readonly MagazineManager $manager)
#[IsGranted('subscribe', subject: 'magazine')]
public function subscribe(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('subscribe', $request->request->get('token'));
$this->validateCsrf('subscribe', $request->getPayload()->get('token'));

$this->manager->subscribe($magazine, $this->getUserOrThrow());

Expand All @@ -37,7 +37,7 @@ public function subscribe(Magazine $magazine, Request $request): Response
#[IsGranted('subscribe', subject: 'magazine')]
public function unsubscribe(Magazine $magazine, Request $request): Response
{
$this->validateCsrf('subscribe', $request->request->get('token'));
$this->validateCsrf('subscribe', $request->getPayload()->get('token'));

$this->manager->unsubscribe($magazine, $this->getUserOrThrow());

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Magazine/Panel/MagazineBadgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function remove(
BadgeManager $manager,
Request $request
): Response {
$this->validateCsrf('badge_remove', $request->request->get('token'));
$this->validateCsrf('badge_remove', $request->getPayload()->get('token'));

$manager->delete($badge);

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Magazine/Panel/MagazineBanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function ban(Magazine $magazine, Request $request, ?User $user = null): R
#[IsGranted('moderate', subject: 'magazine')]
public function unban(Magazine $magazine, User $user, Request $request): Response
{
$this->validateCsrf('magazine_unban', $request->request->get('token'));
$this->validateCsrf('magazine_unban', $request->getPayload()->get('token'));

$this->manager->unban($magazine, $user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function remove(
Moderator $moderator,
Request $request
): Response {
$this->validateCsrf('remove_moderator', $request->request->get('token'));
$this->validateCsrf('remove_moderator', $request->getPayload()->get('token'));

$this->manager->removeModerator($moderator, $this->getUser());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function requests(Magazine $magazine, Request $request): Response
#[IsGranted('edit', subject: 'magazine')]
public function accept(Magazine $magazine, User $user, Request $request): Response
{
$this->validateCsrf('magazine_panel_moderator_request_accept', $request->request->get('token'));
$this->validateCsrf('magazine_panel_moderator_request_accept', $request->getPayload()->get('token'));

$this->manager->acceptModeratorRequest($magazine, $user, $this->getUserOrThrow());

Expand All @@ -45,7 +45,7 @@ public function accept(Magazine $magazine, User $user, Request $request): Respon
#[IsGranted('edit', subject: 'magazine')]
public function reject(Magazine $magazine, User $user, Request $request): Response
{
$this->validateCsrf('magazine_panel_moderator_request_reject', $request->request->get('token'));
$this->validateCsrf('magazine_panel_moderator_request_reject', $request->getPayload()->get('token'));

$this->manager->toggleModeratorRequest($magazine, $user);

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Magazine/Panel/MagazineReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function reportApprove(
Report $report,
Request $request
): Response {
$this->validateCsrf('report_approve', $request->request->get('token'));
$this->validateCsrf('report_approve', $request->getPayload()->get('token'));

$this->reportManager->accept($report, $this->getUserOrThrow());

Expand All @@ -65,7 +65,7 @@ public function reportReject(
Report $report,
Request $request
): Response {
$this->validateCsrf('report_decline', $request->request->get('token'));
$this->validateCsrf('report_decline', $request->getPayload()->get('token'));

$this->reportManager->reject($report, $this->getUserOrThrow());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(
PostComment $comment,
Request $request
): Response {
$this->validateCsrf('change_adult', $request->request->get('token'));
$this->validateCsrf('change_adult', $request->getPayload()->get('token'));

$comment->isAdult = 'on' === $request->get('adult');

Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Post/Comment/PostCommentDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function delete(
PostComment $comment,
Request $request
): Response {
$this->validateCsrf('post_comment_delete', $request->request->get('token'));
$this->validateCsrf('post_comment_delete', $request->getPayload()->get('token'));

$this->manager->delete($this->getUserOrThrow(), $comment);

Expand All @@ -44,7 +44,7 @@ public function restore(
PostComment $comment,
Request $request
): Response {
$this->validateCsrf('post_comment_restore', $request->request->get('token'));
$this->validateCsrf('post_comment_restore', $request->getPayload()->get('token'));

$this->manager->restore($this->getUserOrThrow(), $comment);

Expand All @@ -60,7 +60,7 @@ public function purge(
PostComment $comment,
Request $request
): Response {
$this->validateCsrf('post_comment_purge', $request->request->get('token'));
$this->validateCsrf('post_comment_purge', $request->getPayload()->get('token'));

$this->manager->purge($this->getUserOrThrow(), $comment);

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Post/PostChangeAdultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __invoke(
Post $post,
Request $request
): Response {
$this->validateCsrf('change_adult', $request->request->get('token'));
$this->validateCsrf('change_adult', $request->getPayload()->get('token'));

$post->isAdult = 'on' === $request->get('adult');

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Post/PostChangeMagazineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __invoke(
Post $post,
Request $request
): Response {
$this->validateCsrf('change_magazine', $request->request->get('token'));
$this->validateCsrf('change_magazine', $request->getPayload()->get('token'));

$newMagazine = $this->repository->findOneByName($request->get('change_magazine')['new_magazine']);

Expand Down
Loading

0 comments on commit e6a8ebb

Please sign in to comment.