feat(unity): mobile build targets from Player Settings; generated app projects recorded (#480)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Docs (push) Successful in 1m11s
CI / Deploy Dashboard (push) Successful in 4m54s
CI / Deploy MCP (push) Successful in 3m51s
CI / Deploy Agent (push) Successful in 6m2s

This commit was merged in pull request #480.
This commit is contained in:
sharang committed 2026-10-05 23:56:34 +00:00
1 parent 918c871a25
commit 25072056dc
23 files changed
+709 -98

No files matched your search

+81 -22
View File
@@ -135,8 +135,13 @@ struct MobileShape {
flutter: bool,
/// A Unity project (`ProjectSettings/ProjectVersion.txt`).
unity: bool,
/// A Unity project with Android plugins (`Assets/Plugins/Android`).
/// A Unity project building for Android: Android plug-ins or a chosen
/// Android bundle identifier (see [`crate::pipeline::unity_settings`]).
unity_android: bool,
/// A Unity project building for iOS, likewise.
unity_ios: bool,
/// The bundle identifiers chosen for those platforms (`ios:com.x.y`).
unity_bundle_ids: Vec<String>,
}
/// How many .NET projects of each kind a tree holds.
@@ -244,9 +249,21 @@ fn mobile_shape(root: &Path, m: &Markers) -> MobileShape {
.map(|settings| settings.rsplit_once('/').map_or("", |(dir, _)| dir))
.collect();
shape.unity = !unity_roots.is_empty();
shape.unity_android = unity_roots
.iter()
.any(|unity| root.join(unity).join("Assets/Plugins/Android").is_dir());
for unity in unity_roots {
let platforms = crate::pipeline::unity_settings::unity_platforms(&root.join(unity));
for (name, platform, targeted) in [
("ios", platforms.ios, &mut shape.unity_ios),
("android", platforms.android, &mut shape.unity_android),
] {
let Some(platform) = platform else {
continue;
};
*targeted = true;
if let Some(id) = platform.bundle_id {
shape.unity_bundle_ids.push(format!("{name}:{id}"));
}
}
}
shape
}
@@ -357,24 +374,37 @@ impl HeuristicClassifier {
if shape.unity {
let mut facts = facts_lang("csharp");
facts.push(DetectedFact::new("framework", "unity", "heuristic"));
// Unity keeps the build target out of the repository; Android
// plugins in its Assets, or Android app modules beside it, are
// the sign it ships to Android.
let (target_type, confidence, why) =
if shape.unity_android || !shape.android_modules.is_empty() {
(
TargetType::AndroidApp,
0.8,
"Unity project with Android plugins",
)
} else {
(
TargetType::DesktopApp,
0.6,
"Unity project (build target unknown)",
)
};
out.push(verdict(target_type, confidence, why, facts));
for id in &shape.unity_bundle_ids {
facts.push(DetectedFact::new("bundle_id", id.clone(), "heuristic"));
}
// Unity keeps the build target out of the repository; a chosen
// bundle identifier or native plug-ins for a platform, or
// Android app modules beside it, are the sign it ships there.
let android = shape.unity_android || !shape.android_modules.is_empty();
if android {
out.push(verdict(
TargetType::AndroidApp,
0.8,
"Unity project building for Android",
facts.clone(),
));
}
if shape.unity_ios {
out.push(verdict(
TargetType::IosApp,
0.8,
"Unity project building for iOS",
facts.clone(),
));
}
if !android && !shape.unity_ios {
out.push(verdict(
TargetType::DesktopApp,
0.6,
"Unity project (build target unknown)",
facts,
));
}
}
if m.any_dir_ends_with(".xcodeproj")
|| m.any_dir_ends_with(".xcworkspace")
@@ -728,6 +758,35 @@ mod tests {
.any(|f| f.key == "framework" && f.value == "unity")));
}
#[tokio::test]
async fn a_unity_project_for_ios_and_android_offers_both_with_its_bundle_ids() {
let settings = "%YAML 1.1\nPlayerSettings:\n applicationIdentifier:\n \
Android: com.DefaultCompany.Pump\n iPhone: com.example.pump\n \
iOSTargetOSVersionString: 12.0\n";
let v = classify_tree(|root| {
write_all(
root,
&[
(
"game/ProjectSettings/ProjectVersion.txt",
"m_EditorVersion: 2022.3.1f1",
),
("game/ProjectSettings/ProjectSettings.asset", settings),
("game/Assets/Plugins/Android/libpump.aar", ""),
],
);
})
.await;
let types: Vec<TargetType> = v.iter().map(|x| x.target_type).collect();
assert!(types.contains(&TargetType::IosApp), "{types:?}");
assert!(types.contains(&TargetType::AndroidApp), "{types:?}");
assert!(!types.contains(&TargetType::DesktopApp), "{types:?}");
assert!(v.iter().any(|x| x
.facts
.iter()
.any(|f| f.key == "bundle_id" && f.value == "ios:com.example.pump")));
}
#[tokio::test]
async fn a_react_native_app_is_mobile_not_a_web_app() {
let v = classify_tree(|root| {
+130 -24
View File
@@ -244,30 +244,15 @@ fn check_xcode_project(root: &Path, file: &Path) -> Vec<Hit> {
.map_or_else(String::new, |p| relative(root, p));
let path = relative(root, file);
let mut hits = Vec::new();
if let Some(((major, minor), line)) = lowest_setting(&text, "IPHONEOS_DEPLOYMENT_TARGET") {
if (major, minor) < OLDEST_PATCHED_IOS {
let (oldest, _) = OLDEST_PATCHED_IOS;
hits.push(Hit {
scanner: SCANNER,
scan_type: ScanType::Sbom,
rule_id: "ios-deployment-target-end-of-support",
title: format!(
"The app installs on iOS {major}.{minor}, which receives no security updates"
),
description: format!(
"{project} sets its iOS deployment target to {major}.{minor}: the app \
installs and runs on devices still on that release. iOS releases below \
{oldest} receive no security updates, so those devices stay vulnerable \
whatever the app does. The app also runs on current iOS releases."
),
remediation: "Raise IPHONEOS_DEPLOYMENT_TARGET of every target and build \
configuration to a supported iOS release, and test on it.",
severity: Severity::Low,
cwe: "CWE-1104",
path: path.clone(),
line: Some(line),
});
}
if let Some((version, line)) = lowest_setting(&text, "IPHONEOS_DEPLOYMENT_TARGET") {
hits.extend(ios_deployment_target(
&project,
version,
"Raise IPHONEOS_DEPLOYMENT_TARGET of every target and build configuration to a \
supported iOS release, and test on it.",
path.clone(),
line,
));
}
if let Some(((major, minor), line)) = lowest_setting(&text, "SWIFT_VERSION") {
if (major, minor) < OLDEST_BUILDABLE_SWIFT {
@@ -295,6 +280,91 @@ fn check_xcode_project(root: &Path, file: &Path) -> Vec<Hit> {
hits
}
/// The finding for an iOS deployment target below [`OLDEST_PATCHED_IOS`], if it
/// is: `project` sets `version` at `path:line`.
fn ios_deployment_target(
project: &str,
(major, minor): (u32, u32),
remediation: &'static str,
path: String,
line: u32,
) -> Option<Hit> {
let (oldest, _) = OLDEST_PATCHED_IOS;
((major, minor) < OLDEST_PATCHED_IOS).then(|| Hit {
scanner: SCANNER,
scan_type: ScanType::Sbom,
rule_id: "ios-deployment-target-end-of-support",
title: format!(
"The app installs on iOS {major}.{minor}, which receives no security updates"
),
description: format!(
"{project} sets its iOS deployment target to {major}.{minor}: the app installs and \
runs on devices still on that release. iOS releases below {oldest} receive no \
security updates, so those devices stay vulnerable whatever the app does. The app \
also runs on current iOS releases."
),
remediation,
severity: Severity::Low,
cwe: "CWE-1104",
path,
line: Some(line),
})
}
/// The lifecycle findings of the mobile platforms a Unity project builds for
/// (see [`crate::pipeline::unity_settings`]): the minimum iOS release and
/// Android API level it installs on.
fn unity_platform_hits(root: &Path, project: &Path) -> Vec<Hit> {
let platforms = crate::pipeline::unity_settings::unity_platforms(project);
let label = relative(root, project);
let path = relative(
root,
&crate::pipeline::unity_settings::player_settings_path(project),
);
let mut hits = Vec::new();
let ios_min = platforms.ios.and_then(|p| p.min_os);
if let Some(setting) = ios_min {
if let Some(version) = version_pair(&setting.value) {
hits.extend(ios_deployment_target(
&label,
version,
"Raise the Target minimum iOS Version in the Player Settings (iOS) to a \
supported iOS release, and test on it.",
path.clone(),
setting.line,
));
}
}
let android_min = platforms.android.and_then(|p| p.min_os);
if let Some(setting) = android_min {
let api = setting.value.parse::<u32>().ok();
if let Some(api) = api.filter(|api| *api < OLDEST_PATCHED_ANDROID_API) {
hits.push(Hit {
scanner: SCANNER,
scan_type: ScanType::Sbom,
rule_id: "android-min-sdk-end-of-support",
title: format!(
"The app installs on Android API {api}, which receives no security updates"
),
description: format!(
"{label} sets its minimum Android API level to {api}: the app installs and \
runs on devices still on that release. Android releases below API \
{OLDEST_PATCHED_ANDROID_API} (Android 10) receive no security updates, so \
those devices stay vulnerable whatever the app does. The app also runs on \
current Android releases."
),
remediation: "Raise the Minimum API Level in the Player Settings (Android) to a \
supported Android release, and test on it.",
severity: Severity::Low,
cwe: "CWE-1104",
path,
line: Some(setting.line),
});
}
}
hits
}
/// A Unity project at `project`: without `Packages/manifest.json` its packages
/// are not declared; an editor version out of support is a finding of its own.
fn check_unity_project(root: &Path, project: &Path) -> Vec<Hit> {
@@ -331,6 +401,7 @@ fn check_unity_project(root: &Path, project: &Path) -> Vec<Hit> {
line: Some(1),
});
}
hits.extend(unity_platform_hits(root, project));
if unity_out_of_support(&version) {
hits.push(Hit {
scanner: SCANNER,
@@ -486,6 +557,41 @@ mod tests {
);
}
#[test]
fn a_unity_project_is_judged_only_for_the_platforms_it_builds_for() {
let settings = |ios_id: &str| {
format!(
"%YAML 1.1\nPlayerSettings:\n applicationIdentifier:\n \
Android: com.DefaultCompany.Pump\n iPhone: {ios_id}\n \
AndroidMinSdkVersion: 19\n iOSTargetOSVersionString: 11.0\n"
)
};
let mobile = settings("com.example.pump");
let desktop = settings("com.DefaultCompany.Pump");
let t = tree(&[
(
"game/ProjectSettings/ProjectVersion.txt",
"m_EditorVersion: 2022.3.50f1\n",
),
("game/ProjectSettings/ProjectSettings.asset", &mobile),
("game/Packages/manifest.json", "{\"dependencies\":{}}"),
("game/Assets/Plugins/Android/libpump.aar", ""),
(
"tool/ProjectSettings/ProjectVersion.txt",
"m_EditorVersion: 2022.3.50f1\n",
),
("tool/ProjectSettings/ProjectSettings.asset", &desktop),
("tool/Packages/manifest.json", "{\"dependencies\":{}}"),
]);
assert_eq!(
hits(&t),
[
"ios-deployment-target-end-of-support game/ProjectSettings/ProjectSettings.asset:7",
"android-min-sdk-end-of-support game/ProjectSettings/ProjectSettings.asset:6",
]
);
}
#[test]
fn current_xcode_settings_give_nothing() {
let t = tree(&[(
+1
View File
@@ -32,4 +32,5 @@ pub mod semgrep;
pub mod source_text;
pub mod tool_cmd;
mod tracker_dispatch;
pub(crate) mod unity_settings;
pub mod vendor;
@@ -339,6 +339,25 @@ impl PipelineOrchestrator {
)
.await;
}
// A Unity app's Xcode or Gradle project is generated at build time:
// what only it holds is not here to check.
for subject in crate::pipeline::unity_settings::generated_platform_projects(&repo_path) {
self.skip_stage(
scan_run_id,
SkippedStage::new(
"platform_project",
SkipCode::PlatformProjectGenerated,
format!(
"for {subject}, Unity generates the app project at build time; it is not \
in the repository, so its Info.plist or manifest, permissions and native \
code are not checked; export it and upload it as an archive to check \
them"
),
)
.about(subject),
)
.await;
}
// Libraries copied into a firmware tree (an RTOS, a TCP/IP stack, a TLS
// library) have no manifest; their headers say which version they are.
@@ -384,6 +403,27 @@ impl PipelineOrchestrator {
)
.await;
}
// Prebuilt Carthage frameworks have no purl: no advisory database
// covers them.
let binary_frameworks: Vec<String> = sbom_entries
.iter()
.filter(|e| {
e.purl.is_none()
&& e.package_manager == crate::pipeline::sbom::carthage::CARTHAGE_MANAGER
})
.map(|e| format!("{} {}", e.name, e.version))
.collect();
if !binary_frameworks.is_empty() {
cve_complete = false;
self.record_cve_gap(
scan_run_id,
&format!("Carthage: {}", component_list(&binary_frameworks)),
"these prebuilt binary frameworks are pinned in Cartfile.resolved, and no \
advisory database covers them, so they were not matched; check them \
against their vendors' security advisories",
)
.await;
}
let mut cve_alerts = match tokio::time::timeout(
std::time::Duration::from_secs(600),
async {
@@ -10,8 +10,7 @@
//! given the purl OSV keys Swift advisories by,
//! `pkg:swift/github.com/Alamofire/Alamofire@5.4.0`, and is matched like one.
//! A `binary` pin is a prebuilt vendor framework: it is listed without a purl,
//! as no advisory database covers it (see
//! [`super::mobile::unlocked_mobile_ecosystems`], which says so).
//! as no advisory database covers it, and the scan records it as not matched.
use std::path::Path;
@@ -23,11 +22,11 @@ use super::mobile::{MAX_DEPTH, SKIPPED_DIRS};
pub(crate) const CARTHAGE_MANAGER: &str = "carthage";
/// The file that pins Carthage dependencies.
pub(crate) const RESOLVED_FILE: &str = "Cartfile.resolved";
pub(super) const RESOLVED_FILE: &str = "Cartfile.resolved";
/// One line of `Cartfile.resolved`.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Pin {
struct Pin {
/// The repository (`Alamofire/Alamofire`, `https://host/x/y.git`) or the
/// binary spec URL.
pub source: String,
@@ -39,7 +38,7 @@ pub(crate) struct Pin {
/// The pins of one `Cartfile.resolved`; lines that are not pins (comments,
/// blank lines, unknown kinds) are skipped.
pub(crate) fn parse_resolved(text: &str) -> Vec<Pin> {
fn parse_resolved(text: &str) -> Vec<Pin> {
text.lines()
.filter_map(|line| {
let (kind, rest) = line.trim().split_once(char::is_whitespace)?;
@@ -117,7 +116,7 @@ fn entry(repo_id: &str, pin: &Pin) -> SbomEntry {
/// The `Cartfile.resolved` files under `root`, outside installed dependencies
/// and build output.
pub(crate) fn resolved_files(root: &Path) -> impl Iterator<Item = walkdir::DirEntry> {
fn resolved_files(root: &Path) -> impl Iterator<Item = walkdir::DirEntry> {
walkdir::WalkDir::new(root)
.min_depth(1)
.max_depth(MAX_DEPTH)
+3 -35
View File
@@ -137,7 +137,7 @@ impl Seen {
/// by a lockfile the SBOM reads.
pub(crate) fn unlocked_mobile_ecosystems(root: &Path) -> Vec<UnlockedEcosystem> {
let seen = walk(root);
let mut out: Vec<UnlockedEcosystem> = ECOSYSTEMS
ECOSYSTEMS
.iter()
.zip(seen.manifest)
.zip(seen.locked)
@@ -149,31 +149,7 @@ pub(crate) fn unlocked_mobile_ecosystems(root: &Path) -> Vec<UnlockedEcosystem>
remedy: eco.remedy,
})
})
.collect();
// Prebuilt Carthage frameworks are listed with their versions, but no
// advisory database covers them.
let binary = super::carthage::resolved_files(root).find(|file| {
std::fs::read_to_string(file.path()).is_ok_and(|text| {
super::carthage::parse_resolved(&text)
.iter()
.any(|pin| pin.binary)
})
});
if let Some(file) = binary {
out.push(UnlockedEcosystem {
manifest: file
.path()
.strip_prefix(root)
.unwrap_or(file.path())
.to_string_lossy()
.replace('\\', "/"),
problem: "pins prebuilt binary frameworks, which are listed but which no \
advisory database covers",
remedy: "check these vendor frameworks against their vendors' security \
advisories, or depend on their source through Swift Package Manager",
});
}
out
.collect()
}
/// Walk `root` once, recording manifests and lockfiles of every ecosystem.
@@ -328,7 +304,7 @@ mod tests {
}
#[test]
fn carthage_is_reported_without_its_resolved_file_or_with_binaries() {
fn carthage_is_reported_without_its_resolved_file() {
let unlocked = tree(&[("Cartfile", "")]);
assert_eq!(manifests(unlocked.path()), vec!["Cartfile"]);
let pinned = tree(&[
@@ -339,14 +315,6 @@ mod tests {
),
]);
assert!(manifests(pinned.path()).is_empty());
let binary = tree(&[
("ios/Cartfile", ""),
(
"ios/Cartfile.resolved",
"binary \"https://vendor.example.com/Sdk.json\" \"3.1.0\"\n",
),
]);
assert_eq!(manifests(binary.path()), vec!["ios/Cartfile.resolved"]);
}
#[test]
+1 -1
View File
@@ -1,5 +1,5 @@
mod cargo_audit;
mod carthage;
pub(crate) mod carthage;
mod gradle;
mod mobile;
mod nuget;
+1 -1
View File
@@ -25,7 +25,7 @@ const EDITOR_COMPONENT: &str = "Unity Editor";
/// The Unity projects under `root`: the directories holding
/// `ProjectSettings/ProjectVersion.txt`.
fn unity_projects(root: &Path) -> Vec<PathBuf> {
pub(crate) fn unity_projects(root: &Path) -> Vec<PathBuf> {
walkdir::WalkDir::new(root)
.min_depth(1)
.max_depth(MAX_DEPTH)
@@ -0,0 +1,290 @@
//! The mobile platforms a Unity project builds for, read from its Player
//! Settings (`ProjectSettings/ProjectSettings.asset`).
//!
//! The active build target is kept in `Library/`, which is never committed, and
//! `EditorBuildSettings.asset` lists only scenes. Player Settings hold every
//! platform's settings whether the project ships to it or not: Unity writes a
//! `com.DefaultCompany.<Product>` bundle identifier and a default minimum OS for
//! each one. A platform therefore counts as targeted when its bundle identifier
//! was set by someone (not a Unity default) or the project carries native
//! plug-ins for it (`Assets/Plugins/iOS`, `Assets/Plugins/Android`).
//!
//! For a targeted platform, the Xcode or Gradle project Unity generates at build
//! time is not in the repository: its Info.plist or manifest, entitlements and
//! native code go unchecked, which the scan records.
use std::path::{Path, PathBuf};
/// Where Player Settings live in a Unity project.
const PLAYER_SETTINGS: &str = "ProjectSettings/ProjectSettings.asset";
/// Bundle identifiers Unity writes by itself.
const DEFAULT_IDENTIFIER_PREFIXES: &[&str] = &["com.DefaultCompany.", "com.Company.ProductName"];
/// A setting's value and its 1-based line in `ProjectSettings.asset`.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Setting {
pub value: String,
pub line: u32,
}
/// One mobile platform a Unity project builds for.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Platform {
/// The bundle identifier, unless it is a Unity default.
pub bundle_id: Option<String>,
/// The minimum OS the app installs on: `iOSTargetOSVersionString`
/// (`12.0`) or `AndroidMinSdkVersion` (`21`).
pub min_os: Option<Setting>,
}
/// The mobile platforms of one Unity project.
#[derive(Debug, Default, Clone, PartialEq)]
pub(crate) struct UnityPlatforms {
pub ios: Option<Platform>,
pub android: Option<Platform>,
}
/// The Player Settings keys read, one level below `PlayerSettings:`.
#[derive(Debug, Default)]
struct PlayerSettings {
/// `applicationIdentifier:` entries, by platform (`iPhone`, `Android`).
identifiers: Vec<(String, String)>,
ios_min: Option<Setting>,
android_min: Option<Setting>,
}
/// Read the keys of a text-serialised `ProjectSettings.asset`. `None` for a
/// binary-serialised one (Asset Serialization Mode "Force Binary").
fn read_player_settings(text: &str) -> Option<PlayerSettings> {
if !text.starts_with("%YAML") {
return None;
}
let mut settings = PlayerSettings::default();
let mut in_identifiers = false;
for (i, line) in text.lines().enumerate() {
let line_number = u32::try_from(i + 1).unwrap_or(u32::MAX);
// `applicationIdentifier:` is a map, its entries indented by four.
if in_identifiers {
if let Some(entry) = line.strip_prefix(" ") {
if let Some((platform, id)) = entry.split_once(':') {
settings
.identifiers
.push((platform.trim().to_string(), id.trim().to_string()));
}
continue;
}
in_identifiers = false;
}
let Some(key_value) = line.strip_prefix(" ") else {
continue;
};
let Some((key, value)) = key_value.split_once(':') else {
continue;
};
let setting = || Setting {
value: value.trim().to_string(),
line: line_number,
};
match key {
"applicationIdentifier" => in_identifiers = true,
"iOSTargetOSVersionString" => settings.ios_min = Some(setting()),
"AndroidMinSdkVersion" => settings.android_min = Some(setting()),
_ => {}
}
}
Some(settings)
}
/// The bundle identifier set for `platform`, unless Unity wrote it.
fn chosen_identifier(settings: &PlayerSettings, platform: &str) -> Option<String> {
settings
.identifiers
.iter()
.find(|(p, _)| p == platform)
.map(|(_, id)| id.clone())
.filter(|id| {
!id.is_empty()
&& !DEFAULT_IDENTIFIER_PREFIXES
.iter()
.any(|prefix| id.starts_with(prefix))
})
}
/// The mobile platforms the Unity project at `project` builds for.
///
/// # Arguments
///
/// * `project` - the project's root, the directory holding `ProjectSettings/`
pub(crate) fn unity_platforms(project: &Path) -> UnityPlatforms {
let settings = std::fs::read_to_string(project.join(PLAYER_SETTINGS))
.ok()
.and_then(|text| read_player_settings(&text))
.unwrap_or_default();
let platform = |identifier_key: &str, plugins: &str, min_os: &Option<Setting>| {
let bundle_id = chosen_identifier(&settings, identifier_key);
let has_plugins = project.join("Assets/Plugins").join(plugins).is_dir();
(bundle_id.is_some() || has_plugins).then(|| Platform {
bundle_id,
min_os: min_os.clone(),
})
};
UnityPlatforms {
ios: platform("iPhone", "iOS", &settings.ios_min),
android: platform("Android", "Android", &settings.android_min),
}
}
/// The native projects Unity generates for the platforms the Unity projects
/// under `root` build for, unless an exported one is in the tree: an Xcode
/// project for iOS, a Gradle build for Android. Each as
/// `<project> – iOS (Xcode)`.
pub(crate) fn generated_platform_projects(root: &Path) -> Vec<String> {
let projects = crate::pipeline::sbom::unity::unity_projects(root);
if projects.is_empty() {
return Vec::new();
}
let (mut xcode, mut gradle) = (false, false);
for entry in walkdir::WalkDir::new(root)
.max_depth(10)
.into_iter()
.filter_entry(|e| {
!(e.file_type().is_dir()
&& ["Library", "Temp", "Pods", ".git", "node_modules"]
.contains(&e.file_name().to_string_lossy().as_ref()))
})
.filter_map(Result::ok)
{
let name = entry.file_name().to_string_lossy();
xcode |= entry.file_type().is_dir() && name.ends_with(".xcodeproj");
gradle |= name == "build.gradle" || name == "build.gradle.kts";
}
let mut out = Vec::new();
for project in projects {
let label = project
.strip_prefix(root)
.ok()
.map(|p| p.to_string_lossy().replace('\\', "/"))
.filter(|p| !p.is_empty())
.unwrap_or_else(|| "Unity".to_string());
let platforms = unity_platforms(&project);
if platforms.ios.is_some() && !xcode {
out.push(format!("{label} – iOS (Xcode)"));
}
if platforms.android.is_some() && !gradle {
out.push(format!("{label} – Android (Gradle)"));
}
}
out
}
/// `ProjectSettings.asset` of `project`, relative to it.
pub(crate) fn player_settings_path(project: &Path) -> PathBuf {
project.join(PLAYER_SETTINGS)
}
#[cfg(test)]
#[allow(clippy::expect_used)]
mod tests {
use super::*;
/// The shape of a real `ProjectSettings.asset` (Unity 2019 to 6).
const SETTINGS: &str = "%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
companyName: Example
productName: Pump Game
applicationIdentifier:
Android: com.example.pumpgame
Standalone: com.DefaultCompany.PumpGame
iPhone: com.DefaultCompany.PumpGame
buildNumber:
Standalone: 0
AndroidMinSdkVersion: 22
AndroidTargetSdkVersion: 0
iOSTargetOSVersionString: 12.0
";
/// A scratch Unity project with `settings` and the given plug-in folders.
fn project(settings: &str, plugins: &[&str]) -> PathBuf {
let dir = std::env::temp_dir().join(format!("cs-unityset-{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(dir.join("ProjectSettings")).expect("mkdir");
std::fs::write(dir.join(PLAYER_SETTINGS), settings).expect("write");
for plugin in plugins {
std::fs::create_dir_all(dir.join("Assets/Plugins").join(plugin)).expect("mkdir");
}
dir
}
#[test]
fn a_chosen_bundle_identifier_marks_the_platform_and_a_default_does_not() {
let dir = project(SETTINGS, &[]);
let platforms = unity_platforms(&dir);
let _ = std::fs::remove_dir_all(&dir);
assert_eq!(platforms.ios, None);
assert_eq!(
platforms.android,
Some(Platform {
bundle_id: Some("com.example.pumpgame".into()),
min_os: Some(Setting {
value: "22".into(),
line: 14
}),
})
);
}
#[test]
fn native_plugins_mark_the_platform_without_an_identifier() {
let dir = project(SETTINGS, &["iOS"]);
let platforms = unity_platforms(&dir);
let _ = std::fs::remove_dir_all(&dir);
let ios = platforms.ios.expect("iOS is targeted");
assert_eq!(ios.bundle_id, None);
assert_eq!(
ios.min_os,
Some(Setting {
value: "12.0".into(),
line: 16
})
);
}
#[test]
fn a_generated_project_is_named_unless_an_export_is_in_the_tree() {
let root = std::env::temp_dir().join(format!("cs-unitygen-{}", uuid::Uuid::new_v4()));
let game = root.join("Pump Game");
std::fs::create_dir_all(game.join("ProjectSettings")).expect("mkdir");
std::fs::write(
game.join("ProjectSettings/ProjectVersion.txt"),
"m_EditorVersion: 6000.0.1f1",
)
.expect("write");
std::fs::write(
game.join(PLAYER_SETTINGS),
SETTINGS.replace(
"iPhone: com.DefaultCompany.PumpGame",
"iPhone: com.example.pump",
),
)
.expect("write");
let before = generated_platform_projects(&root);
std::fs::create_dir_all(root.join("export/Unity-iPhone.xcodeproj")).expect("mkdir");
let after = generated_platform_projects(&root);
let _ = std::fs::remove_dir_all(&root);
assert_eq!(
before,
["Pump Game – iOS (Xcode)", "Pump Game – Android (Gradle)"]
);
assert_eq!(after, ["Pump Game – Android (Gradle)"]);
}
#[test]
fn binary_or_missing_settings_target_nothing() {
assert!(read_player_settings("\u{0}\u{0}binary").is_none());
let dir = std::env::temp_dir().join(format!("cs-unityset-{}", uuid::Uuid::new_v4()));
assert_eq!(unity_platforms(&dir), UnityPlatforms::default());
}
}
+5
View File
@@ -208,6 +208,11 @@ pub enum SkipCode {
/// A scheduled or webhook scan found no new commits since the last scan,
/// so nothing was scanned again.
NoNewCommits,
/// A Unity project builds for a mobile platform whose native project
/// (Xcode, Gradle) Unity generates at build time, so its settings and
/// native code are not in the repository; `subject` names the project and
/// platform.
PlatformProjectGenerated,
}
/// Why a scan run failed, stable for the dashboard to word.
+26
View File
@@ -443,6 +443,10 @@ pub mod scans {
de: "Abhängigkeiten (SBOM)",
en: "Dependencies (SBOM)",
},
"platform_project" => Text {
de: "Von Unity erzeugtes App-Projekt",
en: "App project generated by Unity",
},
"firmware_sbom" => Text {
de: "Firmware-SBOM",
en: "Firmware SBOM",
@@ -586,6 +590,18 @@ pub mod scans {
\"Run scan\" always scans in full."
.into()
}
(SkipCode::PlatformProjectGenerated, Lang::De) => format!(
"Für {subject} erzeugt Unity das App-Projekt erst beim Build; es liegt nicht \
im Repository. Info.plist bzw. Manifest, Berechtigungen und nativer Code sind \
daher nicht geprüft. Exportieren Sie das Projekt aus Unity und laden Sie es als \
Archiv hoch, damit sie geprüft werden."
),
(SkipCode::PlatformProjectGenerated, Lang::En) => format!(
"For {subject}, Unity generates the app project at build time; it is not in the \
repository, so its Info.plist or manifest, permissions and native code are not \
checked. Export the project from Unity and upload it as an archive to have them \
checked."
),
}
}
@@ -2939,6 +2955,16 @@ mod skipped_reason_tests {
instead",
);
assert!(skipped_reason(&image, Lang::De).starts_with("Firmware-Images werden noch nicht"));
let unity = SkippedStage::new(
"platform_project",
SkipCode::PlatformProjectGenerated,
"generated at build time",
)
.about("Pump Game – iOS (Xcode)");
assert!(skipped_reason(&unity, Lang::De)
.starts_with("Für Pump Game – iOS (Xcode) erzeugt Unity das App-Projekt erst"));
assert!(skipped_reason(&unity, Lang::En)
.starts_with("For Pump Game – iOS (Xcode), Unity generates the app project"));
}
#[test]
+3 -2
View File
@@ -761,9 +761,10 @@
"android-sdk-end-of-support",
"unity-editor-end-of-support",
"ios-deployment-target-end-of-support",
"swift-version-end-of-support"
"swift-version-end-of-support",
"android-min-sdk-end-of-support"
],
"check": "The platform a product is built for, and the tools it is built with, must still receive security updates; an Android API level, a Unity editor release or an iOS deployment target out of support, or a Swift version no supported Xcode builds, violates it."
"check": "The platform a product is built for, and the tools it is built with, must still receive security updates; an Android API level, a Unity editor release, an iOS deployment target or an Android minimum API level out of support, or a Swift version no supported Xcode builds, violates it."
}
],
"note": null,
+16 -4
View File
@@ -54,6 +54,15 @@ Prüfwerk builds the SBOM during each scan:
`ProjectSettings/ProjectVersion.txt`) and the packages pinned in
`Packages/packages-lock.json` (or `Packages/manifest.json`). No advisory
database covers Unity, so they are listed under **CVE-Abgleich unvollständig**.
Which mobile platforms a Unity project builds for is read from its Player
Settings (`ProjectSettings/ProjectSettings.asset`): a bundle identifier set
for iOS or Android (not Unity's `com.DefaultCompany.…` default), or native
plug-ins under `Assets/Plugins/iOS` or `Assets/Plugins/Android`. The active
build target itself is never in the repository. For each such platform the
Xcode or Gradle project Unity generates at build time is missing, so its
Info.plist or manifest, permissions and native code cannot be checked; the
scan says so under **Nicht ausgeführt** (*Von Unity erzeugtes App-Projekt*)
unless an exported project is in the tree.
**End-of-life build systems are not resolved.** An Eclipse/ADT Android project
(`default.properties` or `project.properties` beside the manifest, no Gradle)
@@ -62,11 +71,14 @@ nowhere readable. Prüfwerk reports it as a finding (**Legacy build system: the
SBOM cannot be determined**, with the migration as the remedy) and lists it
under **Nicht ausgeführt**, so the SBOM requirements are **Nicht bewertet**
rather than clean. An Android API level below 29 or a Unity release out of
support is a finding of its own, and so is, in an Xcode project, an iOS
deployment target below 15 (the app then installs on iOS releases that receive
support is a finding of its own, and so is, in an Xcode project or the
Player Settings of a Unity project building for iOS, an iOS deployment target
below 15 (the app then installs on iOS releases that receive
no security updates) or a `SWIFT_VERSION` below 4, which no supported Xcode
builds. Which Xcode builds an app is not recorded in the repository and is not
judged.
builds. A Unity project building for Android whose minimum API level is below
29 is reported the same way (the app installs on Android releases without
security updates). Which Xcode builds an app is not recorded in the repository
and is not judged.
Firmware images, container images and app packages are not unpacked yet; their
components come from the source code.
@@ -1,7 +1,7 @@
{
"scan_status": "completed",
"skipped_stages": [
"sbom_dependencies"
"cve_lookup"
],
"sbom": [
"carthage:Alamofire/Alamofire@4.8.2",
@@ -0,0 +1,16 @@
{
"scan_status": "completed",
"skipped_stages": [
"cve_lookup",
"platform_project",
"sast_vendor_code"
],
"sbom": [
"unity:Unity Editor@2022.3.50f1"
],
"findings": [],
"cves": [
"android-min-sdk-end-of-support",
"ios-deployment-target-end-of-support"
]
}
+2 -1
View File
@@ -12,9 +12,10 @@ as a source archive. They prove that no mobile app ends with "0 packages,
| `ios-cocoapods` | `Podfile.lock` (AFNetworking 2.5.1) | 2 pods; a recorded `cve_lookup` skip, as OSV has no CocoaPods advisories |
| `ios-spm-xcode` | `Package.resolved` inside the Xcode project (swift-nio-http2 1.19.0) | 1 Swift component with its advisories (needs the purl in repository form) |
| `ios-spm-unlocked` | nothing: the Xcode project names a Swift package | none; a recorded `sbom_dependencies` skip naming `project.pbxproj` |
| `ios-carthage-legacy` | `Cartfile.resolved` (Alamofire 4.8.2, grpc-swift 1.0.0, a binary vendor framework); an Xcode project at iOS 10 and Swift 3 | both repositories as Swift components, grpc-swift with its advisories; the binary framework listed without; a recorded `sbom_dependencies` skip naming the binary pin; the iOS deployment target and Swift version lifecycle findings |
| `ios-carthage-legacy` | `Cartfile.resolved` (Alamofire 4.8.2, grpc-swift 1.0.0, a binary vendor framework); an Xcode project at iOS 10 and Swift 3 | both repositories as Swift components, grpc-swift with its advisories; the binary framework listed without; a recorded `cve_lookup` skip naming it as not matched; the iOS deployment target and Swift version lifecycle findings |
| `flutter` | `pubspec.lock` (dio 3.0.10); the Android host app is unlocked | the Dart packages and the host app's direct Gradle dependency; a recorded `sbom_dependencies` skip |
| `react-native` | `package-lock.json`; neither `ios/Podfile` nor the Gradle app is locked | the npm packages; a recorded `sbom_dependencies` skip |
| `unity-mobile` | `Packages/packages-lock.json` (built-in UI package only) | Unity 2022.3 building for iOS and Android (bundle ids, iOS plug-in): the iOS 12 and Android API 22 minimums as lifecycle findings, both generated app projects under `platform_project`, the editor as an SBOM component |
| `android-insecure` | nothing (no Gradle lock) | mobsfscan: manifest (debuggable, backups, cleartext, minSdk), Kotlin (JavaScript bridge, MD5), Java under `inspection/` (world-readable, `Random`) |
| `ios-insecure` | nothing | mobsfscan: ATS off in `Info.plist`, `CC_MD5` in Swift, `NSLog` in Objective-C; semgrep: the password `Store.swift` keeps in `UserDefaults` |
@@ -0,0 +1,3 @@
#import <Foundation/Foundation.h>
void PRVibrate(void) {}
@@ -0,0 +1,6 @@
using UnityEngine;
public class PumpGauge : MonoBehaviour
{
public float flow;
}
@@ -0,0 +1,5 @@
{
"dependencies": {
"com.unity.ugui": "1.0.0"
}
}
@@ -0,0 +1,10 @@
{
"dependencies": {
"com.unity.ugui": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
}
}
}
@@ -0,0 +1,42 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 26
productGUID: 4f1c2d0e8a9b4c7d9e0f1a2b3c4d5e6f
AndroidProfiler: 0
companyName: Example
productName: Pump Remote
defaultScreenWidth: 1024
defaultScreenHeight: 768
bundleVersion: 2.4.1
applicationIdentifier:
Android: com.example.pumpremote
Standalone: com.DefaultCompany.PumpRemote
iPhone: com.example.pumpremote
buildNumber:
Standalone: 0
iPhone: 41
AndroidBundleVersionCode: 41
AndroidMinSdkVersion: 22
AndroidTargetSdkVersion: 0
AndroidPreferredInstallLocation: 1
aotOptions:
stripEngineCode: 1
iPhoneStrippingLevel: 0
iPhoneScriptCallOptimization: 0
ForceInternetPermission: 0
ForceSDCardPermission: 0
CreateWallpaper: 0
APKExpansionFiles: 0
keepLoadedShadersAlive: 0
StripUnusedMeshComponents: 1
VertexChannelCompressionMask: 4054
iPhoneSdkVersion: 988
iOSTargetOSVersionString: 12.0
tvOSSdkVersion: 0
tvOSRequireExtendedGameController: 0
tvOSTargetOSVersionString: 12.0
AndroidKeystoreName:
AndroidKeyaliasName:
@@ -0,0 +1,2 @@
m_EditorVersion: 2022.3.50f1
m_EditorVersionWithRevision: 2022.3.50f1 (c3db7f8bf9b1)
+20 -1
View File
@@ -628,7 +628,7 @@
"key": "mobile-ios-carthage-legacy",
"name": "iOS · Carthage and an old Xcode project",
"target_type": "ios_app",
"description": "Uploaded as a source archive. A Swift 3 app with an iOS 10 deployment target that pins Alamofire 4.8.2, grpc-swift 1.0.0 and a prebuilt vendor framework in Cartfile.resolved. The repositories must appear as Swift purls (pkg:swift/github.com/grpc/grpc-swift@1.0.0) so OSV matches grpc-swift's advisories, the binary framework must be listed and named under sbom_dependencies, and both iOS lifecycle findings must be raised.",
"description": "Uploaded as a source archive. A Swift 3 app with an iOS 10 deployment target that pins Alamofire 4.8.2, grpc-swift 1.0.0 and a prebuilt vendor framework in Cartfile.resolved. The repositories must appear as Swift purls (pkg:swift/github.com/grpc/grpc-swift@1.0.0) so OSV matches grpc-swift's advisories, the binary framework must be listed and named as not matched under cve_lookup, and both iOS lifecycle findings must be raised.",
"artifacts": [
{
"kind": "source_archive",
@@ -784,6 +784,25 @@
],
"min_sbom_components": 1
}
},
{
"key": "mobile-unity-mobile",
"name": "Unity 2022.3 app for iOS and Android",
"target_type": "ios_app",
"description": "Uploaded as a source archive. A supported Unity 2022.3 project whose Player Settings set iOS and Android bundle identifiers, with an iOS native plug-in, minimum iOS 12.0 and Android API 22. Both minimums must give lifecycle findings, the Xcode and Gradle projects Unity generates must be recorded under platform_project, and no legacy-build or editor end-of-support finding may appear.",
"artifacts": [
{
"kind": "source_archive",
"upload": "fixtures/nightly/mobile/unity-mobile"
}
],
"expect": {
"sast_rule_ids": [
"ios-deployment-target-end-of-support",
"android-min-sdk-end-of-support"
],
"min_sbom_components": 1
}
}
]
}