1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Exports: Added rate limits for UI exports

Just as a measure to prevent potential abuse of these potentially
longer-running endpoints.
Adds test to cover for ZIP exports, but applied to all formats.
This commit is contained in:
Dan Brown
2025-01-01 15:42:59 +00:00
parent 7e31725d48
commit 1ff2826678
5 changed files with 32 additions and 0 deletions

View File

@@ -423,6 +423,28 @@ class ZipExportTest extends TestCase
$this->assertStringContainsString("[Link to chapter]([[bsexport:chapter:{$chapter->id}]])", $pageData['markdown']);
}
public function test_exports_rate_limited_low_for_guest_viewers()
{
$this->setSettings(['app-public' => 'true']);
$page = $this->entities->page();
for ($i = 0; $i < 4; $i++) {
$this->get($page->getUrl("/export/zip"))->assertOk();
}
$this->get($page->getUrl("/export/zip"))->assertStatus(429);
}
public function test_exports_rate_limited_higher_for_logged_in_viewers()
{
$this->asAdmin();
$page = $this->entities->page();
for ($i = 0; $i < 10; $i++) {
$this->get($page->getUrl("/export/zip"))->assertOk();
}
$this->get($page->getUrl("/export/zip"))->assertStatus(429);
}
protected function extractZipResponse(TestResponse $response): ZipResultData
{
$zipData = $response->streamedContent();