Skip to content

Beautiful Open-Source Form Builder

Fix local attachment uploads using the form asset size limit (#1367)

Julien Nahumef08a2f92b82
diff --git a/api/.env.example b/api/.env.example
index db1556916..95a8e7787 100644
--- a/api/.env.example
+++ b/api/.env.example
@@ -57,6 +57,7 @@ JWT_REMEMBER_TTL=43200
JWT_SECRET=
# Local development only. Keep false in production/Docker deployments.
JWT_SKIP_IP_UA_VALIDATION=false
+PUBLIC_UPLOADS_MAX_FILE_SIZE=50000000
PUBLIC_UPLOADS_RATE_LIMIT_PER_MINUTE=30
PUBLIC_UPLOADS_RATE_LIMIT_PER_HOUR=300
diff --git a/api/app/Http/Controllers/Content/FileUploadController.php b/api/app/Http/Controllers/Content/FileUploadController.php
index daa8ef38c..15441dc37 100644
--- a/api/app/Http/Controllers/Content/FileUploadController.php
+++ b/api/app/Http/Controllers/Content/FileUploadController.php
@@ -3,7 +3,6 @@
namespace App\Http\Controllers\Content;
use App\Http\Controllers\Controller;
-use App\Http\Requests\UploadAssetRequest;
use App\Service\Storage\FileUploadPathService;
use App\Service\Storage\UploadSecurityService;
use Illuminate\Http\Request;
@@ -21,7 +20,8 @@ class FileUploadController extends Controller
public function upload(Request $request, UploadSecurityService $uploadSecurityService)
{
$request->validate([
- 'file' => 'required|file|max:' . (int) ceil(UploadAssetRequest::FORM_ASSET_MAX_SIZE / 1024),
+ // Temporary uploads include respondent attachments, not only form assets.
+ 'file' => 'required|file|max:' . (config('opnform.public_uploads.max_file_size') / 1024),
]);
try {
diff --git a/api/config/opnform.php b/api/config/opnform.php
index a91a748c4..2db2bf455 100644
--- a/api/config/opnform.php
+++ b/api/config/opnform.php
@@ -11,6 +11,7 @@ return [
'enable_self_hosted' => env('CUSTOM_CODE_ENABLE_SELF_HOSTED', false),
],
'public_uploads' => [
+ 'max_file_size' => (int) env('PUBLIC_UPLOADS_MAX_FILE_SIZE', 50000000),
'rate_limit' => [
'per_minute' => (int) env('PUBLIC_UPLOADS_RATE_LIMIT_PER_MINUTE', 30),
'per_hour' => (int) env('PUBLIC_UPLOADS_RATE_LIMIT_PER_HOUR', 300),
diff --git a/api/tests/Feature/Forms/UploadFileSizeTest.php b/api/tests/Feature/Forms/UploadFileSizeTest.php
new file mode 100644
index 000000000..6ba4bf1fd
--- /dev/null
+++ b/api/tests/Feature/Forms/UploadFileSizeTest.php
@@ -0,0 +1,96 @@
+<?php
+
+use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
+
+beforeEach(function () {
+ Storage::fake('local');
+});
+
+it('enforces the default local temporary upload limit at the byte boundary', function (int $bytes, int $status) {
+ $file = UploadedFile::fake()->createWithContent('attachment.txt', 'safe content');
+ $file->sizeToReport = $bytes;
+
+ $response = $this->post('/upload-file', ['file' => $file]);
+
+ $response->assertStatus($status);
+ if ($status === 201) {
+ Storage::assertExists($response->json('key'));
+ } else {
+ $response->assertJsonValidationErrors('file');
+ expect(Storage::allFiles())->toBeEmpty();
+ }
+})->with([
+ '50 MB accepted' => [50_000_000, 201],
+ 'one byte over 50 MB rejected' => [50_000_001, 422],
+]);
+
+it('supports a configured temporary upload limit', function (int $limit, int $bytes, int $status) {
+ config(['opnform.public_uploads.max_file_size' => $limit]);
+ $file = UploadedFile::fake()->createWithContent('attachment.txt', 'safe content');
+ $file->sizeToReport = $bytes;
+
+ $response = $this->post('/upload-file', ['file' => $file]);
+
+ $response->assertStatus($status);
+ if ($status === 422) {
+ $response->assertJsonValidationErrors('file');
+ expect(Storage::allFiles())->toBeEmpty();
+ }
+})->with([
+ '100 MB accepted' => [100_000_000, 100_000_000, 201],
+ 'one byte over configured limit rejected' => [100_000_000, 100_000_001, 422],
+ 'lower configured limit accepted' => [1024, 1024, 201],
+ 'one byte over lower configured limit rejected' => [1024, 1025, 422],
+]);
+
+it('keeps workspace and field limits when submitting a local attachment larger than 5 MB', function (int $fieldLimit, bool $selfHosted, int $status) {
+ config([
+ 'app.self_hosted' => $selfHosted,
+ 'cashier.key' => 'test-key',
+ 'plans.limits.file_upload_size.free' => 5_000_000,
+ ]);
+ $user = $this->createUser();
+ $workspace = $this->createUserWorkspace($user);
+ expect($workspace->max_file_size)->toBe($selfHosted ? 50_000_000 : 5_000_000);
+ $form = $this->createForm($user, $workspace, [
+ 'properties' => [[
+ 'id' => 'attachment',
+ 'name' => 'Attachment',
+ 'type' => 'files',
+ 'max_file_size' => $fieldLimit,
+ ]],
+ ]);
+
+ $upload = $this->post('/upload-file', [
+ 'file' => UploadedFile::fake()->createWithContent('attachment.txt', str_repeat('a', 6_000_000)),
+ ])->assertCreated();
+ expect(Storage::size($upload->json('key')))->toBe(6_000_000);
+
+ $response = $this->postJson(route('forms.answer', $form->slug), [
+ 'attachment' => ['attachment_' . $upload->json('uuid') . '.txt'],
+ ]);
+
+ $response->assertStatus($status);
+ if ($status === 422) {
+ $response->assertJsonValidationErrors('attachment.0');
+ expect($form->submissions()->count())->toBe(0);
+ } else {
+ expect($form->submissions()->count())->toBe(1);
+ }
+})->with([
+ '50 MB field accepts 6 MB' => [50, true, 200],
+ '5 MB field rejects 6 MB' => [5, true, 422],
+ '5 MB workspace rejects 6 MB despite a 50 MB field' => [50, false, 422],
+]);
+
+it('still rejects form assets larger than 5 MB after temporary upload', function () {
+ $upload = $this->post('/upload-file', [
+ 'file' => UploadedFile::fake()->createWithContent('asset.txt', str_repeat('a', 6_000_000)),
+ ])->assertCreated();
+
+ $this->postJson('/open/forms/assets/upload', [
+ 'url' => 'asset_' . $upload->json('uuid') . '.txt',
+ 'type' => 'files',
+ ])->assertUnprocessable()->assertJsonValidationErrors('url');
+});
diff --git a/docs/configuration/environment-variables.mdx b/docs/configuration/environment-variables.mdx
index f2ac6e28d..ca8c3a8ff 100644
--- a/docs/configuration/environment-variables.mdx
+++ b/docs/configuration/environment-variables.mdx
@@ -76,6 +76,7 @@ There are dedicated configuration pages available for more detailed setup instru
| `OAUTH_ENABLED` | Enables the delegated OAuth 2.1 infrastructure. Defaults to `true`; set it to `false` only when you need to disable OAuth routes independently of the MCP setting. |
| `OAUTH_ACCESS_TOKEN_TTL` | Passport access token lifetime in minutes. Defaults to `10080` (7 days) and does not change the first-party JWT lifetime. |
| `OAUTH_REFRESH_TOKEN_TTL_DAYS` | Passport refresh token lifetime in days. Defaults to `30`. |
+| `PUBLIC_UPLOADS_MAX_FILE_SIZE` | Maximum temporary file size in bytes for local uploads through `/upload-file`. Defaults to `50000000` (50 MB). Workspace and field limits still apply when submitting a response. |
| `PUBLIC_UPLOADS_RATE_LIMIT_PER_MINUTE` | Maximum public upload requests allowed per client IP or authenticated user per route each minute. Defaults to `30`. |
| `PUBLIC_UPLOADS_RATE_LIMIT_PER_HOUR` | Maximum public upload requests allowed per client IP or authenticated user per route each hour. Defaults to `300`. |
| `OIDC_FORCE_LOGIN` | When set to `true`, password-based authentication is disabled and users must authenticate via OIDC SSO. See [Force Login Mode](../configuration/oidc-sso#7-force-login-mode) for details. |
@@ -134,6 +135,8 @@ OAuth integrations enable user authentication and third-party service connection
These PHP configuration variables are particularly important when handling file uploads and processing large amounts of data. If any of these variables are not set, PHP will use its default values from the php.ini configuration. When using Docker, these values are set in the docker-compose.yml file. For non-Docker installations, you'll need to configure these values in your PHP configuration (php.ini) file.
+For local file storage, `/upload-file` accepts temporary uploads up to `PUBLIC_UPLOADS_MAX_FILE_SIZE` (50 MB by default). If your workspace allows larger attachments, increase this value and ensure PHP and your reverse proxy accept the larger request, including multipart overhead. This setting does not change direct S3 uploads. Form assets, such as logos and cover images, retain their separate 5 MB limit.
+
### Database Configuration Environment Variables
These variables are essential for connecting the Laravel backend to your database.