Skip to content

Beautiful Open-Source Form Builder

Fix self-hosted signed file URL validation (#1284)

Julien Nahum2c466ba584e5
diff --git a/api/app/Http/Controllers/Forms/FormSubmissionController.php b/api/app/Http/Controllers/Forms/FormSubmissionController.php
index 1a3f75d86..ffb8e079a 100644
--- a/api/app/Http/Controllers/Forms/FormSubmissionController.php
+++ b/api/app/Http/Controllers/Forms/FormSubmissionController.php
@@ -28,7 +28,7 @@ class FormSubmissionController extends Controller
public function __construct()
{
$this->middleware('auth', ['except' => ['submissionFile']]);
- $this->middleware('signed', ['only' => ['submissionFile']]);
+ $this->middleware('signed:relative', ['only' => ['submissionFile']]);
}
public function submissions(Form $form)
diff --git a/api/app/Http/Controllers/Pdf/PdfGenerateController.php b/api/app/Http/Controllers/Pdf/PdfGenerateController.php
index 9d55b528e..baf586efd 100644
--- a/api/app/Http/Controllers/Pdf/PdfGenerateController.php
+++ b/api/app/Http/Controllers/Pdf/PdfGenerateController.php
@@ -65,7 +65,7 @@ class PdfGenerateController extends Controller
abort(404, 'Template not found.');
}
- $url = URL::temporarySignedRoute(
+ $url = URL::temporaryPublicSignedRoute(
'open.forms.pdf-templates.preview-signed',
now()->addMinutes(15),
[
@@ -174,7 +174,7 @@ class PdfGenerateController extends Controller
): string {
$submissionId = SubmissionUrlService::getSubmissionIdentifier($submission);
- return URL::temporarySignedRoute(
+ return URL::temporaryPublicSignedRoute(
'open.forms.pdf-templates.download-submission',
now()->addHours(24),
[
diff --git a/api/app/Http/Resources/FormSubmissionResource.php b/api/app/Http/Resources/FormSubmissionResource.php
index d1c041d36..90d528a19 100644
--- a/api/app/Http/Resources/FormSubmissionResource.php
+++ b/api/app/Http/Resources/FormSubmissionResource.php
@@ -101,7 +101,7 @@ class FormSubmissionResource extends JsonResource
$encodedFilename = FilenameUrlEncoder::encode($file);
return [
- 'file_url' => URL::signedRoute(
+ 'file_url' => URL::publicSignedRoute(
'open.forms.submissions.file',
[$this->form_id, $encodedFilename],
now()->addMinutes(10)
diff --git a/api/app/Providers/AppServiceProvider.php b/api/app/Providers/AppServiceProvider.php
index 4d37a0137..9197bb7f6 100644
--- a/api/app/Providers/AppServiceProvider.php
+++ b/api/app/Providers/AppServiceProvider.php
@@ -24,9 +24,27 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
+ $toPublicUrl = static function (string $relativeUrl): string {
+ $appUrl = config('app.url');
+
+ if (! is_string($appUrl) || $appUrl === '') {
+ return $relativeUrl;
+ }
+
+ return rtrim($appUrl, '/') . '/' . ltrim($relativeUrl, '/');
+ };
+
+ URL::macro('publicSignedRoute', function ($name, $parameters = [], $expiration = null) use ($toPublicUrl) {
+ return $toPublicUrl(URL::signedRoute($name, $parameters, $expiration, false));
+ });
+
+ URL::macro('temporaryPublicSignedRoute', function ($name, $expiration, $parameters = []) {
+ return URL::publicSignedRoute($name, $parameters, $expiration);
+ });
+
if (config('filesystems.default') === 'local') {
Storage::disk('local')->buildTemporaryUrlsUsing(function ($path, $expiration, $options) {
- return URL::temporarySignedRoute(
+ return URL::temporaryPublicSignedRoute(
'local.temp',
$expiration,
array_merge($options, ['path' => $path])
diff --git a/api/app/Service/Forms/FormSubmissionFormatter.php b/api/app/Service/Forms/FormSubmissionFormatter.php
index 8875c13d8..4d73542d0 100644
--- a/api/app/Service/Forms/FormSubmissionFormatter.php
+++ b/api/app/Service/Forms/FormSubmissionFormatter.php
@@ -417,7 +417,7 @@ class FormSubmissionFormatter
// See: https://github.com/OpnForm/OpnForm/issues/1024
$encodedFilename = FilenameUrlEncoder::encode($file);
- return $this->useSignedUrlForFiles ? URL::temporarySignedRoute(
+ return $this->useSignedUrlForFiles ? URL::temporaryPublicSignedRoute(
'open.forms.submissions.file',
$this->signedFileUrlExpiration ?? now()->addMinutes(self::SIGNED_FILE_URL_EXPIRATION_MINUTES),
[$formId, $encodedFilename]
diff --git a/api/app/Service/Forms/FormSummaryService.php b/api/app/Service/Forms/FormSummaryService.php
index fe96826a4..e5696ff80 100644
--- a/api/app/Service/Forms/FormSummaryService.php
+++ b/api/app/Service/Forms/FormSummaryService.php
@@ -524,7 +524,7 @@ class FormSummaryService
return $item;
}
- $item['value'] = URL::signedRoute(
+ $item['value'] = URL::publicSignedRoute(
'open.forms.submissions.file',
[$formId, $item['value']],
now()->addMinutes(10)
diff --git a/api/routes/api.php b/api/routes/api.php
index 34d7ef1c5..ecc10c884 100644
--- a/api/routes/api.php
+++ b/api/routes/api.php
@@ -265,7 +265,7 @@ Route::group(['middleware' => 'auth.multi'], function () {
->middleware('throttle:export-status')
->name('export.status');
Route::get('/file/{filename}', [FormSubmissionController::class, 'submissionFile'])
- ->middleware('signed')
+ ->middleware('signed:relative')
->withoutMiddleware(['auth.multi'])
->name('file');
Route::delete('/{submission_id}', [FormSubmissionController::class, 'destroy'])->name('destroy');
@@ -351,7 +351,7 @@ Route::group(['middleware' => 'auth.multi'], function () {
'/{form}/pdf-templates/{pdfTemplate}/submissions/{submission_id}/download',
[PdfGenerateController::class, 'downloadByTemplate']
)
- ->middleware('signed')
+ ->middleware('signed:relative')
->withoutMiddleware(['auth.multi'])
->name('pdf-templates.download-submission');
@@ -360,7 +360,7 @@ Route::group(['middleware' => 'auth.multi'], function () {
'/{form}/pdf-templates/{pdfTemplate}/preview',
[PdfGenerateController::class, 'previewBySignature']
)
- ->middleware('signed')
+ ->middleware('signed:relative')
->withoutMiddleware(['auth.multi'])
->name('pdf-templates.preview-signed');
});
@@ -566,7 +566,7 @@ Route::post(
)->middleware('throttle:public-uploads')->name('upload-file');
Route::get('local/temp/{path}', function (Request $request, string $path) {
- if (!$request->hasValidSignature()) {
+ if (!$request->hasValidRelativeSignature()) {
abort(401);
}
diff --git a/api/tests/Feature/Forms/FileDownloadSecurityTest.php b/api/tests/Feature/Forms/FileDownloadSecurityTest.php
index 5db7dfea2..671718197 100644
--- a/api/tests/Feature/Forms/FileDownloadSecurityTest.php
+++ b/api/tests/Feature/Forms/FileDownloadSecurityTest.php
@@ -31,7 +31,11 @@ it('forces attachment download with safe headers for submission files', function
// Call signed file route with encoded filename (as the new implementation does)
// See: https://github.com/OpnForm/OpnForm/issues/1024
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute(
+ 'open.forms.submissions.file',
+ [$form->id, $encodedFilename],
+ absolute: false
+ );
$response = $this->get($signedUrl);
$response->assertOk();
@@ -66,7 +70,11 @@ it('does not eager load workspace users for signed submission file downloads', f
]);
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute(
+ 'open.forms.submissions.file',
+ [$form->id, $encodedFilename],
+ absolute: false
+ );
DB::flushQueryLog();
DB::enableQueryLog();
diff --git a/api/tests/Feature/Forms/FileDownloadSpecialCharsTest.php b/api/tests/Feature/Forms/FileDownloadSpecialCharsTest.php
index 237e0a931..4d5b2779e 100644
--- a/api/tests/Feature/Forms/FileDownloadSpecialCharsTest.php
+++ b/api/tests/Feature/Forms/FileDownloadSpecialCharsTest.php
@@ -31,7 +31,7 @@ describe('File download with special characters in filename', function () {
// Use base64url encoded filename (as the new implementation does)
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename], absolute: false);
$response = $this->get($signedUrl);
$response->assertOk();
@@ -59,7 +59,7 @@ describe('File download with special characters in filename', function () {
]);
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename], absolute: false);
$response = $this->get($signedUrl);
$response->assertOk();
@@ -87,7 +87,7 @@ describe('File download with special characters in filename', function () {
]);
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename], absolute: false);
$response = $this->get($signedUrl);
$response->assertOk();
@@ -116,7 +116,7 @@ describe('File download with special characters in filename', function () {
]);
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename], absolute: false);
$response = $this->get($signedUrl);
$response->assertOk();
@@ -143,7 +143,7 @@ describe('File download with special characters in filename', function () {
]);
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename], absolute: false);
$response = $this->get($signedUrl);
$response->assertOk();
@@ -170,7 +170,7 @@ describe('File download with special characters in filename', function () {
]);
$encodedFilename = FilenameUrlEncoder::encode($fileName);
- $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename]);
+ $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $encodedFilename], absolute: false);
$response = $this->get($signedUrl);
$response->assertOk();
diff --git a/api/tests/Feature/Forms/FormSubmissionResourceTest.php b/api/tests/Feature/Forms/FormSubmissionResourceTest.php
index 26575228c..16b0c877c 100644
--- a/api/tests/Feature/Forms/FormSubmissionResourceTest.php
+++ b/api/tests/Feature/Forms/FormSubmissionResourceTest.php
@@ -4,6 +4,8 @@ use App\Models\Forms\FormSubmission;
use Illuminate\Support\Str;
it('sanitizes rich_text and maps files in FormSubmissionResource', function () {
+ config()->set('app.url', 'https://forms.example.test');
+
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
@@ -55,7 +57,9 @@ it('sanitizes rich_text and maps files in FormSubmissionResource', function () {
expect($data[$filesId])->toBeArray();
expect($data[$filesId])->toHaveCount(2);
expect($data[$filesId][0]['file_name'])->toBe($files[0]);
- expect($data[$filesId][0]['file_url'])->toBeString();
+ expect($data[$filesId][0]['file_url'])
+ ->toStartWith('https://forms.example.test/open/forms/')
+ ->toContain('signature=');
// Plain text remains raw (escaping is at render time)
expect($data[$textId])->toBe($textPayload);
diff --git a/api/tests/Feature/Forms/FormSummaryTest.php b/api/tests/Feature/Forms/FormSummaryTest.php
index df1f2bc29..77bbb13e8 100644
--- a/api/tests/Feature/Forms/FormSummaryTest.php
+++ b/api/tests/Feature/Forms/FormSummaryTest.php
@@ -98,8 +98,14 @@ describe('Form Summary', function () {
});
it('returns correct summary types for different field types', function () {
+ config()->set('app.url', 'https://forms.example.test');
+
+ $submissionData = $this->generateFormSubmissionData($this->form, [], true);
+ $filesProperty = collect($this->form->properties)->firstWhere('type', 'files');
+ $submissionData[$filesProperty['id']] = ['summary-file.png'];
+
$this->form->submissions()->create([
- 'data' => $this->generateFormSubmissionData($this->form, [], true),
+ 'data' => $submissionData,
'status' => FormSubmission::STATUS_COMPLETED,
]);
@@ -131,6 +137,11 @@ describe('Form Summary', function () {
// Check date field has date_summary summary type
$dateField = $fields->firstWhere('type', 'date');
expect($dateField['summary_type'])->toBe('date_summary');
+
+ $filesField = $fields->firstWhere('type', 'files');
+ expect($filesField['data']['values'][0]['value'])
+ ->toStartWith('https://forms.example.test/open/forms/')
+ ->toContain('signature=');
});
it('calculates numeric stats correctly', function () {
diff --git a/api/tests/Feature/Forms/PublicAssetSecurityTest.php b/api/tests/Feature/Forms/PublicAssetSecurityTest.php
index 8a3f3dc58..56dc60f00 100644
--- a/api/tests/Feature/Forms/PublicAssetSecurityTest.php
+++ b/api/tests/Feature/Forms/PublicAssetSecurityTest.php
@@ -2,7 +2,6 @@
use App\Http\Controllers\Forms\FormController;
use Illuminate\Support\Facades\Storage;
-use Illuminate\Support\Facades\URL;
function pngFixture(): string
{
@@ -49,22 +48,31 @@ it('serves non-image public assets as attachments with restrictive headers', fun
});
it('serves signed local temporary files with restrictive anti-execution headers', function () {
- Storage::fake();
+ config()->set('app.url', 'https://forms.example.test');
$path = 'tmp/' . uniqid() . '.html';
- Storage::put($path, '<html><script>alert(1)</script></html>');
+ Storage::disk('local')->put($path, '<html><script>alert(1)</script></html>');
- $signedUrl = URL::temporarySignedRoute('local.temp', now()->addMinute(), ['path' => $path]);
- $response = $this->get($signedUrl);
+ try {
+ $signedUrl = Storage::disk('local')->temporaryUrl($path, now()->addMinute());
+ expect($signedUrl)->toStartWith('https://forms.example.test/local/temp/');
- $response->assertOk();
- expect(strtolower($response->headers->get('content-type')))
- ->toStartWith('text/html');
- expect($response->headers->get('content-disposition'))
- ->toStartWith('attachment;');
- expect($response->headers->get('x-content-type-options'))
- ->toBe('nosniff');
- expect($response->headers->get('content-security-policy'))
- ->toContain("script-src 'none'")
- ->toContain('sandbox');
+ $relativeSignedUrl = parse_url($signedUrl, PHP_URL_PATH).'?'.parse_url($signedUrl, PHP_URL_QUERY);
+ $response = $this
+ ->withServerVariables(['HTTP_HOST' => 'self-hosted.example.test'])
+ ->get($relativeSignedUrl);
+
+ $response->assertOk();
+ expect(strtolower($response->headers->get('content-type')))
+ ->toStartWith('text/html');
+ expect($response->headers->get('content-disposition'))
+ ->toStartWith('attachment;');
+ expect($response->headers->get('x-content-type-options'))
+ ->toBe('nosniff');
+ expect($response->headers->get('content-security-policy'))
+ ->toContain("script-src 'none'")
+ ->toContain('sandbox');
+ } finally {
+ Storage::disk('local')->delete($path);
+ }
});
diff --git a/api/tests/Feature/Integrations/ExternalSubmissionFileLinkTest.php b/api/tests/Feature/Integrations/ExternalSubmissionFileLinkTest.php
index 1af5c0d8e..4f987fd37 100644
--- a/api/tests/Feature/Integrations/ExternalSubmissionFileLinkTest.php
+++ b/api/tests/Feature/Integrations/ExternalSubmissionFileLinkTest.php
@@ -8,7 +8,9 @@ use App\Integrations\Handlers\TelegramIntegration;
use App\Integrations\Handlers\ZapierIntegration;
use App\Models\Integration\FormIntegration;
use App\Service\Forms\FormSubmissionFormatter;
+use App\Service\Storage\FileUploadPathService;
use Carbon\Carbon;
+use Illuminate\Support\Facades\Storage;
function queryParameterFromFileLink(string $url, string $key): string
{
@@ -45,7 +47,14 @@ function formWithExternalFileLinkPolicy(object $test, int $expirationHours = 168
}
test('uses the configured workspace policy for signed submission file links', function () {
+ config()->set('app.url', 'https://forms.example.test');
+ Storage::fake('local');
+
[$form, $submissionData] = formWithExternalFileLinkPolicy($this, 168);
+ Storage::put(
+ FileUploadPathService::getFileUploadPath($form->id, 'weekend-upload.png'),
+ 'test image content'
+ );
$now = Carbon::parse('2026-07-17 17:00:00');
Carbon::setTestNow($now);
@@ -54,15 +63,22 @@ test('uses the configured workspace policy for signed submission file links', fu
->outputStringsOnly()
->useSignedUrlForFiles()
->getFieldsWithValue();
+
+ $fileUrl = $fields[0]['value'];
+
+ expect($fileUrl)->toStartWith('https://forms.example.test/open/forms/');
+ expect(queryParameterFromFileLink($fileUrl, 'expires'))
+ ->toBe((string) $now->copy()->addHours(168)->timestamp);
+ expect(queryParameterFromFileLink($fileUrl, 'signature'))->not->toBeEmpty();
+
+ $relativeFileUrl = parse_url($fileUrl, PHP_URL_PATH).'?'.parse_url($fileUrl, PHP_URL_QUERY);
+ $this
+ ->withServerVariables(['HTTP_HOST' => 'self-hosted.example.test'])
+ ->get($relativeFileUrl)
+ ->assertOk();
} 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) {
diff --git a/api/tests/Feature/Integrations/Pdf/PdfGenerateTest.php b/api/tests/Feature/Integrations/Pdf/PdfGenerateTest.php
index 77ade4f26..6eb486eef 100644
--- a/api/tests/Feature/Integrations/Pdf/PdfGenerateTest.php
+++ b/api/tests/Feature/Integrations/Pdf/PdfGenerateTest.php
@@ -57,7 +57,9 @@ describe('PDF Template - Signed URL', function () {
->assertJsonStructure(['url']);
$url = $response->json('url');
- expect($url)->toContain('signature=');
+ expect($url)
+ ->toStartWith(config('app.url').'/open/forms/')
+ ->toContain('signature=');
});
it('requires authentication to get signed url', function () {
@@ -163,6 +165,8 @@ describe('PDF Template - Signed URL', function () {
describe('PDF Template - Download', function () {
it('can generate and download pdf with valid signed url', function () {
+ config()->set('app.url', 'https://forms.example.test');
+
$user = $this->actingAsProUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
@@ -188,19 +192,29 @@ describe('PDF Template - Download', function () {
'data' => ['name' => 'John Doe'],
]);
- // Generate signed URL
- $signedUrl = URL::temporarySignedRoute(
- 'open.forms.pdf-templates.download-submission',
- now()->addHours(1),
+ $signedUrlEndpoint = route(
+ 'open.forms.pdf-templates.submission.signed-url',
[
'form' => $form->id,
'pdfTemplate' => $template->id,
'submission_id' => getEncodedSubmissionId($submission),
- ]
+ ],
+ absolute: false
);
+ $signedUrlResponse = $this
+ ->withServerVariables(['HTTP_HOST' => 'internal-proxy.example.test'])
+ ->getJson($signedUrlEndpoint);
+ $signedUrlResponse->assertSuccessful();
+ $signedUrl = $signedUrlResponse->json('url');
- // Extract path from URL for testing
- $response = $this->get($signedUrl);
+ expect($signedUrl)->toStartWith('https://forms.example.test/open/forms/');
+
+ $relativeSignedUrl = parse_url($signedUrl, PHP_URL_PATH).'?'.parse_url($signedUrl, PHP_URL_QUERY);
+
+ // The public hostname may differ from the one used by Laravel behind a reverse proxy.
+ $response = $this
+ ->withServerVariables(['HTTP_HOST' => 'self-hosted.example.test'])
+ ->get($relativeSignedUrl);
$response->assertSuccessful()
->assertHeader('content-type', 'application/pdf');
@@ -273,7 +287,8 @@ describe('PDF Template - Download', function () {
'form' => $form->id,
'pdfTemplate' => $template->id,
'submission_id' => getEncodedSubmissionId($submission),
- ]
+ ],
+ absolute: false
);
$response = $this->get($signedUrl);
@@ -317,7 +332,17 @@ describe('PDF Template - Preview', function () {
$response->assertSuccessful()
->assertJsonStructure(['url']);
- expect(str_contains($response->json('url'), 'pdf-templates'))->toBeTrue();
+ $signedUrl = $response->json('url');
+ expect($signedUrl)
+ ->toStartWith(config('app.url').'/open/forms/')
+ ->toContain('signature=');
+
+ $relativeSignedUrl = parse_url($signedUrl, PHP_URL_PATH).'?'.parse_url($signedUrl, PHP_URL_QUERY);
+ $this
+ ->withServerVariables(['HTTP_HOST' => 'self-hosted.example.test'])
+ ->get($relativeSignedUrl)
+ ->assertSuccessful()
+ ->assertHeader('content-type', 'application/pdf');
});
it('can preview pdf with empty data when no submissions exist', function () {
@@ -350,7 +375,9 @@ describe('PDF Template - Preview', function () {
$response->assertSuccessful()
->assertJsonStructure(['url']);
- expect(str_contains($response->json('url'), 'pdf-templates'))->toBeTrue();
+ expect($response->json('url'))
+ ->toStartWith(config('app.url').'/open/forms/')
+ ->toContain('signature=');
});
it('requires authentication for preview', function () {
@@ -432,7 +459,8 @@ describe('PDF with Zone Mappings', function () {
'form' => $form->id,
'pdfTemplate' => $template->id,
'submission_id' => getEncodedSubmissionId($submission),
- ]
+ ],
+ absolute: false
);
$response = $this->get($signedUrl);
@@ -489,7 +517,8 @@ describe('PDF with Zone Mappings', function () {
'form' => $form->id,
'pdfTemplate' => $template->id,
'submission_id' => getEncodedSubmissionId($submission),
- ]
+ ],
+ absolute: false
);
$response = $this->get($signedUrl);
@@ -531,7 +560,8 @@ describe('PDF Branding', function () {
'form' => $form->id,
'pdfTemplate' => $template->id,
'submission_id' => getEncodedSubmissionId($submission),
- ]
+ ],
+ absolute: false
);
$response = $this->get($signedUrl);
@@ -571,7 +601,8 @@ describe('PDF Branding', function () {
'form' => $form->id,
'pdfTemplate' => $template->id,
'submission_id' => getEncodedSubmissionId($submission),
- ]
+ ],
+ absolute: false
);
$response = $this->get($signedUrl);
diff --git a/api/tests/Feature/Submissions/EditSubmissionTest.php b/api/tests/Feature/Submissions/EditSubmissionTest.php
index 8764267ca..ab7e123c2 100644
--- a/api/tests/Feature/Submissions/EditSubmissionTest.php
+++ b/api/tests/Feature/Submissions/EditSubmissionTest.php
@@ -81,7 +81,7 @@ it('keeps an existing upload canonical when an edited submission submits its sig
'status' => FormSubmission::STATUS_COMPLETED,
]);
- $signedUploadUrl = URL::signedRoute(
+ $signedUploadUrl = URL::publicSignedRoute(
'open.forms.submissions.file',
[$form->id, FilenameUrlEncoder::encode($fileName)]
);
diff --git a/api/tests/Feature/Support/PublicSignedUrlMacroTest.php b/api/tests/Feature/Support/PublicSignedUrlMacroTest.php
new file mode 100644
index 000000000..213dbd28c
--- /dev/null
+++ b/api/tests/Feature/Support/PublicSignedUrlMacroTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Facades\URL;
+
+beforeEach(function () {
+ Route::get('/signed-url-test/{value}', fn () => 'ok')
+ ->name('signed-url-test')
+ ->middleware('signed:relative');
+ Route::getRoutes()->refreshNameLookups();
+});
+
+it('returns a canonical absolute URL with a relative signature', function () {
+ config()->set('app.url', 'https://forms.example.test/');
+
+ $url = URL::publicSignedRoute('signed-url-test', ['value' => 123]);
+
+ expect($url)->toStartWith('https://forms.example.test/signed-url-test/123?signature=');
+
+ $this->get($url)->assertOk();
+});
+
+it('returns a canonical temporary URL with a valid relative signature', function () {
+ config()->set('app.url', 'https://forms.example.test/');
+
+ $url = URL::temporaryPublicSignedRoute(
+ 'signed-url-test',
+ now()->addMinute(),
+ ['value' => 123]
+ );
+
+ expect($url)
+ ->toStartWith('https://forms.example.test/signed-url-test/123?expires=')
+ ->toContain('&signature=');
+
+ $this->get($url)->assertOk();
+});
+
+it('falls back to the relative signed URL when the application URL is missing', function () {
+ config()->set('app.url', null);
+
+ $url = URL::publicSignedRoute('signed-url-test', ['value' => 123]);
+
+ expect($url)->toStartWith('/signed-url-test/123?signature=');
+
+ $this->get($url)->assertOk();
+});