Kmp Dependency Security
ASecurityUse when auditing or hardening the dependency supply chain of a Kotlin Multiplatform app across Gradle and SwiftPM - gradle/verification-metadata.xml, "Dependency verification failed", gradle.lockfile or --write-locks, a CVE or GHSA in a Gradle dependency, OSV-Scanner, an SBOM (CycloneDX, swift package generate-sbom), Dependabot or Renovate for libs.versions.toml or Package.resolved, no Dependabot alerts for Gradle, Podfile.lock, gitleaks or a secret committed to git, or OWASP Mobile M2 suppl...
- 17 stars
- 0 votes
- 0 copies
- 0 views
- Added December 3, 2026
Works with
Security analysis
100/100Pro scans all 4 files and shows the line behind each finding
npx -y skills add Kushpawan/kmp-mobile-skills --skill kmp-dependency-security --agent claude-codeAre you the author of Kmp Dependency Security?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/kushpawan-kmp-dependency-security)---
name: kmp-dependency-security
description: Use when auditing or hardening the dependency supply chain of a Kotlin Multiplatform app across Gradle and SwiftPM - gradle/verification-metadata.xml, "Dependency verification failed", gradle.lockfile or --write-locks, a CVE or GHSA in a Gradle dependency, OSV-Scanner, an SBOM (CycloneDX, swift package generate-sbom), Dependabot or Renovate for libs.versions.toml or Package.resolved, no Dependabot alerts for Gradle, Podfile.lock, gitleaks or a secret committed to git, or OWASP Mobile M2 supply chain.
license: Apache-2.0
compatibility: Kotlin Multiplatform Gradle project in git. iOS parts need macOS with Xcode; SwiftPM SBOMs need Swift 6.4+ and a Package.swift. Optional tools - osv-scanner, gitleaks, Docker. Scanners query online vulnerability databases. Tool versions and flags verified December 2026.
metadata:
category: review
platforms: android, ios
---
# KMP dependency security
A KMP app ships code from two package managers — Gradle (Maven repositories) for Android and the
shared Kotlin, SwiftPM or CocoaPods for the iOS host app — and each needs the same four controls:
**pin** what is resolved, **verify** what is downloaded, **scan** what is pinned, and **watch** it in
CI. Close the gaps the project has; never replace controls it already runs. Ask before you upgrade
anything or rewrite verification metadata, and never paste a secret a scan finds.
## When to use
- "Are our dependencies safe?", a pre-release or pre-pen-test supply-chain check, OWASP Mobile Top 10
M2 (Inadequate Supply Chain Security), or a customer or regulator asking for an SBOM.
- Setting up or fixing Gradle dependency verification (`gradle/verification-metadata.xml`) or
dependency locking (`gradle.lockfile`), or a build failing with `Dependency verification failed`.
- A CVE, GHSA or OSV advisory names a library the app uses, on either platform.
- Adding OSV-Scanner, Dependabot, Renovate, GitHub dependency submission or gitleaks to CI.
- Dependabot shows no alerts for the Gradle side, or no updates for Swift packages in an `.xcodeproj`.
- A token, key or password may have been committed.
## When not to use
- Reviewing app code for security (storage, network, WebView, deep links, logging): use
`mobile-security-review`. This skill owns third-party dependencies, the build supply chain and
secrets in git.
- Choosing or bumping a library version as a feature task: use `kmp-gradle-version-catalog`.
A fix that needs Kotlin, AGP, Compose Multiplatform, Gradle or Xcode to move: use
`kmp-toolchain-upgrade`.
- Build and test jobs in GitHub Actions: use `kmp-ci-github-actions`. This skill adds security jobs
next to them.
- Signing keys, keystores and store credentials: use `mobile-release`.
## Step 0 — Read the project first
```bash
git ls-files | grep -E '(^|/)(gradle\.lockfile|buildscript-gradle\.lockfile|settings-gradle\.lockfile)$'
ls gradle/verification-metadata.xml gradle/verification-keyring.* 2>/dev/null
grep -nE '<verify-(metadata|signatures)>' gradle/verification-metadata.xml 2>/dev/null
grep -rnE 'dependencyLocking|activateDependencyLocking|lockAllConfigurations' --include='*.gradle.kts' . | head
grep -n 'distributionSha256Sum' gradle/wrapper/gradle-wrapper.properties
grep -nE 'cyclonedx|dependency-?check|osv' gradle/libs.versions.toml
ls .github/dependabot.yml .github/dependabot.yaml renovate.json renovate.json5 .github/renovate.json* 2>/dev/null
grep -lE 'osv-scanner|dependency-submission|dependency-review|gitleaks|trufflehog|codeql|snyk' .github/workflows/* 2>/dev/null
ls .gitleaks.toml .gitleaksignore osv-scanner.toml .pre-commit-config.yaml 2>/dev/null
git ls-files | grep -E '(^|/)(Package\.swift|Package\.resolved|Podfile|Podfile\.lock|Gemfile\.lock)$'
grep -rnE 'native\.cocoapods|cocoapods \{' --include='*.gradle.kts' . | head
git ls-files | grep -iE '\.(jks|keystore|p12|p8|mobileprovision)$|google-services\.json|GoogleService-Info\.plist|(^|/)\.env'
```
Record, as a table: each ecosystem in use (Gradle, SwiftPM via `.xcodeproj`, SwiftPM via
`Package.swift`, CocoaPods, Bundler for Fastlane, GitHub Actions), and for each one whether it is
pinned, verified, scanned, and updated by a bot. Note which update bot the project uses — **keep it**;
never add Dependabot next to Renovate for the same ecosystem. Note any existing scanner and its
ignore file: findings it already accepted are decisions to respect, not to re-litigate.
## Ground rules
- **Ask first** before: bootstrapping or regenerating `verification-metadata.xml`, writing or
updating lockfiles, bumping any version, adding a Gradle plugin, or adding a workflow. Show the
command and the files it changes.
- **Secrets:** run gitleaks with `--redact`. Report rule id, file, line and commit only — never the
value, not even partially. A live secret means **rotate first** (step 4), then clean up.
- **No history rewrites** (`git filter-repo`, BFG, force-push) without explicit approval: they break
every clone and open PR.
- Every tool command pins a version. Never pipe a downloaded installer into a shell.
## Workflow
### 1. Inventory what ships
Separate what reaches users from what only builds them. Get the real configuration names first:
```bash
./gradlew :shared:resolvableConfigurations | grep -E '^Configuration' | head -60
./gradlew :shared:dependencies --configuration <a release runtime classpath from the list above>
./gradlew :androidApp:dependencies --configuration releaseRuntimeClasspath # Android app module
./gradlew buildEnvironment # plugin classpath
```
iOS: read every `Package.resolved` (inside `*.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/`
or `*.xcworkspace/xcshareddata/swiftpm/`, or next to `Package.swift`) and `Podfile.lock`. Fastlane
pulls Ruby gems through `Gemfile.lock`; CI pulls GitHub Actions by tag.
Done when: a table lists each ecosystem, its lock file (or "none"), and its shipped scope
(app runtime / iOS framework / build tooling / test only).
### 2. Pin and verify
Gradle has two separate controls; most projects need both. Details, XML and KMP host traps are in
[references/gradle-verification-and-locking.md](references/gradle-verification-and-locking.md).
| Control | Stops | Files |
|---|---|---|
| Dependency **locking** | A version range, `+`, or a transitive bump silently changing what resolves | `gradle.lockfile` per project, `buildscript-gradle.lockfile` |
| Dependency **verification** | A tampered or substituted artifact (wrong checksum or signature) | `gradle/verification-metadata.xml`, optional keyring |
| Wrapper checksum | A tampered Gradle distribution | `distributionSha256Sum` in `gradle-wrapper.properties` |
- A catalog with exact versions already pins direct dependencies; transitive ones still float when a
direct one changes. Lockfiles also give OSV-Scanner an exact graph to scan.
- Bootstrapping verification **trusts whatever the repositories serve today**. After
`./gradlew --write-verification-metadata sha256` (or `sha256,pgp`), review the diff before
committing it. Check new `origin="Generated by Gradle"` entries against the publisher where you
can.
- iOS: commit `Package.resolved` (SwiftPM pins exact revisions there) and `Podfile.lock`. SwiftPM and
CocoaPods have no equivalent of Gradle's checksum file for this skill to configure; see
[references/ios-dependencies.md](references/ios-dependencies.md).
Done when: each ecosystem has a committed lock file, and Gradle verification is either on and
green on every CI host or explicitly declined by the user.
### 3. Scan
**OSV-Scanner** (Apache-2.0, v2.7.1, Nov 2026) reads `gradle.lockfile`, `buildscript-gradle.lockfile`,
`gradle/verification-metadata.xml` and CycloneDX/SPDX SBOMs (`bom.json`, `*.cdx.json`,
`*.spdx.json`). Its supported-lockfile list has **no** SwiftPM `Package.resolved` and **no**
`Podfile.lock` entry.
```bash
# Pinned install (pick one); then confirm with: osv-scanner --version
go install github.com/google/osv-scanner/v2/cmd/osv-scanner@v2.7.1
docker run --rm -v "$PWD":/src ghcr.io/google/osv-scanner:v2.7.1 scan source -r /src
osv-scanner scan source -r . # lockfiles + verification metadata
osv-scanner scan source -L shared/gradle.lockfile --format json --output-file osv.json
```
- **No lockfiles?** Generate a CycloneDX SBOM (step 5) and scan it explicitly:
`osv-scanner scan source -L build/reports/cyclonedx/bom.json`. A recursive scan skips `build/`
because it honours `.gitignore`.
- `verification-metadata.xml` lists every artifact the build ever verified, including plugins,
test libraries and stale versions — a hit there may not ship. Confirm against step 1.
- **iOS**: use Dependabot alerts for the `swift` ecosystem, or query the OSV API per public pin
(`SwiftURL` ecosystem, e.g. `github.com/apple/swift-nio`) — commands in
[references/ios-dependencies.md](references/ios-dependencies.md). CocoaPods has no scanner here;
list each pod and check its advisories by hand.
**gitleaks** (MIT, v8.30.1, Mar 2026) for secrets in history and in the working tree:
```bash
docker run --rm -v "$PWD":/repo ghcr.io/gitleaks/gitleaks:v8.30.1 git --redact -v -i /repo /repo # history
docker run --rm -v "$PWD":/repo ghcr.io/gitleaks/gitleaks:v8.30.1 dir --redact -i /repo /repo # working tree
# or the v8.30.1 release binary, checked against gitleaks_8.30.1_checksums.txt from the same release
```
Also list keystores, provisioning profiles and `.env` files from Step 0 — gitleaks matches text
patterns and does not flag a committed binary keystore.
Done when: every ecosystem has a scan result or a stated reason it was NOT RUN.
### 4. Triage each finding
For each finding record: id (GHSA/CVE/OSV), package and version, ecosystem, **shipped scope** from
step 1, fixed version, and a verdict.
| Question | How to answer |
|---|---|
| Does it ship? | Only in `buildEnvironment`, a test configuration or a stale verification entry → lower priority, still fix on the next bump |
| Which platforms? | A JVM-only library in `androidMain` does not ship on iOS; a `commonMain` one ships on both |
| Is the vulnerable code reachable? | Read the advisory's affected functions; search the codebase for calls. Server-side or desktop-only paths of a library are often unused on mobile |
| Is there a fixed version? | Advisory "patched versions"; OSV `affected.ranges` |
| Can it move alone? | Direct dependency → bump its catalog entry (`kmp-gradle-version-catalog`). Transitive → bump the parent, or add a constraint. Tied to Kotlin, AGP, Compose or Xcode → `kmp-toolchain-upgrade` |
A transitive fix without a parent release can be forced with a constraint whose version lives in
the catalog:
```toml
# gradle/libs.versions.toml
[versions]
okio = "<patched version from the advisory>"
```
```kotlin
// shared/build.gradle.kts - raise a vulnerable transitive dependency; remove when the parent catches up
dependencies {
constraints {
add("commonMainImplementation", "com.squareup.okio:okio:${libs.versions.okio.get()}") {
because("<advisory id>: transitive version is vulnerable")
}
}
}
```
If the project already uses `dependencies { constraints { } }` or a platform BOM, follow that
instead. **Accepting** a finding is a decision for the user: record it with a reason and an expiry
in the scanner's ignore file (`osv-scanner.toml` `[[IgnoredVulns]]` with `reason` and
`effectiveUntil`), never with a blanket package ignore.
**Secret findings:** decide if the value is live and private. Firebase and Google API keys in
`google-services.json` / `GoogleService-Info.plist` are client identifiers that ship in every build
— confirm they are restricted in the provider console instead of treating them as leaks. Anything
else (server keys, signing passwords, PATs, private keys) is a leak: **rotate or revoke it at the
issuer first**, then remove it from the tree, then ask before any history rewrite. A secret pushed
to a remote is compromised even after a rewrite.
Done when: every finding has a verdict — fix now, fix with next bump, accepted (with expiry), or
false positive (with reason).
### 5. SBOM
Gradle: the CycloneDX Gradle plugin (Apache-2.0, v3.6.1, Nov 2026; needs Gradle 8.4+). Apply it to
the root project:
```toml
# gradle/libs.versions.toml
[versions]
cyclonedx = "3.6.1"
[plugins]
cyclonedx = { id = "org.cyclonedx.bom", version.ref = "cyclonedx" }
```
```kotlin
// build.gradle.kts (root)
plugins {
alias(libs.plugins.cyclonedx)
}
```
`./gradlew cyclonedxBom` writes the aggregate SBOM to `build/reports/cyclonedx/bom.{json,xml}`;
`./gradlew :shared:cyclonedxDirectBom` writes one project's. Narrow it to shipped configurations with
`includeConfigs` / `skipConfigs` and set `failOnUnresolvedDependencies = true` (plugin 3.6.0+) —
see the reference. SwiftPM (Swift 6.4+, packages with a `Package.swift`):
`swift package generate-sbom --sbom-spec cyclonedx`. An Xcode-only project has no SwiftPM command for
this; record its packages from `Package.resolved` instead.
Done when: the SBOM is generated from a successful build and attached to the release, or the user
declined it.
### 6. Wire CI
Ready-to-adapt workflows are in [references/ci-workflows.md](references/ci-workflows.md):
- `dependabot.yml` for `gradle` (catalog, lockfiles), `swift` (`Package.swift` or, since 31 Mar 2026,
`.xcodeproj`), `github-actions` and `bundler`. Dependabot has no CocoaPods ecosystem.
- **Gradle Dependabot alerts need the dependency submission API**: Dependabot reads build files but
raises Gradle security alerts only from a submitted graph. Use
`gradle/actions/dependency-submission@v6` on pushes to `main`, plus
`actions/dependency-review-action@v5` on PRs.
- OSV-Scanner reusable workflows (`google/osv-scanner-action`, `@v2.7.1`) for PRs and a weekly scan.
- gitleaks on every PR. `gitleaks/gitleaks-action@v3` needs a `GITLEAKS_LICENSE` secret for
organization repositories and is not MIT-licensed; the pinned container avoids both.
- Renovate instead of Dependabot only if the project already uses it — see the reference.
Done when: workflows are added (after approval), and one real run has been observed for each.
### 7. Report
```text
Supply chain - <app> - <date>
| Ecosystem | Pinned | Verified | Scanned | Bot |
| Gradle | lockfiles: yes | sha256 + pgp: yes | OSV: 2 findings | Dependabot |
| SwiftPM .xcodeproj | Package.resolved| n/a | Dependabot alerts| Dependabot |
| CocoaPods | Podfile.lock | n/a | NOT RUN (no tool)| none |
Findings: <id> <package>@<version> <scope> <verdict> <next step>
Secrets: <rule> <file>:<line> <commit> - rotated: yes/no (value not shown)
Not done / needs approval: ...
```
## Quick reference
| Need | Command or file |
|---|---|
| Bootstrap Gradle checksums | `./gradlew --write-verification-metadata sha256` (review the diff) |
| Preview without writing | `./gradlew --write-verification-metadata sha256 help --dry-run` |
| Verification mode | `--dependency-verification strict\|lenient\|off`; default `strict` |
| Full failure detail in CI logs | `org.gradle.dependency.verification.console=verbose` in `gradle.properties` |
| Lock all configurations | `dependencyLocking { lockAllConfigurations() }`, then `./gradlew :shared:dependencies --write-locks` |
| Update one locked module | `./gradlew :shared:dependencies --update-locks com.squareup.okio:okio` |
| Scan | `osv-scanner scan source -r .` (v2.7.1) |
| Accept a finding | `osv-scanner.toml` `[[IgnoredVulns]]` with `reason`, `effectiveUntil` |
| Gradle SBOM | `./gradlew cyclonedxBom` (plugin `org.cyclonedx.bom` 3.6.1) |
| SwiftPM SBOM | `swift package generate-sbom --sbom-spec cyclonedx` (Swift 6.4+) |
| Secrets | `gitleaks git --redact` / `gitleaks dir --redact` (v8.30.1) |
| Gradle alerts on GitHub | `gradle/actions/dependency-submission@v6` |
| PR gate on new vulnerable deps | `actions/dependency-review-action@v5` |
## Verify
Report each check as `PASS`, `FAIL` or `NOT RUN` with the reason. Never mark a check PASS that you
did not run. Replace `:shared` and `:androidApp` with the project's modules.
```bash
./gradlew --dependency-verification strict help # verification metadata is complete for configuration
./gradlew :shared:allTests :androidApp:assembleRelease # verification + locks hold for real task resolution
osv-scanner scan source -r . # findings match the triage table
docker run --rm -v "$PWD":/repo ghcr.io/gitleaks/gitleaks:v8.30.1 git --redact /repo # no unexplained leaks
./gradlew cyclonedxBom && test -s build/reports/cyclonedx/bom.json # if the SBOM was added
git status --porcelain -- gradle/ '*gradle.lockfile' # nothing regenerated without approval
```
Verification and locks must pass on **each CI host** (Linux and macOS): KMP resolves some artifacts
on one host only. A workflow is verified only by an observed run; parsing YAML is not a run. iOS
checks are NOT RUN without macOS; say where they will run.
## Common mistakes
| Mistake | Why it bites | Fix |
|---|---|---|
| Committing bootstrapped `verification-metadata.xml` unreviewed | It records whatever the repository served, including a compromised artifact | Review the diff; check new entries against the publisher |
| `--write-verification-metadata` to "fix" a checksum mismatch | Overwrites the one signal that an artifact changed | Treat a mismatch as a possible compromise; investigate first (reference) |
| Generating metadata or locks on macOS only | Linux CI fails on artifacts or configurations it resolves differently | Run on each CI host; merge the results |
| `./gradlew dependencies --write-locks` at the root only | `dependencies` runs on one project; subprojects keep no lock state | Run it per project or use a resolve-all task |
| Expecting Dependabot alerts for Gradle from build files alone | Gradle security alerts come only from a submitted graph | Add the dependency submission workflow |
| Adding Dependabot to a Renovate project | Duplicate PRs and conflicting lockfile edits | Keep the bot the project already has |
| Recursive OSV scan expecting `build/reports/cyclonedx/bom.json` | `.gitignore`d paths are skipped | Pass the SBOM with `-L` |
| Blanket ignore of a package in the scanner config | Hides every future advisory for it | Ignore one id, with `reason` and `effectiveUntil` |
| Pasting a found secret into the report or a PR | Spreads the leak further | Redact; report location only; rotate first |
| Deleting a leaked key in a new commit and calling it fixed | It stays in history and in every clone and fork | Rotate at the issuer; history rewrite only with approval |
| Bumping Kotlin or Compose to fix a transitive CVE inside a security PR | Toolchain changes need their own sequence | Constraint now; toolchain bump via `kmp-toolchain-upgrade` |
| Assuming CocoaPods will get the fix | CocoaPods trunk planned to stop accepting new podspecs on 2 Dec 2026 | Plan a move to SwiftPM for that dependency (reference) |
## Related skills
- `mobile-security-review` — app-code security review; it hands dependency findings to this skill.
- `kmp-gradle-version-catalog` — catalog edits for the upgrade a finding needs.
- `kmp-toolchain-upgrade` — when the fix needs Kotlin, AGP, Compose Multiplatform, Gradle or Xcode.
- `kmp-ci-github-actions` — the build and test workflows these jobs sit beside.
- `kmp-build-check` — confirm both platforms still build after a dependency change.
- `mobile-release` — signing keys, keystores and release credentials.
- Trail of Bits [static-analysis](https://github.com/trailofbits/skills/tree/main/plugins/static-analysis)
(CodeQL, Semgrep, SARIF parsing; CC-BY-SA-4.0, linked not copied) for first-party code scanning.
Its [supply-chain-risk-auditor](https://github.com/trailofbits/skills/blob/main/plugins/supply-chain-risk-auditor/skills/supply-chain-risk-auditor/SKILL.md)
covers npm, PyPI and Go, not Gradle or SwiftPM.
Files in this skill
- SKILL.md
- references/ci-workflows.md
- references/gradle-verification-and-locking.md
- references/ios-dependencies.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.