Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

SSRF / IDOR fixes (#984)

Dave Earley04be1086bf95
diff --git a/backend/app/Http/Actions/Orders/GetOrderAction.php b/backend/app/Http/Actions/Orders/GetOrderAction.php
index 0d399caca..694703790 100644
--- a/backend/app/Http/Actions/Orders/GetOrderAction.php
+++ b/backend/app/Http/Actions/Orders/GetOrderAction.php
@@ -4,8 +4,10 @@ namespace HiEvents\Http\Actions\Orders;
use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\EventDomainObject;
+use HiEvents\DomainObjects\Generated\OrderDomainObjectAbstract;
use HiEvents\DomainObjects\OrderItemDomainObject;
use HiEvents\DomainObjects\QuestionAndAnswerViewDomainObject;
+use HiEvents\Exceptions\ResourceNotFoundException;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Repository\Eloquent\Value\OrderAndDirection;
use HiEvents\Repository\Eloquent\Value\Relationship;
@@ -22,6 +24,9 @@ class GetOrderAction extends BaseAction
$this->orderRepository = $orderRepository;
}
+ /**
+ * @throws ResourceNotFoundException
+ */
public function __invoke(int $eventId, int $orderId): JsonResponse
{
$this->isActionAuthorized($eventId, EventDomainObject::class);
@@ -32,7 +37,14 @@ class GetOrderAction extends BaseAction
->loadRelation(new Relationship(domainObject: QuestionAndAnswerViewDomainObject::class, orderAndDirections: [
new OrderAndDirection(order: 'question_id'),
]))
- ->findById($orderId);
+ ->findFirstWhere([
+ OrderDomainObjectAbstract::ID => $orderId,
+ OrderDomainObjectAbstract::EVENT_ID => $eventId,
+ ]);
+
+ if ($order === null) {
+ throw new ResourceNotFoundException(__('Order not found'));
+ }
return $this->resourceResponse(OrderResource::class, $order);
}
diff --git a/backend/app/Http/Actions/Questions/GetQuestionAction.php b/backend/app/Http/Actions/Questions/GetQuestionAction.php
index 6701e7ce3..6859f9549 100644
--- a/backend/app/Http/Actions/Questions/GetQuestionAction.php
+++ b/backend/app/Http/Actions/Questions/GetQuestionAction.php
@@ -3,7 +3,9 @@
namespace HiEvents\Http\Actions\Questions;
use HiEvents\DomainObjects\EventDomainObject;
+use HiEvents\DomainObjects\Generated\QuestionDomainObjectAbstract;
use HiEvents\DomainObjects\ProductDomainObject;
+use HiEvents\Exceptions\ResourceNotFoundException;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Repository\Interfaces\QuestionRepositoryInterface;
use HiEvents\Resources\Question\QuestionResource;
@@ -19,14 +21,24 @@ class GetQuestionAction extends BaseAction
$this->questionRepository = $questionRepository;
}
+ /**
+ * @throws ResourceNotFoundException
+ */
public function __invoke(Request $request, int $eventId, int $questionId): JsonResponse
{
$this->isActionAuthorized($eventId, EventDomainObject::class);
- $questions = $this->questionRepository
+ $question = $this->questionRepository
->loadRelation(ProductDomainObject::class)
- ->findById($questionId);
+ ->findFirstWhere([
+ QuestionDomainObjectAbstract::ID => $questionId,
+ QuestionDomainObjectAbstract::EVENT_ID => $eventId,
+ ]);
- return $this->resourceResponse(QuestionResource::class, $questions);
+ if ($question === null) {
+ throw new ResourceNotFoundException(__('Question not found'));
+ }
+
+ return $this->resourceResponse(QuestionResource::class, $question);
}
}
diff --git a/backend/app/Services/Application/Handlers/Attendee/PartialEditAttendeeHandler.php b/backend/app/Services/Application/Handlers/Attendee/PartialEditAttendeeHandler.php
index 0256ccd6b..393dd0ecc 100644
--- a/backend/app/Services/Application/Handlers/Attendee/PartialEditAttendeeHandler.php
+++ b/backend/app/Services/Application/Handlers/Attendee/PartialEditAttendeeHandler.php
@@ -102,7 +102,14 @@ class PartialEditAttendeeHandler
{
if ($data->status === AttendeeStatus::CANCELLED->name) {
// Get the order to access the creation date for daily statistics
- $order = $this->orderRepository->findById($attendee->getOrderId());
+ $order = $this->orderRepository->findFirstWhere([
+ 'id' => $attendee->getOrderId(),
+ 'event_id' => $attendee->getEventId(),
+ ]);
+
+ if ($order === null) {
+ return;
+ }
$this->eventStatisticsCancellationService->decrementForCancelledAttendee(
eventId: $attendee->getEventId(),
diff --git a/backend/app/Services/Application/Handlers/Event/UpdateEventStatusHandler.php b/backend/app/Services/Application/Handlers/Event/UpdateEventStatusHandler.php
index 49c7bd46b..175e1e304 100644
--- a/backend/app/Services/Application/Handlers/Event/UpdateEventStatusHandler.php
+++ b/backend/app/Services/Application/Handlers/Event/UpdateEventStatusHandler.php
@@ -49,7 +49,10 @@ readonly class UpdateEventStatusHandler
$this->eventRepository->updateWhere(
attributes: ['status' => $updateEventStatusDTO->status],
- where: ['id' => $updateEventStatusDTO->eventId]
+ where: [
+ 'id' => $updateEventStatusDTO->eventId,
+ 'account_id' => $updateEventStatusDTO->accountId,
+ ]
);
$this->logger->info('Event status updated', [
@@ -57,6 +60,9 @@ readonly class UpdateEventStatusHandler
'status' => $updateEventStatusDTO->status
]);
- return $this->eventRepository->findById($updateEventStatusDTO->eventId);
+ return $this->eventRepository->findFirstWhere([
+ 'id' => $updateEventStatusDTO->eventId,
+ 'account_id' => $updateEventStatusDTO->accountId,
+ ]);
}
}
diff --git a/backend/app/Services/Application/Handlers/Organizer/EditOrganizerHandler.php b/backend/app/Services/Application/Handlers/Organizer/EditOrganizerHandler.php
index 7cf492755..62e5c8fe5 100644
--- a/backend/app/Services/Application/Handlers/Organizer/EditOrganizerHandler.php
+++ b/backend/app/Services/Application/Handlers/Organizer/EditOrganizerHandler.php
@@ -51,6 +51,9 @@ class EditOrganizerHandler
return $this->organizerRepository
->loadRelation(ImageDomainObject::class)
- ->findById($organizerData->id);
+ ->findFirstWhere([
+ 'id' => $organizerData->id,
+ 'account_id' => $organizerData->account_id,
+ ]);
}
}
diff --git a/backend/app/Services/Application/Handlers/Organizer/UpdateOrganizerStatusHandler.php b/backend/app/Services/Application/Handlers/Organizer/UpdateOrganizerStatusHandler.php
index d82c62845..9042838bf 100644
--- a/backend/app/Services/Application/Handlers/Organizer/UpdateOrganizerStatusHandler.php
+++ b/backend/app/Services/Application/Handlers/Organizer/UpdateOrganizerStatusHandler.php
@@ -48,7 +48,10 @@ class UpdateOrganizerStatusHandler
$this->organizerRepository->updateWhere(
attributes: ['status' => $updateOrganizerStatusDTO->status],
- where: ['id' => $updateOrganizerStatusDTO->organizerId]
+ where: [
+ 'id' => $updateOrganizerStatusDTO->organizerId,
+ 'account_id' => $updateOrganizerStatusDTO->accountId,
+ ]
);
$this->logger->info('Organizer status updated', [
@@ -56,6 +59,9 @@ class UpdateOrganizerStatusHandler
'status' => $updateOrganizerStatusDTO->status
]);
- return $this->organizerRepository->findById($updateOrganizerStatusDTO->organizerId);
+ return $this->organizerRepository->findFirstWhere([
+ 'id' => $updateOrganizerStatusDTO->organizerId,
+ 'account_id' => $updateOrganizerStatusDTO->accountId,
+ ]);
}
}
diff --git a/backend/app/Services/Application/Handlers/ProductCategory/EditProductCategoryHandler.php b/backend/app/Services/Application/Handlers/ProductCategory/EditProductCategoryHandler.php
index 105adde14..574183a57 100644
--- a/backend/app/Services/Application/Handlers/ProductCategory/EditProductCategoryHandler.php
+++ b/backend/app/Services/Application/Handlers/ProductCategory/EditProductCategoryHandler.php
@@ -29,6 +29,9 @@ class EditProductCategoryHandler
],
);
- return $this->productCategoryRepository->findById($dto->product_category_id);
+ return $this->productCategoryRepository->findFirstWhere([
+ 'id' => $dto->product_category_id,
+ 'event_id' => $dto->event_id,
+ ]);
}
}
diff --git a/backend/app/Services/Application/Handlers/TaxAndFee/EditTaxHandler.php b/backend/app/Services/Application/Handlers/TaxAndFee/EditTaxHandler.php
index d3a65a788..50e1163a2 100644
--- a/backend/app/Services/Application/Handlers/TaxAndFee/EditTaxHandler.php
+++ b/backend/app/Services/Application/Handlers/TaxAndFee/EditTaxHandler.php
@@ -61,7 +61,10 @@ class EditTaxHandler
);
/** @var TaxAndFeesDomainObject $tax */
- $tax = $this->taxRepository->findById($data->id);
+ $tax = $this->taxRepository->findFirstWhere([
+ 'id' => $data->id,
+ 'account_id' => $data->account_id,
+ ]);
$this->logger->info('Updated tax', [
'id' => $tax->getId(),
diff --git a/backend/app/Services/Application/Handlers/User/CancelEmailChangeHandler.php b/backend/app/Services/Application/Handlers/User/CancelEmailChangeHandler.php
index 330c8c497..f4c086b20 100644
--- a/backend/app/Services/Application/Handlers/User/CancelEmailChangeHandler.php
+++ b/backend/app/Services/Application/Handlers/User/CancelEmailChangeHandler.php
@@ -3,6 +3,7 @@
namespace HiEvents\Services\Application\Handlers\User;
use HiEvents\DomainObjects\UserDomainObject;
+use HiEvents\Exceptions\ResourceNotFoundException;
use HiEvents\Repository\Interfaces\UserRepositoryInterface;
use HiEvents\Services\Application\Handlers\User\DTO\CancelEmailChangeDTO;
use Psr\Log\LoggerInterface;
@@ -24,6 +25,12 @@ class CancelEmailChangeHandler
public function handle(CancelEmailChangeDTO $data): UserDomainObject
{
+ $user = $this->userRepository->findByIdAndAccountId($data->userId, $data->accountId);
+
+ if ($user === null) {
+ throw new ResourceNotFoundException(__('User not found'));
+ }
+
$this->userRepository->updateWhere(
attributes: [
'pending_email' => null,
diff --git a/backend/app/Services/Application/Handlers/User/UpdateMeHandler.php b/backend/app/Services/Application/Handlers/User/UpdateMeHandler.php
index 0deba3033..965a9257b 100644
--- a/backend/app/Services/Application/Handlers/User/UpdateMeHandler.php
+++ b/backend/app/Services/Application/Handlers/User/UpdateMeHandler.php
@@ -88,15 +88,10 @@ readonly class UpdateMeHandler
private function getExistingUser(UpdateMeDTO $updateUserData): UserDomainObject
{
- $existingUser = $this->userRepository->findFirstWhere([
- 'id' => $updateUserData->id,
- ]);
-
- if ($existingUser === null) {
- throw new ResourceNotFoundException();
- }
-
- return $existingUser;
+ return $this->userRepository->findByIdAndAccountId(
+ $updateUserData->id,
+ $updateUserData->account_id
+ );
}
private function sendEmailChangeConfirmation(UserDomainObject $existingUser): void