Store answers atomically and limit word cloud input
- Run the checks and the insert of VoteService::submit() in one transaction with the slide row locked, so double clicks or retries cannot store a vote twice (also covers the Q&A upvote budget and word cloud duplicates). - Limit word cloud terms per request and per participant, and throttle answers per IP and minute (THROTTLE_VOTES_PER_MINUTE, 429 with message). - Treat array values in text fields as empty instead of storing "Array". - Move the throttle helper to AppController for reuse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b0e82d806
commit
9c532d164f
11 files changed
+224
-50
No files matched your search
@@ -118,8 +118,14 @@ class ParticipateController extends AppController
|
||||
$slide = $stateService->currentSlide($poll);
|
||||
$submittedSlideId = (int)$this->request->getData('slide_id');
|
||||
$ajax = $this->request->is('ajax');
|
||||
$status = 200;
|
||||
|
||||
try {
|
||||
// Generous per IP (a whole audience may share one Wi-Fi), only stops scripted floods.
|
||||
if (!$this->throttle('vote', 'Plenario.throttle.votesPerMinute', 60)) {
|
||||
$status = 429;
|
||||
throw new VoteException(__('Zu viele Antworten in kurzer Zeit. Bitte warte einen Moment und versuche es dann noch einmal.'));
|
||||
}
|
||||
if ($slide === null || $slide->id !== $submittedSlideId) {
|
||||
throw new VoteException(__('Diese Frage ist nicht mehr aktiv.'));
|
||||
}
|
||||
@@ -141,7 +147,7 @@ class ParticipateController extends AppController
|
||||
'ok' => $ok,
|
||||
'message' => $message,
|
||||
'state' => $stateService->forParticipant($poll, $this->participantHash($poll)),
|
||||
]);
|
||||
], $status);
|
||||
}
|
||||
$ok ? $this->Flash->success($message) : $this->Flash->error($message);
|
||||
|
||||
|
||||
Reference in new issue
Block a user