Skip to content

Commit 875ebb9

Browse files
authored
fix: secure link password deletion (#1126)
1 parent aae3521 commit 875ebb9

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

resources/views/backend/edit.blade.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ class="col-span-6"
140140
@svg('icon-key', 'mr-1') Edit Password
141141
</button>
142142

143-
<a href="{{ route('link.password.delete', $url) }}" onclick="return confirm('Are you sure you want to remove the password?')" class="btn btn-delete-danger btn-sm dark:text-red-700! dark:hover:text-red-400! dark:border-red-900!">
143+
<button type="button" x-on:click="$dispatch('open-modal', 'remove-password-modal')"
144+
class="btn btn-delete-danger btn-sm dark:text-red-700! dark:hover:text-red-400! dark:border-red-900!"
145+
>
144146
Remove Password
145-
</a>
147+
</button>
146148
@else
147149
<button type="button" title="Add Password" x-on:click="$dispatch('open-modal', 'add-password-modal')" class="btn btn-sm">
148150
@svg('icon-key', 'mr-1') Add Password
@@ -213,6 +215,26 @@ class="flatpickr-input form-input"
213215
@include('backend.linkpassword.create')
214216
@else
215217
@include('backend.linkpassword.edit')
218+
219+
<x-modal name="remove-password-modal" maxWidth="md">
220+
<x-slot:title>Remove Password for <span class="font-semibold">{{ $url->keyword }}</span></x-slot:title>
221+
<form method="post" action="{{ route('link.password.delete', $url) }}" class="space-y-6">
222+
@csrf @method('DELETE')
223+
<p class="font-light text-sm dark:text-dark-400 mt-2 mb-2">
224+
Are you sure you want to remove the password for this link? This action cannot be undone.
225+
</p>
226+
227+
<div class="flex justify-end items-center">
228+
<button type="button"
229+
x-on:click="$dispatch('close-modal', 'remove-password-modal')"
230+
class="btn btn-secondary mr-2"
231+
>
232+
Cancel
233+
</button>
234+
<button type="submit" class="btn btn-delete-danger">Remove Password</button>
235+
</div>
236+
</form>
237+
</x-modal>
216238
@endif
217239
</div>
218240
@endsection

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
Route::delete('/delete/{url:keyword}', [LinkController::class, 'delete'])->name('link.delete');
2828
Route::post('/password/store/{url:keyword}', [LinkPasswordController::class, 'store'])->name('link.password.store');
2929
Route::post('/password/update/{url:keyword}', [LinkPasswordController::class, 'update'])->name('link.password.update');
30-
Route::get('/password/delete/{url:keyword}', [LinkPasswordController::class, 'delete'])->name('link.password.delete');
30+
Route::delete('/password/delete/{url:keyword}', [LinkPasswordController::class, 'delete'])->name('link.password.delete');
3131
Route::get('/tag/restricted', [DashboardController::class, 'restrictedLinkView'])->name('dboard.links.restricted');
3232
Route::get('/tag/restricted/{user:name}', [DashboardController::class, 'userRestrictedLinkView'])
3333
->name('dboard.links.user.restricted');

tests/Feature/AuthPage/LinkAuthorizationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function password_delete_adminCanAccessAll()
196196
{
197197
$url = Url::factory()->create(['password' => 'password']);
198198
$this->actingAs($this->adminUser())
199-
->get(route('link.password.delete', $url));
199+
->delete(route('link.password.delete', $url));
200200

201201
$this->assertNull($url->fresh()->password);
202202
}

tests/Feature/AuthPage/LinkTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function testRemovePasswordFromLink()
247247
$url = Url::factory()->create(['password' => 'password']);
248248
$response = $this->actingAs($url->author)
249249
->from(route('link.edit', $url))
250-
->get(route('link.password.delete', $url));
250+
->delete(route('link.password.delete', $url));
251251

252252
$response
253253
->assertRedirectToRoute('link.edit', $url)

0 commit comments

Comments
 (0)