Skip to content

Beautiful Open-Source Form Builder

Let workspaces choose uploaded file link validity (#1205)

Julien Nahum9360748bdc97
diff --git a/api/app/Http/Controllers/Forms/FormSubmissionController.php b/api/app/Http/Controllers/Forms/FormSubmissionController.php
index c581cc0ee..caa3cac91 100644
--- a/api/app/Http/Controllers/Forms/FormSubmissionController.php
+++ b/api/app/Http/Controllers/Forms/FormSubmissionController.php
@@ -153,6 +153,7 @@ class FormSubmissionController extends Controller
private function processSyncExport(Form $form, array $displayColumns, array $submissionIds, FormExportService $exportService)
{
$allRows = [];
+ $fileLinkExpiresAt = $exportService->fileLinkExpiresAt($form);
// Use query builder with orderBy for consistency with async export
$submissionQuery = $form->submissions()->orderByDesc('created_at');
if (!empty($submissionIds)) {
@@ -160,7 +161,7 @@ class FormSubmissionController extends Controller
}
foreach ($submissionQuery->get() as $submission) {
- $allRows[] = $exportService->formatSubmissionForExport($form, $submission, $displayColumns);
+ $allRows[] = $exportService->formatSubmissionForExport($form, $submission, $displayColumns, $fileLinkExpiresAt);
}
$csvExport = (new FormSubmissionExport($allRows));
diff --git a/api/app/Http/Controllers/WorkspaceController.php b/api/app/Http/Controllers/WorkspaceController.php
index f7851c8f0..abc42a03c 100644
--- a/api/app/Http/Controllers/WorkspaceController.php
+++ b/api/app/Http/Controllers/WorkspaceController.php
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Http\Requests\Workspace\CustomDomainRequest;
use App\Http\Requests\Workspace\CustomCodeSettingsRequest;
use App\Http\Requests\Workspace\EmailSettingsRequest;
+use App\Http\Requests\Workspace\ExternalFileLinkSettingsRequest;
use App\Http\Resources\WorkspaceResource;
use App\Models\User;
use App\Models\UserWorkspace;
@@ -81,6 +82,20 @@ class WorkspaceController extends Controller
return new WorkspaceResource($request->workspace);
}
+ public function saveExternalFileLinkSettings(ExternalFileLinkSettingsRequest $request)
+ {
+ $this->authorize('adminAction', $request->workspace);
+
+ $settings = $request->workspace->settings ?? [];
+ $settings['external_file_links'] = [
+ 'expires_in_hours' => $request->validated('expires_in_hours'),
+ ];
+
+ $request->workspace->update(['settings' => $settings]);
+
+ return new WorkspaceResource($request->workspace);
+ }
+
public function delete(Workspace $workspace)
{
$this->authorize('delete', $workspace);
diff --git a/api/app/Http/Requests/Workspace/ExternalFileLinkSettingsRequest.php b/api/app/Http/Requests/Workspace/ExternalFileLinkSettingsRequest.php
new file mode 100644
index 000000000..e0dce7d12
--- /dev/null
+++ b/api/app/Http/Requests/Workspace/ExternalFileLinkSettingsRequest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests\Workspace;
+
+use App\Models\Workspace;
+use App\Service\Forms\ExternalSubmissionFileLinkPolicy;
+use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Http\Request;
+use Illuminate\Validation\Rule;
+
+class ExternalFileLinkSettingsRequest extends FormRequest
+{
+ public Workspace $workspace;
+
+ public function __construct(Request $request)
+ {
+ $this->workspace = $request->route('workspace');
+ }
+
+ public function rules(): array
+ {
+ return [
+ 'expires_in_hours' => [
+ 'required',
+ 'integer',
+ Rule::in(ExternalSubmissionFileLinkPolicy::ALLOWED_EXPIRATION_HOURS),
+ ],
+ ];
+ }
+}
diff --git a/api/app/Integrations/Handlers/DiscordIntegration.php b/api/app/Integrations/Handlers/DiscordIntegration.php
index a569347ec..c97a6df2d 100644
--- a/api/app/Integrations/Handlers/DiscordIntegration.php
+++ b/api/app/Integrations/Handlers/DiscordIntegration.php
@@ -55,7 +55,9 @@ class DiscordIntegration extends AbstractIntegrationHandler
$color = hexdec(str_replace('#', '', $this->form->color));
$blocks = [];
if (Arr::get($settings, 'include_submission_data', true)) {
- $formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
+ $formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))
+ ->outputStringsOnly()
+ ->useSignedUrlForFiles();
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
$formatter->showHiddenFields();
}
@@ -92,7 +94,11 @@ class DiscordIntegration extends AbstractIntegrationHandler
}
$formattedData = $this->escapeFormattedDataForDiscord(
- (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly()->showHiddenFields()->getFieldsWithValue()
+ (new FormSubmissionFormatter($this->form, $this->submissionData))
+ ->outputStringsOnly()
+ ->showHiddenFields()
+ ->useSignedUrlForFiles()
+ ->getFieldsWithValue()
);
$message = Arr::get($settings, 'message', 'New form submission');
return [
diff --git a/api/app/Integrations/Handlers/SlackIntegration.php b/api/app/Integrations/Handlers/SlackIntegration.php
index 3a1081a5a..5a6d4a6c9 100644
--- a/api/app/Integrations/Handlers/SlackIntegration.php
+++ b/api/app/Integrations/Handlers/SlackIntegration.php
@@ -53,7 +53,11 @@ class SlackIntegration extends AbstractIntegrationHandler
}
$formattedData = $this->escapeFormattedDataForSlack(
- (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly()->showHiddenFields()->getFieldsWithValue()
+ (new FormSubmissionFormatter($this->form, $this->submissionData))
+ ->outputStringsOnly()
+ ->showHiddenFields()
+ ->useSignedUrlForFiles()
+ ->getFieldsWithValue()
);
$message = Arr::get($settings, 'message', 'New form submission');
$blocks = [
@@ -67,7 +71,9 @@ class SlackIntegration extends AbstractIntegrationHandler
];
if (Arr::get($settings, 'include_submission_data', true)) {
- $formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
+ $formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))
+ ->outputStringsOnly()
+ ->useSignedUrlForFiles();
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
$formatter->showHiddenFields();
}
diff --git a/api/app/Integrations/Handlers/TelegramIntegration.php b/api/app/Integrations/Handlers/TelegramIntegration.php
index 71d9fa4d1..badfbcd5d 100644
--- a/api/app/Integrations/Handlers/TelegramIntegration.php
+++ b/api/app/Integrations/Handlers/TelegramIntegration.php
@@ -54,7 +54,9 @@ class TelegramIntegration extends AbstractIntegrationHandler
$settings = (array) $this->integrationData ?? [];
$messageParts = [];
- $formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
+ $formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))
+ ->outputStringsOnly()
+ ->useSignedUrlForFiles();
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
$formatter->showHiddenFields();
}
diff --git a/api/app/Jobs/Form/ExportFormSubmissionsJob.php b/api/app/Jobs/Form/ExportFormSubmissionsJob.php
index dd6e2694c..1f2b71cd8 100644
--- a/api/app/Jobs/Form/ExportFormSubmissionsJob.php
+++ b/api/app/Jobs/Form/ExportFormSubmissionsJob.php
@@ -4,6 +4,7 @@ namespace App\Jobs\Form;
use App\Models\Forms\Form;
use App\Service\Forms\FormExportService;
+use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@@ -53,13 +54,15 @@ class ExportFormSubmissionsJob implements ShouldQueue
$chunkSize = 500;
$processedCount = 0;
$allRows = [];
+ $fileLinkExpiresAt = $exportService->fileLinkExpiresAt($this->form);
- $submissionQuery->chunk($chunkSize, function ($submissions) use (&$processedCount, &$allRows, $totalSubmissions, $exportService) {
+ $submissionQuery->chunk($chunkSize, function ($submissions) use (&$processedCount, &$allRows, $totalSubmissions, $exportService, $fileLinkExpiresAt) {
foreach ($submissions as $submission) {
$formattedRow = $exportService->formatSubmissionForExport(
$this->form,
$submission,
- $this->columns
+ $this->columns,
+ $fileLinkExpiresAt
);
$allRows[] = $formattedRow;
$processedCount++;
@@ -74,10 +77,10 @@ class ExportFormSubmissionsJob implements ShouldQueue
$this->updateJobStatus('processing', 95, 'Generating export file...');
$fileName = $this->form->slug . '-submissions-' . now()->format('Y-m-d-H-i-s') . '.csv';
- $fileUrl = $exportService->generateAndUploadCsvFile($allRows, $fileName);
+ $fileUrl = $exportService->generateAndUploadCsvFile($allRows, $fileName, $fileLinkExpiresAt);
// Mark as completed
- $this->updateJobStatus('completed', 100, null, $totalSubmissions, $totalSubmissions, $fileUrl);
+ $this->updateJobStatus('completed', 100, null, $totalSubmissions, $totalSubmissions, $fileUrl, $fileLinkExpiresAt);
Log::info("Export job {$this->jobId} completed successfully", [
'form_id' => $this->form->id,
@@ -102,7 +105,8 @@ class ExportFormSubmissionsJob implements ShouldQueue
?string $errorMessage = null,
?int $processedSubmissions = null,
?int $totalSubmissions = null,
- ?string $fileUrl = null
+ ?string $fileUrl = null,
+ ?Carbon $fileExpiresAt = null
): void {
$exportService = app(FormExportService::class);
$cacheKey = $exportService->getCacheKey($this->jobId);
@@ -133,7 +137,7 @@ class ExportFormSubmissionsJob implements ShouldQueue
if ($fileUrl) {
$data['file_url'] = $fileUrl;
- $data['expires_at'] = now()->addDay()->toISOString(); // File expires in 24 hours
+ $data['expires_at'] = ($fileExpiresAt ?? now()->addDay())->toISOString();
}
// Cache for 2 hours
diff --git a/api/app/Service/Forms/ExternalSubmissionFileLinkPolicy.php b/api/app/Service/Forms/ExternalSubmissionFileLinkPolicy.php
new file mode 100644
index 000000000..67579f750
--- /dev/null
+++ b/api/app/Service/Forms/ExternalSubmissionFileLinkPolicy.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Service\Forms;
+
+use App\Models\Workspace;
+use Carbon\Carbon;
+
+class ExternalSubmissionFileLinkPolicy
+{
+ public const DEFAULT_EXPIRATION_HOURS = 24;
+
+ public const ALLOWED_EXPIRATION_HOURS = [
+ 24,
+ 72,
+ 168,
+ 336,
+ 720,
+ ];
+
+ public function expirationHours(Workspace $workspace): int
+ {
+ $expirationHours = data_get($workspace->settings ?? [], 'external_file_links.expires_in_hours');
+
+ return in_array($expirationHours, self::ALLOWED_EXPIRATION_HOURS, true)
+ ? $expirationHours
+ : self::DEFAULT_EXPIRATION_HOURS;
+ }
+
+ public function expiresAt(Workspace $workspace): Carbon
+ {
+ return now()->addHours($this->expirationHours($workspace));
+ }
+}
diff --git a/api/app/Service/Forms/FormExportService.php b/api/app/Service/Forms/FormExportService.php
index a5b56335e..b4a0404fb 100644
--- a/api/app/Service/Forms/FormExportService.php
+++ b/api/app/Service/Forms/FormExportService.php
@@ -4,6 +4,7 @@ namespace App\Service\Forms;
use App\Models\Forms\Form;
use App\Models\Forms\FormSubmission;
+use Carbon\Carbon;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
@@ -15,6 +16,15 @@ class FormExportService
public const CACHE_KEY_PREFIX = 'form_export_job';
public const EXPORT_FILE_PATH = 'exports/temp/';
+ public function __construct(private ExternalSubmissionFileLinkPolicy $externalFileLinkPolicy)
+ {
+ }
+
+ public function fileLinkExpiresAt(Form $form): Carbon
+ {
+ return $this->externalFileLinkPolicy->expiresAt($form->workspace);
+ }
+
/**
* Determine if export should be processed synchronously or asynchronously
*/
@@ -28,14 +38,18 @@ class FormExportService
/**
* Format a single submission for export
*/
- public function formatSubmissionForExport(Form $form, FormSubmission $submission, array $displayColumns): array
- {
+ public function formatSubmissionForExport(
+ Form $form,
+ FormSubmission $submission,
+ array $displayColumns,
+ ?Carbon $fileLinkExpiresAt = null
+ ): array {
$formatter = (new FormSubmissionFormatter($form, $submission->data))
->outputStringsOnly()
->setEmptyForNoValue()
->showRemovedFields()
->showHiddenFields()
- ->useSignedUrlForFiles();
+ ->useSignedUrlForFiles($fileLinkExpiresAt ?? $this->fileLinkExpiresAt($form));
$formattedData = $formatter->getCleanKeyValue();
$filteredData = ['id' => Hashids::encode($submission->id)];
@@ -64,7 +78,7 @@ class FormExportService
/**
* Generate CSV content from rows and upload to storage
*/
- public function generateAndUploadCsvFile(array $rows, string $fileName): string
+ public function generateAndUploadCsvFile(array $rows, string $fileName, Carbon $expiresAt): string
{
if (empty($rows)) {
throw new \Exception('No data to export');
@@ -84,7 +98,7 @@ class FormExportService
]);
// Generate temporary URL for download (works for all storage types)
- return $disk->temporaryUrl($filePath, now()->addDay());
+ return $disk->temporaryUrl($filePath, $expiresAt);
}
/**
diff --git a/api/app/Service/Forms/FormSubmissionFormatter.php b/api/app/Service/Forms/FormSubmissionFormatter.php
index 56482fef1..a57a43a8a 100644
--- a/api/app/Service/Forms/FormSubmissionFormatter.php
+++ b/api/app/Service/Forms/FormSubmissionFormatter.php
@@ -35,6 +35,8 @@ class FormSubmissionFormatter
private $useSignedUrlForFiles = false;
+ private ?Carbon $signedFileUrlExpiration = null;
+
/**
* Logic resolver needs an array id => value, so we create it here
*/
@@ -80,9 +82,11 @@ class FormSubmissionFormatter
return $this;
}
- public function useSignedUrlForFiles()
+ public function useSignedUrlForFiles(?Carbon $expiresAt = null)
{
$this->useSignedUrlForFiles = true;
+ $this->signedFileUrlExpiration = $expiresAt ?? app(ExternalSubmissionFileLinkPolicy::class)
+ ->expiresAt($this->form->workspace);
return $this;
}
@@ -361,7 +365,7 @@ class FormSubmissionFormatter
return $this->useSignedUrlForFiles ? URL::temporarySignedRoute(
'open.forms.submissions.file',
- now()->addMinutes(self::SIGNED_FILE_URL_EXPIRATION_MINUTES),
+ $this->signedFileUrlExpiration ?? now()->addMinutes(self::SIGNED_FILE_URL_EXPIRATION_MINUTES),
[$formId, $encodedFilename]
) : route('open.forms.submissions.file', [$formId, $encodedFilename]);
} catch (\Exception $e) {
diff --git a/api/routes/api.php b/api/routes/api.php
index 0cff3c2de..6bee33d74 100644
--- a/api/routes/api.php
+++ b/api/routes/api.php
@@ -175,6 +175,7 @@ Route::group(['middleware' => 'auth.multi'], function () {
Route::put('/custom-domains', [WorkspaceController::class, 'saveCustomDomain'])->name('save-custom-domains');
Route::put('/email-settings', [WorkspaceController::class, 'saveEmailSettings'])->name('save-email-settings');
Route::put('/custom-code-settings', [WorkspaceController::class, 'saveCustomCodeSettings'])->name('save-custom-code-settings');
+ Route::put('/external-file-link-settings', [WorkspaceController::class, 'saveExternalFileLinkSettings'])->name('save-external-file-link-settings');
Route::put('/', [WorkspaceController::class, 'update'])->name('update');
Route::delete('/', [WorkspaceController::class, 'delete'])->name('delete');
diff --git a/api/tests/Feature/Forms/EmailNotificationTest.php b/api/tests/Feature/Forms/EmailNotificationTest.php
index a4817e0e0..19ff0466d 100644
--- a/api/tests/Feature/Forms/EmailNotificationTest.php
+++ b/api/tests/Feature/Forms/EmailNotificationTest.php
@@ -30,6 +30,58 @@ it('send email with the submitted data', function () {
expect(trim($renderedMail->render()))->toContain('Test body');
});
+it('uses the workspace policy for file links in email notifications', function () {
+ $user = $this->actingAsUser();
+ $workspace = $this->createUserWorkspace($user);
+ $workspace->update([
+ 'settings' => [
+ 'external_file_links' => [
+ 'expires_in_hours' => 168,
+ ],
+ ],
+ ]);
+ $form = $this->createForm($user, $workspace, [
+ 'properties' => [
+ [
+ 'id' => 'attachment',
+ 'name' => 'Attachment',
+ 'type' => 'files',
+ 'required' => false,
+ ],
+ ],
+ ]);
+ $form->load('workspace', 'creator');
+ $integrationData = $this->createFormIntegration('email', $form->id, [
+ 'send_to' => $user->email,
+ 'sender_name' => 'OpnForm',
+ 'subject' => 'New form submission',
+ 'email_content' => 'New submission',
+ 'include_submission_data' => true,
+ ]);
+
+ $now = \Carbon\Carbon::parse('2026-07-17 17:00:00');
+ \Carbon\Carbon::setTestNow($now);
+
+ try {
+ $mailable = new FormEmailNotification(
+ new \App\Events\Forms\FormSubmitted($form, ['attachment' => ['weekend-upload.png']]),
+ $integrationData,
+ 'mail'
+ );
+ $notifiable = new AnonymousNotifiable();
+ $notifiable->route('mail', $user->email);
+ $renderedMail = html_entity_decode($mailable->toMail($notifiable)->render());
+ } finally {
+ \Carbon\Carbon::setTestNow();
+ }
+
+ preg_match('/href="([^"]*submissions\/file[^"]*)"/', $renderedMail, $matches);
+ parse_str((string) parse_url($matches[1] ?? '', PHP_URL_QUERY), $queryParameters);
+
+ expect((int) ($queryParameters['expires'] ?? 0))->toBe($now->copy()->addHours(168)->timestamp);
+ expect($queryParameters['signature'] ?? null)->not->toBeEmpty();
+});
+
it('sends a email if needed', function () {
$user = $this->actingAsProUser();
$workspace = $this->createUserWorkspace($user);
diff --git a/api/tests/Feature/Forms/FormSubmissionExportTest.php b/api/tests/Feature/Forms/FormSubmissionExportTest.php
index 4d0b71b1a..f05443b45 100644
--- a/api/tests/Feature/Forms/FormSubmissionExportTest.php
+++ b/api/tests/Feature/Forms/FormSubmissionExportTest.php
@@ -2,8 +2,9 @@
use App\Models\User;
use App\Models\Forms\FormSubmission;
-use App\Service\Forms\FormSubmissionFormatter;
+use App\Service\Forms\FormExportService;
use App\Service\Storage\FileUploadPathService;
+use Carbon\Carbon;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
@@ -352,9 +353,16 @@ it('does not include status column when partial submissions are disabled', funct
expect(str_contains($content, 'status'))->toBeFalse();
});
-it('exports file urls with a durable expiration and a valid signature', function () {
+it('exports file urls with the workspace policy expiration and a valid signature', function () {
$user = $this->actingAsProUser();
$workspace = $this->createUserWorkspace($user);
+ $workspace->update([
+ 'settings' => [
+ 'external_file_links' => [
+ 'expires_in_hours' => 168,
+ ],
+ ],
+ ]);
$form = $this->createForm($user, $workspace, [
'properties' => [
[
@@ -398,7 +406,7 @@ it('exports file urls with a durable expiration and a valid signature', function
parse_str(parse_url($exportedFileUrl, PHP_URL_QUERY), $queryParameters);
expect($queryParameters)->toHaveKeys(['expires', 'signature']);
- expect((int) $queryParameters['expires'])->toBeGreaterThan(now()->addMinutes(FormSubmissionFormatter::SIGNED_FILE_URL_EXPIRATION_MINUTES - 1)->timestamp);
+ expect((int) $queryParameters['expires'])->toBeGreaterThan(now()->addHours(168)->subMinute()->timestamp);
$this->get($exportedFileUrl)->assertOk();
@@ -409,6 +417,39 @@ it('exports file urls with a durable expiration and a valid signature', function
$this->travelBack();
});
+it('uses the workspace policy for asynchronous CSV download links', function () {
+ $user = $this->actingAsProUser();
+ $workspace = $this->createUserWorkspace($user);
+ $workspace->update([
+ 'settings' => [
+ 'external_file_links' => [
+ 'expires_in_hours' => 72,
+ ],
+ ],
+ ]);
+ $form = $this->createForm($user, $workspace);
+ $form->load('workspace');
+
+ Storage::fake();
+ $now = Carbon::parse('2026-07-17 17:00:00');
+ Carbon::setTestNow($now);
+
+ try {
+ $exportService = app(FormExportService::class);
+ $expiresAt = $exportService->fileLinkExpiresAt($form);
+ $fileUrl = $exportService->generateAndUploadCsvFile([
+ ['id' => 'submission-1'],
+ ], 'weekend-submissions.csv', $expiresAt);
+ } finally {
+ Carbon::setTestNow();
+ }
+
+ parse_str((string) parse_url($fileUrl, PHP_URL_QUERY), $queryParameters);
+
+ expect((int) ($queryParameters['expiration'] ?? 0))->toBe($now->copy()->addHours(72)->timestamp);
+ Storage::assertExists(FormExportService::EXPORT_FILE_PATH . 'weekend-submissions.csv');
+});
+
it('allows export status polling when the general api rate limit is exhausted', function () {
$this->withMiddleware(ThrottleRequests::class);
diff --git a/api/tests/Feature/Integrations/ExternalSubmissionFileLinkTest.php b/api/tests/Feature/Integrations/ExternalSubmissionFileLinkTest.php
new file mode 100644
index 000000000..1af5c0d8e
--- /dev/null
+++ b/api/tests/Feature/Integrations/ExternalSubmissionFileLinkTest.php
@@ -0,0 +1,135 @@
+<?php
+
+use App\Events\Forms\FormSubmitted;
+use App\Integrations\Handlers\AbstractIntegrationHandler;
+use App\Integrations\Handlers\DiscordIntegration;
+use App\Integrations\Handlers\SlackIntegration;
+use App\Integrations\Handlers\TelegramIntegration;
+use App\Integrations\Handlers\ZapierIntegration;
+use App\Models\Integration\FormIntegration;
+use App\Service\Forms\FormSubmissionFormatter;
+use Carbon\Carbon;
+
+function queryParameterFromFileLink(string $url, string $key): string
+{
+ parse_str((string) parse_url($url, PHP_URL_QUERY), $queryParameters);
+
+ return $queryParameters[$key] ?? '';
+}
+
+function formWithExternalFileLinkPolicy(object $test, int $expirationHours = 168): array
+{
+ $user = $test->actingAsProUser();
+ $workspace = $test->createUserWorkspace($user);
+ $workspace->update([
+ 'settings' => [
+ 'external_file_links' => [
+ 'expires_in_hours' => $expirationHours,
+ ],
+ ],
+ ]);
+
+ $form = $test->createForm($user, $workspace, [
+ 'properties' => [
+ [
+ 'id' => 'attachment',
+ 'name' => 'Attachment',
+ 'type' => 'files',
+ 'required' => false,
+ ],
+ ],
+ ]);
+ $form->load('workspace');
+
+ return [$form, ['attachment' => ['weekend-upload.png']]];
+}
+
+test('uses the configured workspace policy for signed submission file links', function () {
+ [$form, $submissionData] = formWithExternalFileLinkPolicy($this, 168);
+ $now = Carbon::parse('2026-07-17 17:00:00');
+ Carbon::setTestNow($now);
+
+ try {
+ $fields = (new FormSubmissionFormatter($form, $submissionData))
+ ->outputStringsOnly()
+ ->useSignedUrlForFiles()
+ ->getFieldsWithValue();
+ } finally {
+ Carbon::setTestNow();
+ }
+
+ $fileUrl = $fields[0]['value'];
+
+ expect(queryParameterFromFileLink($fileUrl, 'expires'))
+ ->toBe((string) $now->copy()->addHours(168)->timestamp);
+ expect(queryParameterFromFileLink($fileUrl, 'signature'))->not->toBeEmpty();
+});
+
+test('uses the workspace policy in generic webhook and Zapier payloads', function (string $integrationClass) {
+ [$form, $submissionData] = formWithExternalFileLinkPolicy($this, 72);
+ $now = Carbon::parse('2026-07-17 17:00:00');
+ Carbon::setTestNow($now);
+
+ try {
+ $payload = $integrationClass::formatWebhookData($form, $submissionData);
+ } finally {
+ Carbon::setTestNow();
+ }
+
+ $file = $payload['data']['attachment']['value']->first();
+
+ expect(queryParameterFromFileLink($file['file_url'], 'signature'))->not->toBeEmpty();
+ expect((int) queryParameterFromFileLink($file['file_url'], 'expires'))
+ ->toBe($now->copy()->addHours(72)->timestamp);
+})->with([
+ 'generic webhooks (Webhook, Activepieces and n8n)' => [AbstractIntegrationHandler::class],
+ 'Zapier' => [ZapierIntegration::class],
+]);
+
+test('signs file links in Slack, Discord and Telegram payloads', function (string $integrationClass, array $settings) {
+ [$form, $submissionData] = formWithExternalFileLinkPolicy($this, 72);
+ $integration = FormIntegration::factory()->make([
+ 'form_id' => $form->id,
+ 'data' => $settings,
+ ]);
+
+ $now = Carbon::parse('2026-07-17 17:00:00');
+ Carbon::setTestNow($now);
+
+ try {
+ $handler = new $integrationClass(new FormSubmitted($form, $submissionData), $integration, ['name' => 'Chat']);
+ $method = new ReflectionMethod($integrationClass, 'getWebhookData');
+ $method->setAccessible(true);
+ $payload = $method->invoke($handler);
+ } finally {
+ Carbon::setTestNow();
+ }
+
+ $payloadJson = html_entity_decode(json_encode($payload, JSON_UNESCAPED_SLASHES));
+ $payloadJson = str_replace('\\', '', $payloadJson);
+
+ expect($payloadJson)->toContain('signature=');
+ expect(preg_match('/expires=(\d+)/', $payloadJson, $matches))->toBe(1);
+ expect((int) $matches[1])->toBe($now->copy()->addHours(72)->timestamp);
+})->with([
+ 'Slack' => [
+ SlackIntegration::class,
+ [
+ 'slack_webhook_url' => 'https://hooks.slack.com/services/test/test/test',
+ 'include_submission_data' => true,
+ ],
+ ],
+ 'Discord' => [
+ DiscordIntegration::class,
+ [
+ 'discord_webhook_url' => 'https://discord.com/api/webhooks/test/test',
+ 'include_submission_data' => true,
+ ],
+ ],
+ 'Telegram' => [
+ TelegramIntegration::class,
+ [
+ 'include_submission_data' => true,
+ ],
+ ],
+]);
diff --git a/api/tests/Feature/Integrations/Google/Sheets/SpreadsheetManagerTest.php b/api/tests/Feature/Integrations/Google/Sheets/SpreadsheetManagerTest.php
index 4e8692d1d..0f8664da2 100644
--- a/api/tests/Feature/Integrations/Google/Sheets/SpreadsheetManagerTest.php
+++ b/api/tests/Feature/Integrations/Google/Sheets/SpreadsheetManagerTest.php
@@ -9,6 +9,7 @@ use App\Models\OAuthProvider;
use function PHPUnit\Framework\assertCount;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertSame;
+use function PHPUnit\Framework\assertTrue;
test('build columns', function () {
/** @var \App\Models\User $user */
@@ -162,3 +163,60 @@ test('build row', function () {
assertSame(['First value', '', 'Third value'], $row);
});
+
+test('build row uses the workspace policy for file links', function () {
+ /** @var \App\Models\User $user */
+ $user = $this->createUser();
+
+ /** @var \App\Models\Workspace $workspace */
+ $workspace = $this->createUserWorkspace($user);
+ $workspace->update([
+ 'settings' => [
+ 'external_file_links' => [
+ 'expires_in_hours' => 72,
+ ],
+ ],
+ ]);
+
+ /** @var \App\Models\Forms\Form $form */
+ $form = $this->createForm($user, $workspace, [
+ 'properties' => [
+ ['id' => 'upload', 'name' => 'Upload', 'type' => 'files'],
+ ],
+ ]);
+ $form->load('workspace');
+
+ /** @var \App\Models\OAuthProvider $provider */
+ $provider = OAuthProvider::factory()
+ ->for($user)
+ ->create();
+
+ /** @var FormIntegration $integration */
+ $integration = FormIntegration::factory()
+ ->for($form)
+ ->for($provider, 'provider')
+ ->create([
+ 'data' => new SpreadsheetData(
+ url: 'https://google.com',
+ spreadsheet_id: 'sp_test',
+ columns: [
+ ['id' => 'upload', 'name' => 'Upload'],
+ ]
+ )
+ ]);
+
+ $now = \Carbon\Carbon::parse('2026-07-17 17:00:00');
+ \Carbon\Carbon::setTestNow($now);
+
+ try {
+ $manager = new SpreadsheetManager(new Google($integration), $integration);
+ $row = $manager->buildRow(['upload' => ['weekend-upload.png']]);
+ } finally {
+ \Carbon\Carbon::setTestNow();
+ }
+
+ parse_str((string) parse_url($row[0], PHP_URL_QUERY), $queryParameters);
+
+ assertSame($now->copy()->addHours(72)->timestamp, (int) $queryParameters['expires']);
+ assertTrue(isset($queryParameters['signature']));
+});
diff --git a/api/tests/Feature/Workspaces/WorkspaceTest.php b/api/tests/Feature/Workspaces/WorkspaceTest.php
index 59bdefd26..5a4f47b35 100644
--- a/api/tests/Feature/Workspaces/WorkspaceTest.php
+++ b/api/tests/Feature/Workspaces/WorkspaceTest.php
@@ -325,6 +325,53 @@ describe('Custom Code Settings', function () {
});
});
+describe('External File Link Settings', function () {
+ it('defaults external file links to 24 hours', function () {
+ $user = $this->actingAsUser();
+ $workspace = $this->createUserWorkspace($user);
+
+ expect(app(\App\Service\Forms\ExternalSubmissionFileLinkPolicy::class)->expirationHours($workspace))
+ ->toBe(24);
+ });
+
+ it('can save external file link settings for a workspace', function () {
+ $user = $this->actingAsUser();
+ $workspace = $this->createUserWorkspace($user);
+ $workspace->update(['settings' => ['custom_code' => '<script>test</script>']]);
+
+ $this->putJson(route('open.workspaces.save-external-file-link-settings', $workspace), [
+ 'expires_in_hours' => 168,
+ ])->assertSuccessful();
+
+ $workspace->refresh();
+
+ expect($workspace->settings['external_file_links']['expires_in_hours'])->toBe(168);
+ expect($workspace->settings['custom_code'])->toBe('<script>test</script>');
+ });
+
+ it('validates external file link settings', function () {
+ $user = $this->actingAsUser();
+ $workspace = $this->createUserWorkspace($user);
+
+ $this->putJson(route('open.workspaces.save-external-file-link-settings', $workspace), [
+ 'expires_in_hours' => 48,
+ ])->assertUnprocessable()->assertJsonValidationErrors('expires_in_hours');
+ });
+
+ it('prevents non-admin users from saving external file link settings', function () {
+ $admin = $this->createUser();
+ $workspace = $this->createUserWorkspace($admin);
+
+ $member = $this->createUser();
+ $workspace->users()->attach($member, ['role' => 'user']);
+ $this->actingAsUser($member);
+
+ $this->putJson(route('open.workspaces.save-external-file-link-settings', $workspace), [
+ 'expires_in_hours' => 168,
+ ])->assertForbidden();
+ });
+});
+
describe('SMTP settings redaction', function () {
it('exposes email_settings to admin users', function () {
$admin = $this->actingAsProUser();
diff --git a/client/components/open/forms/FormExportModal.vue b/client/components/open/forms/FormExportModal.vue
index 0c1f7cb75..2ddf5b3a2 100644
--- a/client/components/open/forms/FormExportModal.vue
+++ b/client/components/open/forms/FormExportModal.vue
@@ -1,14 +1,16 @@
<template>
<div>
<!-- Export Button -->
- <UButton
- size="sm"
- color="neutral"
- variant="ghost"
- label="Export"
- :loading="isExporting"
- @click="startExport"
- />
+ <UTooltip :text="`Uploaded-file links in this export remain available for ${fileLinkExpirationLabel}.`">
+ <UButton
+ size="sm"
+ color="neutral"
+ variant="ghost"
+ label="Export"
+ :loading="isExporting"
+ @click="startExport"
+ />
+ </UTooltip>
<!-- Export Progress Modal -->
<UModal v-model:open="showModal">
@@ -125,6 +127,13 @@ const exportStatus = ref(null)
const exportError = ref(null)
const pollingInterval = ref(null)
+const fileLinkExpirationHours = computed(() => props.form?.workspace?.settings?.external_file_links?.expires_in_hours || 24)
+const fileLinkExpirationLabel = computed(() => {
+ const hours = fileLinkExpirationHours.value
+
+ return hours % 24 === 0 ? `${hours / 24} day${hours === 24 ? '' : 's'}` : `${hours} hours`
+})
+
// Continuous progress system
const learnedSpeed = ref(0) // Real speed learned from API calls (% per second)
const smoothProgress = ref(0)
diff --git a/client/components/open/integrations/EmailIntegration.vue b/client/components/open/integrations/EmailIntegration.vue
index 587bbe718..94a61ac5d 100644
--- a/client/components/open/integrations/EmailIntegration.vue
+++ b/client/components/open/integrations/EmailIntegration.vue
@@ -183,6 +183,18 @@
label="Include submission data"
help="If enabled the email will contain form submission answers"
/>
+ <p
+ v-if="integrationData.data.include_submission_data"
+ class="mt-2 text-xs text-neutral-500"
+ >
+ Uploaded-file links follow your workspace security policy ({{ externalFileLinkExpirationLabel }}).
+ <a
+ class="cursor-pointer underline"
+ @click="openWorkspaceSettings('external-file-links')"
+ >
+ Change policy
+ </a>
+ </p>
<toggle-switch-input
v-if="integrationData.data.include_submission_data"
:form="integrationData"
@@ -245,6 +257,12 @@ const showGoogleFontPicker = ref(false)
const workspaceFeatures = computed(() => props.form?.workspace?.features ?? [])
const canUseAdvancedEmail = computed(() => workspaceFeatures.value.includes('integrations.email.advanced'))
const canUseAdvancedBranding = computed(() => workspaceFeatures.value.includes('branding.advanced'))
+const externalFileLinkExpirationHours = computed(() => props.form?.workspace?.settings?.external_file_links?.expires_in_hours || 24)
+const externalFileLinkExpirationLabel = computed(() => {
+ const hours = externalFileLinkExpirationHours.value
+
+ return hours % 24 === 0 ? `${hours / 24} day${hours === 24 ? '' : 's'}` : `${hours} hours`
+})
function onApplyFont(val) {
if (props.integrationData.data) {
diff --git a/client/components/workspaces/settings/ExternalFileLinks.vue b/client/components/workspaces/settings/ExternalFileLinks.vue
new file mode 100644
index 000000000..ef06673e8
--- /dev/null
+++ b/client/components/workspaces/settings/ExternalFileLinks.vue
@@ -0,0 +1,84 @@
+<template>
+ <div class="space-y-4">
+ <div>
+ <h3 class="text-lg font-medium text-neutral-900">External file links</h3>
+ <p class="mt-1 text-sm text-neutral-500">
+ Control how long uploaded-file links shared outside your workspace remain available.
+ </p>
+ </div>
+
+ <UAlert
+ icon="i-heroicons-shield-check"
+ color="warning"
+ variant="subtle"
+ title="Anyone with a link can access the file until it expires"
+ description="This policy applies to links in email notifications, CSV exports, webhooks, chat integrations and Google Sheets. It only affects newly generated links."
+ />
+
+ <VForm size="sm">
+ <form @submit.prevent="saveChanges">
+ <div class="max-w-xl">
+ <OptionSelectorInput
+ :form="externalFileLinkSettingsForm"
+ name="expires_in_hours"
+ label="Link validity"
+ :options="expirationOptions"
+ :columns="5"
+ seamless
+ />
+ </div>
+
+ <div class="mt-4">
+ <UButton
+ type="submit"
+ :loading="externalFileLinkSettingsForm.busy"
+ >
+ Save changes
+ </UButton>
+ </div>
+ </form>
+ </VForm>
+ </div>
+</template>
+
+<script setup>
+const alert = useAlert()
+const { current: workspace } = useCurrentWorkspace()
+const { invalidateAll } = useWorkspaces()
+
+const expirationOptions = [
+ { name: 24, label: '24 hours' },
+ { name: 72, label: '3 days' },
+ { name: 168, label: '7 days' },
+ { name: 336, label: '14 days' },
+ { name: 720, label: '30 days' },
+]
+
+const externalFileLinkSettingsForm = useForm({
+ expires_in_hours: 24,
+})
+
+function initSettings() {
+ externalFileLinkSettingsForm.expires_in_hours = workspace.value?.settings?.external_file_links?.expires_in_hours || 24
+}
+
+function saveChanges() {
+ externalFileLinkSettingsForm
+ .put(`/open/workspaces/${workspace.value.id}/external-file-link-settings`)
+ .then(() => {
+ invalidateAll()
+ alert.success('External file link settings saved.')
+ })
+ .catch((error) => {
+ alert.error('Failed to update external file link settings: ' + (error.response?.data?.message || 'Unknown error'))
+ })
+}
+
+onMounted(() => {
+ initSettings()
+})
+
+watch(workspace, () => {
+ initSettings()
+})
+</script>
diff --git a/client/components/workspaces/settings/Modal.vue b/client/components/workspaces/settings/Modal.vue
index 82f16cf71..ffe4eb213 100644
--- a/client/components/workspaces/settings/Modal.vue
+++ b/client/components/workspaces/settings/Modal.vue
@@ -40,11 +40,20 @@
<LazyWorkspacesSettingsEmails />
</SettingsModalPage>
+ <SettingsModalPage
+ v-if="workspace && workspace.is_admin"
+ id="external-file-links"
+ label="Security & data"
+ icon="i-heroicons-shield-check"
+ >
+ <LazyWorkspacesSettingsExternalFileLinks />
+ </SettingsModalPage>
+
<SettingsModalPage
v-if="workspace && workspace.is_admin"
id="sso"
label="SSO"
- icon="i-heroicons-shield-check"
+ icon="i-heroicons-key"
>
<LazyWorkspacesSettingsSso />
</SettingsModalPage>
@@ -102,4 +111,4 @@ const localActiveTab = computed({
const closeModal = () => {
emit('update:activeTab', null)
}
-</script>
\ No newline at end of file
+</script>
diff --git a/docs/api-reference/openapi.yaml b/docs/api-reference/openapi.yaml
index 45a8d6104..8aca1563c 100644
--- a/docs/api-reference/openapi.yaml
+++ b/docs/api-reference/openapi.yaml
@@ -1549,7 +1549,7 @@ components:
expires_at:
type: string
format: date-time
- description: "File expiration timestamp (24 hours from completion)"
+ description: "File expiration timestamp (workspace policy, 24 hours by default)"
nullable: true
error_message:
type: string
diff --git a/docs/api-reference/submissions/export-status.mdx b/docs/api-reference/submissions/export-status.mdx
index 4d2e6d80d..2613bf836 100644
--- a/docs/api-reference/submissions/export-status.mdx
+++ b/docs/api-reference/submissions/export-status.mdx
@@ -88,7 +88,7 @@ Authorization: Bearer <token>
| `processed_submissions` | number | Number of submissions processed so far |
| `total_submissions` | number | Total number of submissions to process |
| `file_url` | string | Download URL for completed exports |
-| `expires_at` | string | File expiration timestamp (24 hours from completion) |
+| `expires_at` | string | File expiration timestamp (workspace policy, 24 hours by default) |
| `error_message` | string | Error description for failed exports |
| `created_at` | string | Job creation timestamp |
| `updated_at` | string | Last update timestamp |
@@ -99,8 +99,8 @@ Authorization: Bearer <token>
</Note>
<Warning>
- Export files are automatically deleted after 24 hours for security and
- storage management.
+ The download URL is a bearer link. It remains valid until `expires_at`,
+ according to the workspace file-link policy (24 hours by default).
</Warning>
## Error Responses
@@ -130,7 +130,7 @@ After initiating an export that returns `is_async: true`, poll this endpoint to
When status is `completed`, use the `file_url` to download your CSV file.
<Warning>
- Download the file promptly as it expires in 24 hours.
+ Download the file before the `expires_at` timestamp. The workspace policy is 24 hours by default.
</Warning>
</Step>
</Steps>
diff --git a/docs/configuration/external-file-links.mdx b/docs/configuration/external-file-links.mdx
new file mode 100644
index 000000000..7e9092093
--- /dev/null
+++ b/docs/configuration/external-file-links.mdx
@@ -0,0 +1,36 @@
+---
+title: External File Link Validity
+description: Control how long uploaded-file links remain accessible outside your workspace
+---
+
+File links shared outside a workspace are bearer links: anyone who has the link
+can download the file until the link expires. Each workspace admin can choose
+how long those links remain valid.
+
+## Configure the validity period
+
+1. Open the workspace settings.
+2. Select **Security & data**.
+3. Under **External file links**, choose 24 hours, 3 days, 7 days, 14 days, or
+ 30 days, then save.
+
+New workspaces use a 24-hour validity period by default.
+
+## Where the policy applies
+
+The selected period is used for new uploaded-file links included in:
+
+- Form email notifications
+- CSV exports, including the download link for asynchronous exports
+- Webhooks, Activepieces, n8n, and Zapier
+- Slack, Discord, and Telegram notifications
+- Google Sheets rows
+
+Existing links keep their original expiration. Internal dashboard file previews
+and form assets are not changed by this workspace setting.
+
+<Warning>
+ Choose the shortest period that still fits the recipient's workflow. For
+ example, a team that processes weekend submissions on Monday can select
+ 72 hours so links sent on Friday remain available through Monday.
+</Warning>
diff --git a/docs/docs.json b/docs/docs.json
index c257dd5c3..1eb801d1d 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -55,6 +55,7 @@
"configuration/environment-variables",
"configuration/oauth-setup",
"configuration/aws-s3",
+ "configuration/external-file-links",
"configuration/email-setup",
"configuration/custom-domain",
"configuration/subdomain-redirect",