Skip to main content

zip_extensions/audit/handlers/
recommendations.rs

1use crate::audit::entry_audit_handler::EntryAuditHandler;
2use crate::audit::entry_view::EntryView;
3use crate::audit::report::{MAX_SUSPICIOUS_RATIO, ZipAuditReport};
4
5/// A `RecommendationsHandler` is used to provide actionable guidance to configure safe extraction.
6/// This is a report finalization handler that generates human-readable recommendations based
7/// on aggregated report fields (e.g., depth, ratios, encryption, and such).
8pub struct RecommendationsHandler;
9
10impl EntryAuditHandler for RecommendationsHandler {
11    fn visit(&mut self, _view: &EntryView, _report: &mut ZipAuditReport) {}
12    fn finish(&mut self, report: &mut ZipAuditReport) {
13        if report.has_absolute_paths {
14            report
15                .recommendations
16                .push("Reject ZIPs containing absolute paths.".to_string());
17        }
18        if report.max_ratio > MAX_SUSPICIOUS_RATIO {
19            report
20                .recommendations
21                .push("Limit max compression ratio (500 recommended).".to_string());
22        }
23        if report.has_encrypted_entries {
24            report
25                .recommendations
26                .push("Refuse encrypted entries to prevent password prompts.".to_string());
27        }
28        if report.max_depth_hint > 25 {
29            report
30                .recommendations
31                .push("Limit directory depth during extraction.".to_string());
32        }
33    }
34}