Restrict backend selection to admins

An empty `backend` form field now correctly falls back to the default. A
non-empty field submitted by a non-admin user is rejected with a 403
error, preventing potential tampering or issues arising from stale
sessions after role changes.
This commit is contained in:
2026-05-03 18:35:49 +02:00
parent f90f78e78e
commit 366a8381c4
2 changed files with 62 additions and 4 deletions
+9 -1
View File
@@ -57,7 +57,8 @@ impl HasCsrfToken for AnalyzeForm {
/// `analysis_input_v1.json`; otherwise writes `analysis_input_v{N+1}.json`
/// where N is the current latest document version. The worker picks up the
/// new input and produces `document_v{version}.md`. Available to all logged-in
/// users (no admin check). Race protection via `create_new` on the input file.
/// users; the optional `backend` form field is admin-only. Race protection
/// via `create_new` on the input file.
pub async fn handle_analyze_case(
user: AuthenticatedWebUser,
State(config): State<Arc<Config>>,
@@ -72,6 +73,13 @@ pub async fn handle_analyze_case(
));
}
// Backend selection is admin-only. A non-empty field on a non-admin
// session indicates tampering or a stale tab after a role downgrade,
// and is rejected with 403 instead of silently falling back to default.
if !form.backend.is_empty() && !user.is_admin() {
return Err(AppError::Forbidden("Backend-Wahl nur für Admins".into()));
}
// Resolve the requested backend. Empty string falls back to the default
// backend; an unknown id is rejected as a 400 so the user notices the
// misconfiguration instead of silently getting a different model.