mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-13 13:25:19 +02:00
Add rate limiting to login and season-code entry points
Neither /login nor the public season-code guess form (POST /) had any throttling, making both an unlimited brute-force/enumeration oracle. Adds symfony/rate-limiter and enables login_throttling on the main firewall, plus a dedicated per-IP rate limiter on the season-code form.
This commit is contained in:
@@ -17,6 +17,14 @@ use Tvdt\Helpers\Base64;
|
||||
#[CoversClass(QuizController::class)]
|
||||
final class QuizControllerTest extends AbstractControllerWebTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Season-code guessing is rate-limited; start each test with a clean quota.
|
||||
self::getContainer()->get('cache.rate_limiter')->clear();
|
||||
}
|
||||
|
||||
private function answerQuestion(Question $question): void
|
||||
{
|
||||
$tomHash = Base64::base64UrlEncode('Tom');
|
||||
@@ -69,6 +77,26 @@ final class QuizControllerTest extends AbstractControllerWebTestCase
|
||||
self::assertResponseRedirects('/krtek');
|
||||
}
|
||||
|
||||
public function testSelectSeasonIsThrottledAfterTooManyAttempts(): void
|
||||
{
|
||||
for ($i = 0; $i < 3; ++$i) {
|
||||
$crawler = $this->client->request(Request::METHOD_GET, '/');
|
||||
$form = $crawler->filter('form')->form([
|
||||
'select_season[season_code]' => 'aaaaa',
|
||||
]);
|
||||
$this->client->submit($form);
|
||||
self::assertResponseRedirects('/');
|
||||
}
|
||||
|
||||
$crawler = $this->client->request(Request::METHOD_GET, '/');
|
||||
$form = $crawler->filter('form')->form([
|
||||
'select_season[season_code]' => 'aaaaa',
|
||||
]);
|
||||
$this->client->submit($form);
|
||||
|
||||
self::assertResponseStatusCodeSame(429);
|
||||
}
|
||||
|
||||
public function testEnterNamePageLoads(): void
|
||||
{
|
||||
$this->client->request(Request::METHOD_GET, '/krtek');
|
||||
|
||||
Reference in New Issue
Block a user