Beautiful Open-Source Form Builder
Security patches (#900)
Julien Nahum36dad12ac1ee
diff --git a/api/.env.example b/api/.env.exampleindex 03ce6194c..488f51015 100644--- a/api/.env.example+++ b/api/.env.example@@ -20,7 +20,7 @@ DB_DATABASE=postgresDB_USERNAME=postgresDB_PASSWORD=postgres-FILESYSTEM_DRIVER=s3+FILESYSTEM_DRIVER=localBROADCAST_CONNECTION=logCACHE_STORE=filediff --git a/api/app/Http/Controllers/Auth/LoginController.php b/api/app/Http/Controllers/Auth/LoginController.phpindex 2b77ea020..9042a06be 100644--- a/api/app/Http/Controllers/Auth/LoginController.php+++ b/api/app/Http/Controllers/Auth/LoginController.php@@ -118,6 +118,15 @@ class LoginController extends Controller]);}+ /**+ * Customize throttling to be per-credential (email) instead of IP-based, to avoid X-Forwarded-For spoofing bypasses.+ */+ protected function throttleKey(Request $request)+ {+ $email = strtolower((string) $request->input($this->username()));+ return 'login:' . sha1($email !== '' ? $email : 'unknown');+ }+/*** Log the user out of the application.*diff --git a/api/app/Http/Controllers/Forms/FormSubmissionController.php b/api/app/Http/Controllers/Forms/FormSubmissionController.phpindex f0b00da77..5c7221922 100644--- a/api/app/Http/Controllers/Forms/FormSubmissionController.php+++ b/api/app/Http/Controllers/Forms/FormSubmissionController.php@@ -165,11 +165,27 @@ class FormSubmissionController extends Controller}if (config('filesystems.default') !== 's3') {- return response()->file(Storage::path($fileName));+ return response()->download(+ Storage::path($fileName),+ basename($fileName),+ [+ 'Content-Type' => 'application/octet-stream',+ 'X-Content-Type-Options' => 'nosniff',+ 'Content-Disposition' => 'attachment; filename="' . basename($fileName) . '"'+ ]+ );}+ // Force download on S3 as wellreturn redirect(- Storage::temporaryUrl($fileName, now()->addMinute())+ Storage::temporaryUrl(+ $fileName,+ now()->addMinute(),+ [+ 'ResponseContentDisposition' => 'attachment; filename="' . basename($fileName) . '"',+ 'ResponseContentType' => 'application/octet-stream'+ ]+ ));}diff --git a/api/app/Http/Controllers/Forms/Integration/FormIntegrationsController.php b/api/app/Http/Controllers/Forms/Integration/FormIntegrationsController.phpindex 693573f59..2a71cb22c 100644--- a/api/app/Http/Controllers/Forms/Integration/FormIntegrationsController.php+++ b/api/app/Http/Controllers/Forms/Integration/FormIntegrationsController.php@@ -17,7 +17,7 @@ class FormIntegrationsController extends Controllerpublic function index(Form $form){- $this->authorize('view', $form);+ $this->authorize('update', $form);$integrations = FormIntegration::query()->where('form_id', $form->id)diff --git a/api/app/Http/Controllers/Forms/Integration/FormIntegrationsEventController.php b/api/app/Http/Controllers/Forms/Integration/FormIntegrationsEventController.phpindex cc4f0e11e..8657879e7 100644--- a/api/app/Http/Controllers/Forms/Integration/FormIntegrationsEventController.php+++ b/api/app/Http/Controllers/Forms/Integration/FormIntegrationsEventController.php@@ -16,7 +16,7 @@ class FormIntegrationsEventController extends Controllerpublic function index(Form $form, string $integrationid){- $this->authorize('view', $form);+ $this->authorize('update', $form);return FormIntegrationsEventResource::collection(FormIntegrationsEvent::where('integration_id', (int)$integrationid)->orderByDesc('created_at')->get()diff --git a/api/app/Http/Controllers/WorkspaceController.php b/api/app/Http/Controllers/WorkspaceController.phpindex 7cf1a5af1..fca1d36f6 100644--- a/api/app/Http/Controllers/WorkspaceController.php+++ b/api/app/Http/Controllers/WorkspaceController.php@@ -22,15 +22,18 @@ class WorkspaceController extends Controller// Eager load users with pivot roles to prevent N+1 queries in WorkspaceResource// Make this query identical to UserController to avoid duplicate database work- $user = Auth::user()->load([- 'workspaces' => function ($query) {- $query->withPivot('role')->with([- 'users' => function ($subQuery) {- $subQuery->withPivot('role');- }- ]);- }- ]);+ $user = Auth::user();+ if ($user instanceof \App\Models\User) {+ $user->load([+ 'workspaces' => function ($query) {+ $query->withPivot('role')->with([+ 'users' => function ($subQuery) {+ $subQuery->withPivot('role');+ }+ ]);+ }+ ]);+ }$workspaces = $user->workspaces;@@ -39,6 +42,7 @@ class WorkspaceController extends Controllerpublic function saveCustomDomain(CustomDomainRequest $request){+ $this->authorize('adminAction', $request->workspace);if (!$request->workspace->is_pro) {return $this->error(['message' => 'A Pro plan is required to use this feature.',@@ -53,6 +57,7 @@ class WorkspaceController extends Controllerpublic function saveEmailSettings(EmailSettingsRequest $request){+ $this->authorize('adminAction', $request->workspace);if (!$request->workspace->is_pro) {return $this->error(['message' => 'A Pro plan is required to use this feature.',diff --git a/api/app/Http/Resources/FormResource.php b/api/app/Http/Resources/FormResource.phpindex 268de9cde..552c199e7 100644--- a/api/app/Http/Resources/FormResource.php+++ b/api/app/Http/Resources/FormResource.php@@ -23,21 +23,29 @@ class FormResource extends JsonResourcereturn $this->getProtectedForm();}- $ownerData = $this->userIsFormOwner() ? [- 'views_count' => $this->views_count,- 'submissions_count' => $this->submissions_count,- 'redirect_url' => $this->redirect_url,- 'submissions_url' => $this->submissions_url,- 'database_fields_update' => $this->database_fields_update,- 'cleanings' => $this->getCleanigns(),- 'can_be_indexed' => $this->can_be_indexed,- 'password' => $this->password,- 'tags' => $this->tags,- 'visibility' => $this->visibility,- 'removed_properties' => $this->removed_properties,- 'last_edited_human' => $this->updated_at?->diffForHumans(),- 'seo_meta' => $this->seo_meta,- ] : [];+ // Owner/Member view: readonly members can see everything except password+ $ownerData = [];+ if ($this->userIsFormOwner()) {+ $ownerData = [+ 'views_count' => $this->views_count,+ 'submissions_count' => $this->submissions_count,+ 'redirect_url' => $this->redirect_url,+ 'submissions_url' => $this->submissions_url,+ 'database_fields_update' => $this->database_fields_update,+ 'cleanings' => $this->getCleanigns(),+ 'can_be_indexed' => $this->can_be_indexed,+ 'password' => $this->password,+ 'tags' => $this->tags,+ 'visibility' => $this->visibility,+ 'removed_properties' => $this->removed_properties,+ 'last_edited_human' => $this->updated_at?->diffForHumans(),+ 'seo_meta' => $this->seo_meta,+ ];++ if ($this->userIsReadonly()) {+ unset($ownerData['password']);+ }+ }return array_merge(parent::toArray($request), $ownerData, ['is_pro' => $this->workspaceIsPro(),@@ -115,6 +123,31 @@ class FormResource extends JsonResourcereturn $user instanceof UserModel && $user->ownsForm($this->resource);}+ private function userIsReadonly(): bool+ {+ if (!Auth::check()) {+ return false;+ }++ /** @var UserModel|null $user */+ $user = Auth::user();++ // Use preloaded relationships to avoid N+1 when available+ if ($this->relationLoaded('workspace') && $this->workspace->relationLoaded('users')) {+ $pivot = $this->workspace->users->firstWhere('id', $user->id)?->pivot;+ if ($pivot && isset($pivot->role)) {+ return $pivot->role === \App\Models\User::ROLE_READONLY;+ }+ }++ // Minimal query fallback targeting only current user pivot+ return $this->workspace+ ->users()+ ->wherePivot('user_id', $user->id)+ ->wherePivot('role', \App\Models\User::ROLE_READONLY)+ ->exists();+ }+private function getCleanigns(){return $this->cleanings;diff --git a/api/app/Http/Resources/FormSubmissionResource.php b/api/app/Http/Resources/FormSubmissionResource.phpindex 538a87d7b..c3cdb7af6 100644--- a/api/app/Http/Resources/FormSubmissionResource.php+++ b/api/app/Http/Resources/FormSubmissionResource.php@@ -3,8 +3,13 @@namespace App\Http\Resources;use Illuminate\Http\Resources\Json\JsonResource;+use Illuminate\Support\Facades\URL;use Vinkla\Hashids\Facades\Hashids;+use Stevebauman\Purify\Facades\Purify;+/**+ * @property array $data+ */class FormSubmissionResource extends JsonResource{public bool $publiclyAccessed = false;@@ -17,7 +22,8 @@ class FormSubmissionResource extends JsonResource*/public function toArray($request){- $this->generateFileLinks();+ // Single-pass transform: files/signatures → signed URLs, rich_text → purified HTML+ $this->transformDataByFieldTypes();if (!$this->publiclyAccessed) {$this->addExtraData();@@ -50,33 +56,47 @@ class FormSubmissionResource extends JsonResource}/**- * Link to the file (generating signed s3 URL)- *- * @return void+ * Transform data based on field types in a single pass.*/- private function generateFileLinks()+ private function transformDataByFieldTypes(): void{$data = $this->data;$formFields = collect($this->form->properties)->concat(collect($this->form->removed_properties));- $fileFields = $formFields->filter(function ($field) {- return in_array($field['type'], ['files', 'signature']);- });- foreach ($fileFields as $field) {- if (isset($data[$field['id']]) && !empty($data[$field['id']])) {- $data[$field['id']] = collect($data[$field['id']])->filter(function ($file) {- return !is_null($file) && !empty($file);- })->map(function ($file) {- return [- 'file_url' => \URL::signedRoute(- 'open.forms.submissions.file',- [$this->form_id, $file],- now()->addMinutes(10)- ),- 'file_name' => $file,- ];- });++ foreach ($formFields as $field) {+ $fieldId = $field['id'] ?? null;+ $type = $field['type'] ?? null;+ if (!$fieldId || !array_key_exists($fieldId, $data)) {+ continue;+ }++ $value = $data[$fieldId];++ // Files and signatures → signed URLs array+ if (in_array($type, ['files', 'signature'], true) && !empty($value)) {+ $fileItems = is_array($value) ? $value : [$value];+ $mapped = collect($fileItems)+ ->filter(fn ($file) => !is_null($file) && $file !== '')+ ->map(function ($file) {+ return [+ 'file_url' => URL::signedRoute(+ 'open.forms.submissions.file',+ [$this->form_id, $file],+ now()->addMinutes(10)+ ),+ 'file_name' => $file,+ ];+ });+ $data[$fieldId] = $mapped;+ continue;+ }++ // Rich text → purified+ if ($type === 'rich_text' && is_string($value) && $value !== '') {+ $data[$fieldId] = Purify::clean($value);}}+$this->data = $data;}}diff --git a/api/app/Jobs/Form/StoreFormSubmissionJob.php b/api/app/Jobs/Form/StoreFormSubmissionJob.phpindex aef7101cd..228b376e0 100644--- a/api/app/Jobs/Form/StoreFormSubmissionJob.php+++ b/api/app/Jobs/Form/StoreFormSubmissionJob.php@@ -17,6 +17,7 @@ use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;+use Stevebauman\Purify\Facades\Purify;/*** Job to store form submissions@@ -196,6 +197,14 @@ class StoreFormSubmissionJob implements ShouldQueuecontinue;}+ // Sanitize only rich text; plain text fields are stored as-is and rendered safely in UI+ if ($field['type'] === 'rich_text') {+ if (is_string($answerValue)) {+ // Ensure rich text is cleaned with strict allowlist (defense-in-depth)+ $answerValue = Purify::clean($answerValue);+ }+ }+if (($field['type'] == 'url' && isset($field['file_upload']) && $field['file_upload'])|| $field['type'] == 'files'diff --git a/api/app/Models/Workspace.php b/api/app/Models/Workspace.phpindex e82bcdc9f..fb5ada6fa 100644--- a/api/app/Models/Workspace.php+++ b/api/app/Models/Workspace.php@@ -256,7 +256,10 @@ class Workspace extends Model implements CachableAttributes// Use loaded relationship if available to avoid queriesif ($this->relationLoaded('users')) {- return $this->users->where('id', $user->id)->first()?->pivot->role === User::ROLE_ADMIN;+ $pivot = $this->users->where('id', $user->id)->first()?->pivot;+ if ($pivot && isset($pivot->role)) {+ return $pivot->role === User::ROLE_ADMIN;+ }}return $this->users()@@ -273,7 +276,10 @@ class Workspace extends Model implements CachableAttributes// Use loaded relationship if available to avoid queriesif ($this->relationLoaded('users')) {- return $this->users->where('id', $user->id)->first()?->pivot->role === User::ROLE_READONLY;+ $pivot = $this->users->where('id', $user->id)->first()?->pivot;+ if ($pivot && isset($pivot->role)) {+ return $pivot->role === User::ROLE_READONLY;+ }}return $this->users()diff --git a/api/phpunit.xml b/api/phpunit.xmlindex b16ee9a21..3d9dc1d9b 100644--- a/api/phpunit.xml+++ b/api/phpunit.xml@@ -21,6 +21,7 @@<env name="MAIL_FROM_ADDRESS" value="[email protected]"/><env name="MAIL_FROM_NAME" value="NotionForms"/><env name="QUEUE_CONNECTION" value="sync"/>+ <env name="FILESYSTEM_DISK" value="local"/><env name="SESSION_DRIVER" value="array"/><env name="SELF_HOSTED" value="false"/><env name="TEMPLATE_EDITOR_EMAILS" value="[email protected]"/>diff --git a/api/tests/Feature/Forms/FileDownloadSecurityTest.php b/api/tests/Feature/Forms/FileDownloadSecurityTest.phpnew file mode 100644index 000000000..09b29e1a3--- /dev/null+++ b/api/tests/Feature/Forms/FileDownloadSecurityTest.php@@ -0,0 +1,40 @@+<?php++use App\Models\Forms\FormSubmission;+use App\Service\Storage\FileUploadPathService;+use Illuminate\Support\Facades\Storage;+use Illuminate\Support\Facades\URL;++it('forces attachment download with safe headers for submission files', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace);++ // Fake local storage+ Storage::fake();++ $fileName = 'test_file_' . uniqid() . '.svg';+ $path = FileUploadPathService::getFileUploadPath($form->id, $fileName);+ Storage::put($path, '<svg><script>alert(1)</script></svg>');++ /** @var FormSubmission $submission */+ $submission = $form->submissions()->create([+ 'form_id' => $form->id,+ 'data' => [+ 'files_field' => [$fileName],+ ],+ 'status' => FormSubmission::STATUS_COMPLETED,+ ]);++ // Call signed file route (route is protected by 'signed' middleware)+ $signedUrl = URL::signedRoute('open.forms.submissions.file', [$form->id, $fileName]);+ $response = $this->get($signedUrl);++ $response->assertOk();+ expect($response->headers->get('content-disposition'))+ ->toStartWith('attachment;');+ expect(strtolower($response->headers->get('content-type')))+ ->toBe('application/octet-stream');+ expect($response->headers->get('x-content-type-options'))+ ->toBe('nosniff');+});diff --git a/api/tests/Feature/Forms/FormIntegrationTest.php b/api/tests/Feature/Forms/FormIntegrationTest.phpindex 1a307e823..c805414a1 100644--- a/api/tests/Feature/Forms/FormIntegrationTest.php+++ b/api/tests/Feature/Forms/FormIntegrationTest.php@@ -46,6 +46,45 @@ it('can CRUD form integration', function () {]);});+it('forbids non-admin users from viewing integrations and events', function () {+ $owner = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($owner);+ $form = $this->createForm($owner, $workspace);++ // Create one integration as owner+ $this->postJson(route('open.forms.integration.create', $form), [+ 'status' => true,+ 'integration_id' => 'email',+ 'logic' => null,+ 'settings' => [+ 'send_to' => '[email protected]',+ 'sender_name' => 'OpnForm',+ 'subject' => 'Subject',+ 'email_content' => 'Content',+ 'include_submission_data' => false,+ 'include_hidden_fields_submission_data' => false,+ 'reply_to' => null+ ]+ ])->assertSuccessful();++ // Attach viewer and try to read+ $viewer = $this->createUser();+ $viewer->workspaces()->sync([$workspace->id => ['role' => 'readonly']], false);+ $this->actingAs($viewer, 'api');++ $this->getJson(route('open.forms.integrations', $form))+ ->assertStatus(403);++ // Events require an integration id; fetch as owner first+ $this->actingAs($owner, 'api');+ $integrationId = \App\Models\Integration\FormIntegration::where('form_id', $form->id)->value('id');++ // Now as viewer, events should be forbidden as well+ $this->actingAs($viewer, 'api');+ $this->getJson(route('open.forms.integrations.events', [$form, $integrationId]))+ ->assertStatus(403);+});+it('can create form integration with checkbox logic', function () {$user = $this->actingAsProUser();$workspace = $this->createUserWorkspace($user);diff --git a/api/tests/Feature/Forms/FormReadonlyVisibilityTest.php b/api/tests/Feature/Forms/FormReadonlyVisibilityTest.phpnew file mode 100644index 000000000..b582f8b4e--- /dev/null+++ b/api/tests/Feature/Forms/FormReadonlyVisibilityTest.php@@ -0,0 +1,40 @@+<?php++it('hides password for readonly members but shows for admins and users', function () {+ // Owner (admin)+ $owner = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($owner);+ $form = $this->createForm($owner, $workspace);+ $form->update(['password' => 'secret-pass', 'has_password' => true]);++ // Admin/owner can see password+ $this->actingAs($owner, 'api');+ $this->getJson(route('open.forms.show', $form->slug))+ ->assertSuccessful()+ ->assertJsonPath('id', $form->id)+ ->assertJsonPath('password', 'secret-pass')+ ->assertJsonPath('has_password', true);++ // Regular member (user) can see password+ $member = $this->createUser();+ $member->workspaces()->sync([$workspace->id => ['role' => 'user']], false);+ $this->actingAs($member, 'api');+ $this->getJson(route('open.forms.show', $form->slug))+ ->assertSuccessful()+ ->assertJsonPath('id', $form->id)+ ->assertJsonPath('has_password', true)+ ->assertJson(function ($json) {+ // Assert key exists and equals+ return $json->where('password', 'secret-pass')->etc();+ });++ // Readonly member should not receive the password field+ $readonly = $this->createUser();+ $readonly->workspaces()->sync([$workspace->id => ['role' => 'readonly']], false);+ $this->actingAs($readonly, 'api');+ $this->getJson(route('open.forms.show', $form->slug))+ ->assertSuccessful()+ ->assertJsonPath('id', $form->id)+ ->assertJsonPath('has_password', true)+ ->assertJsonMissingPath('password');+});diff --git a/api/tests/Feature/Forms/FormSubmissionResourceTest.php b/api/tests/Feature/Forms/FormSubmissionResourceTest.phpnew file mode 100644index 000000000..1513c99e4--- /dev/null+++ b/api/tests/Feature/Forms/FormSubmissionResourceTest.php@@ -0,0 +1,62 @@+<?php++use App\Models\Forms\FormSubmission;+use Illuminate\Support\Str;++it('sanitizes rich_text and maps files in FormSubmissionResource', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace);++ // Add fields: rich_text, files, and a plain text field+ $richId = 'rt_' . Str::uuid()->toString();+ $filesId = 'fl_' . Str::uuid()->toString();+ $textId = 'tx_' . Str::uuid()->toString();++ $extra = [+ ['id' => $richId, 'name' => 'Rich', 'type' => 'rich_text'],+ ['id' => $filesId, 'name' => 'Files', 'type' => 'files'],+ ['id' => $textId, 'name' => 'Text', 'type' => 'text'],+ ];+ $form->properties = array_merge($form->properties, $extra);+ $form->save();++ $rtPayload = "<p onclick=alert(1)><script>alert(1)</script><a href=javascript:alert(1)>bad</a><strong>ok</strong></p>";+ $files = ['example_1.png', 'doc_2.pdf'];+ $textPayload = "<b>do not execute</b>";++ // Create submission directly+ /** @var FormSubmission $submission */+ $submission = $form->submissions()->create([+ 'form_id' => $form->id,+ 'data' => [+ $richId => $rtPayload,+ $filesId => $files,+ $textId => $textPayload,+ ],+ 'status' => FormSubmission::STATUS_COMPLETED,+ ]);++ // GET submissions (resource collection)+ $response = $this->getJson(route('open.forms.submissions.index', [$form->id]))+ ->assertOk();++ $first = $response->json('data.0');+ expect($first)->not->toBeNull();++ $data = $first['data'];+ // Rich text is cleaned but preserves allowed formatting+ expect($data[$richId])->not->toContain('<script');+ expect($data[$richId])->not->toContain('onclick');+ expect($data[$richId])->not->toContain('javascript:');+ expect($data[$richId])->toContain('<strong>ok</strong>');++ // Files are mapped to signed URLs with file_name+ 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();++ // Plain text remains raw (escaping is at render time)+ expect($data[$textId])->toBe($textPayload);+});diff --git a/api/tests/Feature/Forms/FormSubmissionSanitizationTest.php b/api/tests/Feature/Forms/FormSubmissionSanitizationTest.phpnew file mode 100644index 000000000..f5122383d--- /dev/null+++ b/api/tests/Feature/Forms/FormSubmissionSanitizationTest.php@@ -0,0 +1,57 @@+<?php++use Illuminate\Support\Str;++describe('Form submission sanitization', function () {+ it('preserves plain text-like fields and cleans rich_text', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace);++ // Identify a few default fields by type+ $nameField = collect($form->properties)->firstWhere('name', 'Name'); // text+ $emailField = collect($form->properties)->firstWhere('type', 'email');+ $numberField = collect($form->properties)->firstWhere('type', 'number');++ // Add a rich_text field+ $richTextField = [+ 'id' => 'rt_' . Str::uuid()->toString(),+ 'name' => 'Rich Text',+ 'type' => 'rich_text',+ ];+ $form->properties = array_merge($form->properties, [$richTextField]);+ $form->save();++ $xss = "<img src=x onerror=alert('xss')>Hello";+ $rtXss = "<p onclick=alert(1)><script>alert(1)</script><a href=javascript:alert(1)>bad</a><strong>ok</strong></p>";++ $payload = [+ $nameField['id'] => $xss,+ $emailField['id'] => '[email protected]',+ $numberField['id'] => 42,+ $richTextField['id'] => $rtXss,+ ];++ $this->postJson(route('forms.answer', $form->slug), $payload)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ ]);++ $submission = $form->submissions()->latest()->first();++ // Plain text should preserve raw string (not stripped); UI escapes it+ expect($submission->data[$nameField['id']])->toBe($xss);++ // Email untouched (already validated) and number intact+ expect($submission->data[$emailField['id']])->toBe('[email protected]');+ expect($submission->data[$numberField['id']])->toBe(42);++ // Rich text should be cleaned: no script/onclick/javascript: but keep <strong> and wrapping <p>+ $cleaned = $submission->data[$richTextField['id']];+ expect($cleaned)->not->toContain('<script');+ expect($cleaned)->not->toContain('onclick');+ expect($cleaned)->not->toContain('javascript:');+ expect($cleaned)->toContain('<strong>ok</strong>');+ });+});diff --git a/api/tests/Feature/EnsureUserHasWorkspaceTest.php b/api/tests/Feature/Workspaces/EnsureUserHasWorkspaceTest.phpsimilarity index 100%rename from api/tests/Feature/EnsureUserHasWorkspaceTest.phprename to api/tests/Feature/Workspaces/EnsureUserHasWorkspaceTest.phpdiff --git a/api/tests/Feature/Workspaces/WorkspaceAuthorizationTest.php b/api/tests/Feature/Workspaces/WorkspaceAuthorizationTest.phpnew file mode 100644index 000000000..fd0dbfe35--- /dev/null+++ b/api/tests/Feature/Workspaces/WorkspaceAuthorizationTest.php@@ -0,0 +1,55 @@+<?php+++describe('Workspace admin-only endpoints', function () {+ it('forbids non-admin users from updating custom domains', function () {+ $owner = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($owner);++ // Create a non-admin member+ $viewer = $this->createUser();+ $viewer->workspaces()->sync([$workspace->id => ['role' => 'user']], false);+ $this->actingAs($viewer, 'api');++ $this->putJson(route('open.workspaces.save-custom-domains', $workspace), [+ 'custom_domains' => ['example.com']+ ])->assertStatus(403);+ });++ it('allows admins to update custom domains', function () {+ $owner = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($owner);++ $this->putJson(route('open.workspaces.save-custom-domains', $workspace), [+ 'custom_domains' => ['example.com']+ ])->assertSuccessful();+ });++ it('forbids non-admin users from updating email settings', function () {+ $owner = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($owner);++ $viewer = $this->createUser();+ $viewer->workspaces()->sync([$workspace->id => ['role' => 'user']], false);+ $this->actingAs($viewer, 'api');++ $this->putJson(route('open.workspaces.save-email-settings', $workspace), [+ 'host' => 'smtp.example.com',+ 'port' => '587',+ 'username' => 'user',+ 'password' => 'secret',+ ])->assertStatus(403);+ });++ it('allows admins to update email settings', function () {+ $owner = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($owner);++ $this->putJson(route('open.workspaces.save-email-settings', $workspace), [+ 'host' => 'smtp.example.com',+ 'port' => '587',+ 'username' => 'user',+ 'password' => 'secret',+ ])->assertSuccessful();+ });+});diff --git a/api/tests/Feature/WorkspaceTest.php b/api/tests/Feature/Workspaces/WorkspaceTest.phpsimilarity index 100%rename from api/tests/Feature/WorkspaceTest.phprename to api/tests/Feature/Workspaces/WorkspaceTest.phpdiff --git a/api/tests/Feature/WorkspaceUserTest.php b/api/tests/Feature/Workspaces/WorkspaceUserTest.phpsimilarity index 100%rename from api/tests/Feature/WorkspaceUserTest.phprename to api/tests/Feature/Workspaces/WorkspaceUserTest.phpdiff --git a/client/components/open/tables/OpenTable.vue b/client/components/open/tables/OpenTable.vueindex ee97b626e..44de913ec 100644--- a/client/components/open/tables/OpenTable.vue+++ b/client/components/open/tables/OpenTable.vue@@ -166,6 +166,7 @@ import { useEventListener, refDebounced } from '@vueuse/core'import { useTableState } from '~/composables/components/tables/useTableState'import FormExportModal from '~/components/open/forms/FormExportModal.vue'import OpenText from "./components/OpenText.vue"+import OpenRichText from "./components/OpenRichText.vue"import OpenUrl from "./components/OpenUrl.vue"import OpenSelect from "./components/OpenSelect.vue"import OpenMatrix from "./components/OpenMatrix.vue"@@ -220,7 +221,7 @@ const tableColumns = computed(() => {const fieldComponents = {text: OpenText,- rich_text: OpenText,+ rich_text: OpenRichText,number: OpenText,rating: OpenText,scale: OpenText,diff --git a/client/components/open/tables/components/OpenRichText.vue b/client/components/open/tables/components/OpenRichText.vuenew file mode 100644index 000000000..aafec5d2f--- /dev/null+++ b/client/components/open/tables/components/OpenRichText.vue@@ -0,0 +1,18 @@+<template>+ <div+ class="text-sm text-neutral-900"+ v-html="value"+ />+</template>++<script setup>+defineProps({+ value: {+ type: String,+ required: false,+ default: ''+ },+})+</script>++diff --git a/client/components/open/tables/components/OpenText.vue b/client/components/open/tables/components/OpenText.vueindex c1ec2df03..e9026a100 100644--- a/client/components/open/tables/components/OpenText.vue+++ b/client/components/open/tables/components/OpenText.vue@@ -1,7 +1,8 @@<template><divclass="text-sm text-neutral-900"- v-html="value"+ :title="String(value ?? '')"+ v-text="value"/></template>diff --git a/client/middleware/readonly-block.js b/client/middleware/readonly-block.jsnew file mode 100644index 000000000..d2b2a2174--- /dev/null+++ b/client/middleware/readonly-block.js@@ -0,0 +1,11 @@+export default defineNuxtRouteMiddleware(() => {+ const { isAuthenticated } = useIsAuthenticated()+ if (!isAuthenticated.value) return++ const { current } = useCurrentWorkspace()+ if (current?.value?.is_readonly) {+ throw createError({ statusCode: 403, statusMessage: 'Forbidden' })+ }+})++diff --git a/client/pages/forms/[slug]/edit.vue b/client/pages/forms/[slug]/edit.vueindex 6badf2e52..2c685fd59 100644--- a/client/pages/forms/[slug]/edit.vue+++ b/client/pages/forms/[slug]/edit.vue@@ -129,7 +129,7 @@ useOpnSeoMeta({title: "Edit " + (form.value ? form.value.title : "Your Form"),})definePageMeta({- middleware: "auth",+ middleware: ["auth", "readonly-block"],layout: 'empty'})</script>diff --git a/client/pages/forms/[slug]/show/integrations/index.vue b/client/pages/forms/[slug]/show/integrations/index.vueindex cc60e0f5d..46eb7ecbe 100644--- a/client/pages/forms/[slug]/show/integrations/index.vue+++ b/client/pages/forms/[slug]/show/integrations/index.vue@@ -85,7 +85,7 @@ const props = defineProps({})definePageMeta({- middleware: "auth",+ middleware: ["auth", "readonly-block"],})useOpnSeoMeta({