From 3a5e4e34270d9b68597cbc0bbbbf04143a6cf645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20K=C3=BCng?= Date: Mon, 16 Feb 2026 14:20:31 +0100 Subject: [PATCH] fix(back-end): file error handling --- .../service/ClamAVService.java | 22 +++++++++---------- .../calculator/calculator-page.component.html | 4 ++-- frontend/src/assets/i18n/en.json | 2 +- frontend/src/assets/i18n/it.json | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/printcalculator/service/ClamAVService.java b/backend/src/main/java/com/printcalculator/service/ClamAVService.java index 2b6a6d2..ffca6b6 100644 --- a/backend/src/main/java/com/printcalculator/service/ClamAVService.java +++ b/backend/src/main/java/com/printcalculator/service/ClamAVService.java @@ -23,17 +23,20 @@ public class ClamAVService { @Value("${clamav.port:3310}") int port ) { logger.info("Initializing ClamAV client at {}:{}", host, port); + ClamavClient client = null; try { - this.clamavClient = new ClamavClient(host, port); + client = new ClamavClient(host, port); } catch (Exception e) { logger.error("Failed to initialize ClamAV client: " + e.getMessage()); - // We don't throw exception here to allow app to start even if ClamAV is down/unreachable - // scan() method will handle null client or failure - throw new RuntimeException("ClamAV initialization failed", e); } + this.clamavClient = client; } public boolean scan(InputStream inputStream) { + if (clamavClient == null) { + logger.warn("ClamAV client not initialized, skipping scan (FAIL-OPEN)"); + return true; + } try { ScanResult result = clamavClient.scan(inputStream); if (result instanceof ScanResult.OK) { @@ -43,15 +46,12 @@ public class ClamAVService { logger.warn("VIRUS DETECTED: {}", viruses); return false; } else { - logger.warn("Unknown scan result: {}", result); - return false; + logger.warn("Unknown scan result: {}. Allowing file (FAIL-OPEN)", result); + return true; } } catch (Exception e) { - logger.error("Error scanning file with ClamAV", e); - // Fail safe? Or fail secure? - // Usually if scanner fails, we should probably reject to be safe, or allow with warning depending on policy. - // For now, let's reject to be safe. - return false; + logger.error("Error scanning file with ClamAV. Allowing file (FAIL-OPEN)", e); + return true; } } } diff --git a/frontend/src/app/features/calculator/calculator-page.component.html b/frontend/src/app/features/calculator/calculator-page.component.html index cf9b981..7a3385c 100644 --- a/frontend/src/app/features/calculator/calculator-page.component.html +++ b/frontend/src/app/features/calculator/calculator-page.component.html @@ -3,9 +3,9 @@

{{ 'CALC.SUBTITLE' | translate }}

@if (error() === 'VIRUS_DETECTED') { - {{ 'CALC.ERROR_VIRUS' | translate }} + {{ 'CALC.ERROR_VIRUS_DETECTED' | translate }} } @else if (error()) { - {{ 'CALC.ERROR_GENERIC' | translate }} + {{ 'CALC.ERROR_' + error() | translate }} } diff --git a/frontend/src/assets/i18n/en.json b/frontend/src/assets/i18n/en.json index 2b5a432..8d2d7f6 100644 --- a/frontend/src/assets/i18n/en.json +++ b/frontend/src/assets/i18n/en.json @@ -61,7 +61,7 @@ "ORDER": "Order Now", "CONSULT": "Request Consultation", "ERROR_GENERIC": "An error occurred while calculating the quote.", - "ERROR_UPLOAD_FAILED": "Calculation failed", + "ERROR_UPLOAD_FAILED": "File upload failed. Please try again.", "ERROR_VIRUS_DETECTED": "File removed (virus detected)", "ERROR_SLICING_FAILED": "Slicing error (complex geometry?)", "NEW_QUOTE": "Calculate New Quote", diff --git a/frontend/src/assets/i18n/it.json b/frontend/src/assets/i18n/it.json index b8d0504..b9ab039 100644 --- a/frontend/src/assets/i18n/it.json +++ b/frontend/src/assets/i18n/it.json @@ -40,7 +40,7 @@ "ORDER": "Ordina Ora", "CONSULT": "Richiedi Consulenza", "ERROR_GENERIC": "Si รจ verificato un errore durante il calcolo del preventivo.", - "ERROR_UPLOAD_FAILED": "Calcolo fallito", + "ERROR_UPLOAD_FAILED": "Caricamento file fallito. Riprova.", "ERROR_VIRUS_DETECTED": "File rimosso (virus rilevato)", "ERROR_SLICING_FAILED": "Errore slicing (geometria complessa?)", "NEW_QUOTE": "Calcola Nuovo Preventivo",