Store answers atomically and limit word cloud input
CI / Deploy / test (push) Successful in 51s
CI / Deploy / deploy (push) Skipped

- 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:
gnilebeinandClaude Opus 5.5 committed 2026-11-08 22:01:19 +01:00
1 parent 8b0e82d806
commit 9c532d164f
11 files changed
+224 -50

No files matched your search

@@ -5,6 +5,8 @@ namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
@@ -28,6 +30,7 @@ class ParticipateControllerTest extends TestCase
{
parent::setUp();
$this->enableCsrfToken();
Cache::clear('throttle');
}
public function testUnknownCodeIs404(): void
@@ -157,4 +160,24 @@ class ParticipateControllerTest extends TestCase
$this->get('/p/' . $poll->join_code);
$this->assertResponseContains('Diese Umfrage ist geschlossen');
}
public function testVotesAreThrottledPerIp(): void
{
Configure::write('Plenario.throttle.votesPerMinute', 2);
[$poll] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_WORDCLOUD);
$this->goLive($poll, $slide);
foreach (['Kaffee', 'Tee', 'Wasser'] as $i => $word) {
$this->cookie('plenario_pid', self::PID);
$this->configRequest(['headers' => ['X-Requested-With' => 'XMLHttpRequest', 'Accept' => 'application/json']]);
$this->post("/p/{$poll->join_code}/vote", ['slide_id' => $slide->id, 'word' => $word]);
$body = json_decode((string)$this->_response->getBody(), true);
$this->assertSame($i < 2, $body['ok'], $word);
}
$this->assertResponseCode(429);
$this->assertStringContainsString('Zu viele Antworten', $body['message']);
$this->assertArrayHasKey('state', $body);
$this->assertSame(2, TableRegistry::getTableLocator()->get('Responses')->find()->where(['slide_id' => $slide->id])->count());
}
}