From 48c80dbe18757198812df6efc39e8c50a3c6fcd0 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Tue, 6 Oct 2026 02:51:11 +0200 Subject: [PATCH] test(nightly): public mobile apps at pinned commits; two scanner fixes they exposed iOS readiness, story 5. The nightly now also scans two public apps, fetched at pinned commits like the Zephyr and CODESYS samples (not committed; skipped where the env var is unset): - nalexn/clean-architecture-swiftui (MIT): a current SwiftUI app (iOS 18, Swift 5) with Swift packages but no Package.resolved; - android/nowinandroid (Apache-2.0): a large current Android app with version catalogs and two application modules (app, app-nia-catalog, which become variants). What they found, fixed here: - mobsfscan failed on every SwiftUI app: semgrep reports a file it parses only in part (newer Swift syntax) as an error object, which our report type read as a string, so the whole sast_mobile stage was skipped as "did not complete". Errors are now read as objects or text; semgrep's warnings (level "warn") do not fail the run, and neither kind is logged with its message, which quotes the scanned code (counts only). - gitleaks' generic-api-key flagged 30 Firebase Storage download URLs (`?alt=media&token=`) in nowinandroid; such a token only makes one stored file public and ships with the app by design. A global allowlist (line regex) drops those lines; checked with the image's gitleaks 8.21.2 (`[allowlist]`, as it predates `[[allowlists]]`), and a real key on another line is still reported. Baselines: swiftui completes with only the sbom_dependencies skip; nowinandroid has 63 components and 7 mobsfscan findings, labelled by app module. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- .gitea/workflows/nightly.yml | 15 ++++ compliance-agent/rules/gitleaks.toml | 14 ++++ compliance-agent/src/pipeline/mobsfscan.rs | 63 ++++++++++++--- .../mobile-public-android-nowinandroid.json | 81 +++++++++++++++++++ .../baselines/mobile-public-ios-swiftui.json | 9 +++ fixtures/nightly/targets.json | 31 +++++++ 6 files changed, 203 insertions(+), 10 deletions(-) create mode 100644 fixtures/nightly/baselines/mobile-public-android-nowinandroid.json create mode 100644 fixtures/nightly/baselines/mobile-public-ios-swiftui.json diff --git a/.gitea/workflows/nightly.yml b/.gitea/workflows/nightly.yml index d3673ae..fd75f42 100644 --- a/.gitea/workflows/nightly.yml +++ b/.gitea/workflows/nightly.yml @@ -131,6 +131,19 @@ jobs: env: RUSTC_WRAPPER: "" + # Public mobile apps at pinned commits (MIT, Apache-2.0): a current + # SwiftUI app and a large Android app, so the mobile checks meet real + # projects, not only the hand-written fixtures. Not committed, as with + # the Zephyr example. + - name: Fetch the public mobile samples + run: | + curl -fsSL -o /tmp/ios-sample.zip \ + "https://codeload.github.com/nalexn/clean-architecture-swiftui/zip/9eca97b8cfff96a14084b564b1fefd949c93d232" + curl -fsSL -o /tmp/android-sample.zip \ + "https://codeload.github.com/android/nowinandroid/zip/a49ed253d75e61a2b6ab80a8da677b57437b08eb" + env: + RUSTC_WRAPPER: "" + - name: Wait for the agent run: | for i in $(seq 1 90); do @@ -148,6 +161,8 @@ jobs: NIGHTLY_AGENT_URL: http://agent:3001 NIGHTLY_CODESYS_SAMPLE: /tmp/csv-blackbox.projectarchive NIGHTLY_ZEPHYR_EXAMPLE: /tmp/zephyr-example.zip + NIGHTLY_IOS_SAMPLE: /tmp/ios-sample.zip + NIGHTLY_ANDROID_SAMPLE: /tmp/android-sample.zip NIGHTLY_BLESS: ${{ inputs.bless && '1' || '0' }} # upload-artifact is a Node action and the Rust image has no node. diff --git a/compliance-agent/rules/gitleaks.toml b/compliance-agent/rules/gitleaks.toml index 04b0263..f8a154b 100644 --- a/compliance-agent/rules/gitleaks.toml +++ b/compliance-agent/rules/gitleaks.toml @@ -37,3 +37,17 @@ regex = '''(AIza[\w-]{35})''' path = '''(?i)(?:^|/)(?:google-services\.json|GoogleService-Info\.plist)$''' secretGroup = 1 keywords = ["aiza"] + +# Firebase Storage download URLs (`…/o/?alt=media&token=`): the +# token makes one stored file publicly readable, it is meant to be shipped in +# the app with the file's URL, and it grants nothing else. gitleaks' generic +# rule reads it as an API key in every app that shows images this way. A line +# holding such a URL is not reported; a real key elsewhere on it is rare +# enough to accept. (`[allowlist]` rather than `[[allowlists]]`, which the +# gitleaks release in the image does not read yet.) +[allowlist] +description = "Firebase Storage download URLs" +regexTarget = "line" +regexes = [ + '''firebasestorage\.googleapis\.com/v0/b/[^/\s"']+/o/[^?\s"']+\?alt=media&(?:amp;)?token=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}''', +] diff --git a/compliance-agent/src/pipeline/mobsfscan.rs b/compliance-agent/src/pipeline/mobsfscan.rs index aa38d4f..c64f472 100644 --- a/compliance-agent/src/pipeline/mobsfscan.rs +++ b/compliance-agent/src/pipeline/mobsfscan.rs @@ -173,18 +173,24 @@ async fn run( } let report = std::fs::read(&report_path).map_err(|e| failed(Box::new(e)))?; let report: Report = serde_json::from_slice(&report)?; - // A tool error with nothing found means nothing was checked. - if report.results.is_empty() && !report.errors.is_empty() { + // A tool error with nothing found means nothing was checked. Semgrep's + // warnings (a file it parsed only in part, as with newer Swift syntax) + // are not: the rest of the tree was. Neither is logged with its message, + // which quotes the scanned code. + let (warnings, errors): (Vec<&ReportError>, Vec<&ReportError>) = + report.errors.iter().partition(|e| e.is_warning()); + if report.results.is_empty() && !errors.is_empty() { return Err(failed( - format!( - "{platform} run reported errors: {}", - report.errors.join(" / ") - ) - .into(), + format!("{platform} run reported {} error(s)", errors.len()).into(), )); } - for error in &report.errors { - tracing::warn!(%error, platform, "mobsfscan reported an error"); + if !warnings.is_empty() || !errors.is_empty() { + tracing::warn!( + platform, + warnings = warnings.len(), + errors = errors.len(), + "mobsfscan could not read every file in full" + ); } Ok(report.findings(repo_path, repo_id)) } @@ -195,7 +201,28 @@ struct Report { #[serde(default)] results: BTreeMap, #[serde(default)] - errors: Vec, + errors: Vec, +} + +/// An entry of the report's `errors`: mobsfscan's own as text, or the +/// semgrep error it passes on as an object (`{"level": "warn", …}`). +#[derive(Debug, serde::Deserialize)] +#[serde(untagged)] +enum ReportError { + Semgrep { + #[serde(default)] + level: Option, + }, + /// mobsfscan's own, as text; only counted. + Text(serde::de::IgnoredAny), +} + +impl ReportError { + /// Whether it is a warning (a file parsed only in part) rather than a + /// failure. + fn is_warning(&self) -> bool { + matches!(self, Self::Semgrep { level: Some(level) } if level == "warn") + } } /// One rule's matches and what it says about them. @@ -466,6 +493,22 @@ mod tests { assert_eq!(setting_key(""), None); } + #[test] + fn semgrep_parse_warnings_are_read_and_are_not_failures() { + // What mobsfscan writes for a SwiftUI app whose newer syntax semgrep + // parses only in part: the error is an object, not a string. + let report: Report = serde_json::from_str( + r#"{"errors": [ + {"code": 3, "level": "warn", "message": "Syntax error at line x.swift:1"}, + {"code": 2, "level": "error", "message": "boom"}, + "mobsfscan could not read the config" + ], "results": {}}"#, + ) + .expect("report"); + let warnings: Vec = report.errors.iter().map(ReportError::is_warning).collect(); + assert_eq!(warnings, [true, false, false]); + } + #[test] fn cwe_ids_are_normalised() { assert_eq!(normalise_cwe("cwe-489").as_deref(), Some("CWE-489")); diff --git a/fixtures/nightly/baselines/mobile-public-android-nowinandroid.json b/fixtures/nightly/baselines/mobile-public-android-nowinandroid.json new file mode 100644 index 0000000..f75f2d3 --- /dev/null +++ b/fixtures/nightly/baselines/mobile-public-android-nowinandroid.json @@ -0,0 +1,81 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "sbom_dependencies" + ], + "sbom": [ + "github:actions/checkout@v4", + "github:actions/create-release@v1", + "github:actions/setup-java@v5", + "github:actions/upload-artifact@v4", + "github:actions/upload-release-asset@v1", + "github:android-actions/setup-android@v3", + "github:github/codeql-action/upload-sarif@v3", + "github:gradle/actions/setup-gradle@v4", + "github:jlumbroso/free-disk-space@v1.3.1", + "github:madrapps/jacoco-report@v1.7.1", + "github:reactivecircus/android-emulator-runner@v2", + "github:stefanzweifel/git-auto-commit-action@v5", + "maven:accompanist-permissions@0.37.0", + "maven:activity-compose@1.9.3", + "maven:adaptive-layout@1.1.0-rc01", + "maven:adaptive-navigation3@1.3.0-alpha04", + "maven:adaptive-navigation@1.1.0-rc01", + "maven:adaptive@1.1.0-rc01", + "maven:appcompat@1.7.0", + "maven:benchmark-macro-junit4@1.5.0-alpha01", + "maven:browser@1.8.0", + "maven:coil-compose@2.7.0", + "maven:coil-svg@2.7.0", + "maven:coil@2.7.0", + "maven:converter-kotlinx-serialization@2.11.0", + "maven:core-ktx@1.15.0", + "maven:core-splashscreen@1.0.1", + "maven:core@1.7.0-rc01", + "maven:datastore@1.2.0", + "maven:espresso-core@3.6.1", + "maven:foundation@1.8.0-alpha07", + "maven:gradle-wrapper@UNKNOWN", + "maven:hilt-android-testing@2.59", + "maven:hilt-work@1.2.0", + "maven:javax.inject@1", + "maven:junit-ktx@1.3.0-rc01", + "maven:kotlinx-coroutines-core@1.10.1", + "maven:kotlinx-coroutines-guava@1.10.1", + "maven:kotlinx-coroutines-test@1.10.1", + "maven:kotlinx-datetime@0.6.1", + "maven:kotlinx-serialization-json@1.8.0", + "maven:lifecycle-runtime-compose@2.10.0", + "maven:lifecycle-viewmodel-navigation3@2.10.0", + "maven:logging-interceptor@4.12.0", + "maven:metrics-performance@1.0.0-beta01", + "maven:navigation3-runtime@1.0.0", + "maven:navigation3-ui@1.0.0", + "maven:play-services-oss-licenses@17.1.0", + "maven:profileinstaller@1.4.1", + "maven:protobuf-kotlin-lite@4.29.2", + "maven:retrofit@2.11.0", + "maven:robolectric@4.16", + "maven:roborazzi-accessibility-check@1.56.0", + "maven:roborazzi@1.56.0", + "maven:rules@1.7.0-rc01", + "maven:runner@1.7.0-rc01", + "maven:runtime-tracing@1.7.6", + "maven:savedstate-compose@1.3.1", + "maven:tracing-ktx@1.3.0-alpha02", + "maven:truth@1.4.4", + "maven:uiautomator@2.3.0", + "maven:window-core@1.3.0", + "maven:work-runtime-ktx@2.10.0" + ], + "findings": [ + "mobsfscan:android_kotlin_logging JankStatsModule.kt:37", + "mobsfscan:android_manifest_allow_backup AndroidManifest.xml:20 [app-nia-catalog]", + "mobsfscan:android_manifest_allow_backup AndroidManifest.xml:33 [app]", + "mobsfscan:android_manifest_missing_explicit_allow_backup AndroidManifest.xml:1", + "mobsfscan:android_manifest_missing_explicit_allow_backup AndroidManifest.xml:1 [app]", + "mobsfscan:android_task_hijacking2 AndroidManifest.xml:1 [app-nia-catalog]", + "mobsfscan:android_task_hijacking2 AndroidManifest.xml:1 [app]" + ], + "cves": [] +} diff --git a/fixtures/nightly/baselines/mobile-public-ios-swiftui.json b/fixtures/nightly/baselines/mobile-public-ios-swiftui.json new file mode 100644 index 0000000..c18f738 --- /dev/null +++ b/fixtures/nightly/baselines/mobile-public-ios-swiftui.json @@ -0,0 +1,9 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "sbom_dependencies" + ], + "sbom": [], + "findings": [], + "cves": [] +} diff --git a/fixtures/nightly/targets.json b/fixtures/nightly/targets.json index f89d17b..6475291 100644 --- a/fixtures/nightly/targets.json +++ b/fixtures/nightly/targets.json @@ -803,6 +803,37 @@ ], "min_sbom_components": 1 } + }, + { + "key": "mobile-public-ios-swiftui", + "name": "iOS · public SwiftUI app (pinned source)", + "target_type": "ios_app", + "description": "nalexn/clean-architecture-swiftui (MIT) as a source archive at a pinned commit: a current SwiftUI app (iOS 18, Swift 5) whose Xcode project uses Swift packages without a committed Package.resolved. Must be classified as an iOS app, raise no lifecycle or iOS settings findings, and record the unpinned Swift packages under sbom_dependencies. Not committed: the nightly job downloads it into NIGHTLY_IOS_SAMPLE; skipped where that is unset.", + "artifacts": [ + { + "kind": "source_archive", + "upload_env": "NIGHTLY_IOS_SAMPLE", + "optional": true, + "pin": "9eca97b8cfff96a14084b564b1fefd949c93d232" + } + ] + }, + { + "key": "mobile-public-android-nowinandroid", + "name": "Android · Now in Android (pinned source)", + "target_type": "android_app", + "description": "android/nowinandroid (Apache-2.0) as a source archive at a pinned commit: a large current Android app with Gradle version catalogs, Compose and many modules. Its direct dependencies must be read from the catalog and build files (no gradle.lockfile, so a recorded sbom_dependencies skip), mobsfscan must run with the Android rules, and its flavors, declared in a convention plugin rather than the app's build file, give no app variants. Not committed: the nightly job downloads it into NIGHTLY_ANDROID_SAMPLE; skipped where that is unset.", + "artifacts": [ + { + "kind": "source_archive", + "upload_env": "NIGHTLY_ANDROID_SAMPLE", + "optional": true, + "pin": "a49ed253d75e61a2b6ab80a8da677b57437b08eb" + } + ], + "expect": { + "min_sbom_components": 20 + } } ] }