Skip to main content

verifyos_cli/rules/
privacy_sdk.rs

1use crate::parsers::plist_reader::InfoPlist;
2use crate::rules::core::{
3    AppStoreRule, ArtifactContext, RuleCategory, RuleError, RuleReport, RuleStatus, Severity,
4};
5
6pub struct PrivacyManifestSdkCrossCheckRule;
7
8impl AppStoreRule for PrivacyManifestSdkCrossCheckRule {
9    fn id(&self) -> &'static str {
10        "RULE_PRIVACY_SDK_CROSSCHECK"
11    }
12
13    fn name(&self) -> &'static str {
14        "Privacy Manifest vs SDK Usage"
15    }
16
17    fn category(&self) -> RuleCategory {
18        RuleCategory::Privacy
19    }
20
21    fn severity(&self) -> Severity {
22        Severity::Warning
23    }
24
25    fn recommendation(&self) -> &'static str {
26        "Ensure PrivacyInfo.xcprivacy declares data collection and accessed APIs for included SDKs."
27    }
28
29    fn evaluate(&self, artifact: &ArtifactContext) -> Result<RuleReport, RuleError> {
30        let Some(manifest_path) = artifact.bundle_relative_file("PrivacyInfo.xcprivacy") else {
31            return Ok(RuleReport {
32                status: RuleStatus::Skip,
33                message: Some("PrivacyInfo.xcprivacy not found".to_string()),
34                evidence: None,
35            });
36        };
37
38        let manifest = InfoPlist::from_file(&manifest_path)
39            .map_err(|_| crate::rules::entitlements::EntitlementsError::ParseFailure)?;
40
41        let scan = match artifact.sdk_scan() {
42            Ok(scan) => scan,
43            Err(err) => {
44                return Ok(RuleReport {
45                    status: RuleStatus::Skip,
46                    message: Some(format!("SDK scan skipped: {err}")),
47                    evidence: None,
48                });
49            }
50        };
51
52        if scan.hits.is_empty() {
53            return Ok(RuleReport {
54                status: RuleStatus::Pass,
55                message: Some("No SDK signatures detected".to_string()),
56                evidence: None,
57            });
58        }
59
60        let has_data_types = manifest
61            .get_value("NSPrivacyCollectedDataTypes")
62            .and_then(|v| v.as_array())
63            .map(|arr| !arr.is_empty())
64            .unwrap_or(false);
65        let has_accessed_api_types = manifest
66            .get_value("NSPrivacyAccessedAPITypes")
67            .and_then(|v| v.as_array())
68            .map(|arr| !arr.is_empty())
69            .unwrap_or(false);
70
71        if has_data_types || has_accessed_api_types {
72            return Ok(RuleReport {
73                status: RuleStatus::Pass,
74                message: Some("Privacy manifest includes SDK data declarations".to_string()),
75                evidence: None,
76            });
77        }
78
79        Ok(RuleReport {
80            status: RuleStatus::Fail,
81            message: Some("SDKs detected but privacy manifest lacks declarations".to_string()),
82            evidence: Some(format!("SDK signatures: {}", scan.hits.join(", "))),
83        })
84    }
85}