fix(admin plans form): sanitize back hidden input

This commit is contained in:
萝卜
2026-03-14 10:27:21 +00:00
parent 8746a50f05
commit ffd125f972

View File

@@ -12,9 +12,18 @@
<form method="post" action="{{ $formAction }}" class="card form-grid"> <form method="post" action="{{ $formAction }}" class="card form-grid">
@csrf @csrf
@php $back = (string) ($back ?? ''); @endphp @php
@if($back !== '') $back = (string) ($back ?? '');
<input type="hidden" name="back" value="{{ $back }}"> // back 作为隐藏字段用于 store 后跳转回来源页:同样需要安全护栏
$safeBack = (str_starts_with($back, '/')
&& !preg_match('/["\'<>]/', $back)
// back 本身不应再包含 back避免无限嵌套导致 URL 膨胀)
&& !preg_match('/(?:^|[?&])back=/', $back))
? $back
: '';
@endphp
@if($safeBack !== '')
<input type="hidden" name="back" value="{{ $safeBack }}">
@endif @endif
<label> <label>