fix(frontend): #37 punti 1,4,5,6 - 502 backend giù, barcode quotato, apici Alpine, paginazione ricette
1. api_client.py: ConnectionError/Timeout restituisce status_code=502 invece
di 0 (nessuna route confrontava == 0, verificato); i proxy che inoltrano
resp.get("status_code", 500) ereditano il fix senza altre modifiche.
4. measure.py lookup_barcode: code non stringa -> 400 (prima 500 su
code.strip()); urllib.parse.quote(code, safe="") prima di comporre l'URL
verso il backend - un barcode con '/' o '../' non spezza più il path né
raggiunge altri GET con i permessi dell'utente.
5. Ogni "'{{ _(...) }}'" dentro un attributo Alpine (x-text, :title,
:placeholder, @click) sostituito con "{{ _(...)|tojson_attr }}": la
traduzione EN di admin/stations.html:105 ("Clear the station's recipes")
ha un apostrofo che l'IT non ha, e rompeva quel binding e basta - non è
un XSS, ma stessa classe di difetto di #10. File toccati: admin/stations,
admin/users, maker/recipe_list, maker/recipe_editor, maker/task_editor,
maker/task_drawing, components/caliper_status, measure/select_recipe.
Le occorrenze dentro <script>...</script> (non attributi) sono fuori
perimetro per questo punto.
6. statistics.py dashboard(): ciclo sulle pagine (per_page=100, il massimo
del backend) invece di un'unica chiamata che troncava la tendina ricette
alla centesima.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
"""MeasurementTec blueprint - recipe selection and measurement execution."""
|
||||
import urllib.parse
|
||||
|
||||
from flask import (
|
||||
Blueprint, abort, flash, jsonify, redirect, render_template,
|
||||
request, session, url_for,
|
||||
@@ -449,12 +451,21 @@ def task_complete(recipe_id: int):
|
||||
def lookup_barcode():
|
||||
"""Look up a recipe by barcode/code. Returns JSON for AJAX calls."""
|
||||
data = request.get_json(silent=True) or {}
|
||||
code = data.get("code", "").strip()
|
||||
code = data.get("code", "")
|
||||
|
||||
# #37.4: a non-string "code" (e.g. {"code": 5}) crashed .strip() into a
|
||||
# 500. A slash in the code (or "../") used to walk straight into the URL
|
||||
# path unescaped - "AB/123" split into segments the backend never
|
||||
# matched, and "../" could reach another GET endpoint with this user's
|
||||
# permissions.
|
||||
if not isinstance(code, str):
|
||||
return jsonify({"error": True, "detail": _("Codice non valido")}), 400
|
||||
|
||||
code = code.strip()
|
||||
if not code:
|
||||
return jsonify({"error": True, "detail": _("Codice non fornito")}), 400
|
||||
|
||||
resp = api_client.get(f"/api/recipes/code/{code}")
|
||||
resp = api_client.get(f"/api/recipes/code/{urllib.parse.quote(code, safe='')}")
|
||||
if resp.get("error"):
|
||||
return jsonify({
|
||||
"error": True,
|
||||
|
||||
Reference in New Issue
Block a user