fix(back-end): file error handling
This commit is contained in:
@@ -23,17 +23,20 @@ public class ClamAVService {
|
|||||||
@Value("${clamav.port:3310}") int port
|
@Value("${clamav.port:3310}") int port
|
||||||
) {
|
) {
|
||||||
logger.info("Initializing ClamAV client at {}:{}", host, port);
|
logger.info("Initializing ClamAV client at {}:{}", host, port);
|
||||||
|
ClamavClient client = null;
|
||||||
try {
|
try {
|
||||||
this.clamavClient = new ClamavClient(host, port);
|
client = new ClamavClient(host, port);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to initialize ClamAV client: " + e.getMessage());
|
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) {
|
public boolean scan(InputStream inputStream) {
|
||||||
|
if (clamavClient == null) {
|
||||||
|
logger.warn("ClamAV client not initialized, skipping scan (FAIL-OPEN)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ScanResult result = clamavClient.scan(inputStream);
|
ScanResult result = clamavClient.scan(inputStream);
|
||||||
if (result instanceof ScanResult.OK) {
|
if (result instanceof ScanResult.OK) {
|
||||||
@@ -43,15 +46,12 @@ public class ClamAVService {
|
|||||||
logger.warn("VIRUS DETECTED: {}", viruses);
|
logger.warn("VIRUS DETECTED: {}", viruses);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unknown scan result: {}", result);
|
logger.warn("Unknown scan result: {}. Allowing file (FAIL-OPEN)", result);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error scanning file with ClamAV", e);
|
logger.error("Error scanning file with ClamAV. Allowing file (FAIL-OPEN)", e);
|
||||||
// Fail safe? Or fail secure?
|
return true;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
<p class="subtitle">{{ 'CALC.SUBTITLE' | translate }}</p>
|
<p class="subtitle">{{ 'CALC.SUBTITLE' | translate }}</p>
|
||||||
|
|
||||||
@if (error() === 'VIRUS_DETECTED') {
|
@if (error() === 'VIRUS_DETECTED') {
|
||||||
<app-alert type="error">{{ 'CALC.ERROR_VIRUS' | translate }}</app-alert>
|
<app-alert type="error">{{ 'CALC.ERROR_VIRUS_DETECTED' | translate }}</app-alert>
|
||||||
} @else if (error()) {
|
} @else if (error()) {
|
||||||
<app-alert type="error">{{ 'CALC.ERROR_GENERIC' | translate }}</app-alert>
|
<app-alert type="error">{{ 'CALC.ERROR_' + error() | translate }}</app-alert>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
"ORDER": "Order Now",
|
"ORDER": "Order Now",
|
||||||
"CONSULT": "Request Consultation",
|
"CONSULT": "Request Consultation",
|
||||||
"ERROR_GENERIC": "An error occurred while calculating the quote.",
|
"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_VIRUS_DETECTED": "File removed (virus detected)",
|
||||||
"ERROR_SLICING_FAILED": "Slicing error (complex geometry?)",
|
"ERROR_SLICING_FAILED": "Slicing error (complex geometry?)",
|
||||||
"NEW_QUOTE": "Calculate New Quote",
|
"NEW_QUOTE": "Calculate New Quote",
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
"ORDER": "Ordina Ora",
|
"ORDER": "Ordina Ora",
|
||||||
"CONSULT": "Richiedi Consulenza",
|
"CONSULT": "Richiedi Consulenza",
|
||||||
"ERROR_GENERIC": "Si è verificato un errore durante il calcolo del preventivo.",
|
"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_VIRUS_DETECTED": "File rimosso (virus rilevato)",
|
||||||
"ERROR_SLICING_FAILED": "Errore slicing (geometria complessa?)",
|
"ERROR_SLICING_FAILED": "Errore slicing (geometria complessa?)",
|
||||||
"NEW_QUOTE": "Calcola Nuovo Preventivo",
|
"NEW_QUOTE": "Calcola Nuovo Preventivo",
|
||||||
|
|||||||
Reference in New Issue
Block a user