Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit b39b707

Browse files
authored
Add MobSF static analysis integration and config (#1373)
* Add MobSF static analysis integration and config Introduces MobSF mobsfscan for static security analysis with a new GitHub Actions workflow, a .mobsf configuration file, and a justfile command for local usage. Updates the README with security scanning instructions and adds inline suppressions for specific MobSF rules. Also includes minor code cleanups and enum case renaming for consistency. * Update .mobsf * Update .mobsf
1 parent b970382 commit b39b707

8 files changed

Lines changed: 91 additions & 7 deletions

File tree

.github/workflows/mobsfscan.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: MobSF Scan
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
permissions:
10+
contents: read
11+
security-events: write
12+
13+
jobs:
14+
mobsfscan:
15+
name: mobsfscan static analysis
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Install uv
23+
run: |
24+
curl -LsSf https://astral.sh/uv/install.sh | sh
25+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
26+
27+
- name: Install mobsfscan
28+
run: uv tool install mobsfscan
29+
30+
- name: Run mobsfscan
31+
run: |
32+
set +e
33+
uv tool run mobsfscan -- --type ios --config .mobsf --sarif --output results.sarif --exit-warning
34+
EXIT_CODE=$?
35+
echo "MOBSF_EXIT=${EXIT_CODE}" >> "$GITHUB_ENV"
36+
exit 0
37+
38+
- name: Upload mobsfscan SARIF
39+
if: always() && hashFiles('results.sarif') != ''
40+
uses: github/codeql-action/upload-sarif@v3
41+
with:
42+
sarif_file: results.sarif
43+
44+
- name: Fail when mobsfscan finds issues
45+
if: ${{ env.MOBSF_EXIT != '' && env.MOBSF_EXIT != '0' }}
46+
run: |
47+
echo "mobsfscan reported security findings. Review the SARIF upload for details."
48+
exit 1

.mobsf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- ignore-paths:
3+
- build
4+
- .build
5+
- core
6+
- Gem.xcodeproj
7+
- Gem/Generated
8+
- GemTests/Fixtures
9+
- GemTests
10+
- Packages/Keystore/Tests
11+
- Packages/Keychain/Tests
12+
- Packages/Keychain/Sources/Types/Accessibility.swift
13+
- Packages/Keystore/TestKit
14+
- Packages/Gemstone
15+
- Packages/GemstonePrimitives
16+
- Packages/Primitives/Sources/Extensions/Color+Primitives.swift
17+
- Packages/Primitives/Sources/TransactionLoadMetadata.swift
18+
- swiftgen.yml
19+
severity-filter:
20+
- WARNING
21+
- ERROR

Features/FiatConnect/Sources/ViewModels/FiatTransactionTypeViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public extension FiatQuoteTypeViewModel {
3131

3232
func randomAmount(maxAmount: Double) -> Double? {
3333
switch type {
34-
case .buy: Double(Int.random(in: Int(defaultAmount)..<Int(maxAmount)))
34+
case .buy: Double(Int.random(in: Int(defaultAmount)..<Int(maxAmount))) // mobsf-ignore: ios_insecure_random_no_generator (UI suggestion only)
3535
case .sell: .none
3636
}
3737
}

Features/Onboarding/Sources/Types/WalletImportType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import Localization
77
enum WalletImportType: String, Hashable, CaseIterable, Identifiable {
88
var id: String { rawValue }
99

10-
case phrase = "Phrase"
11-
case address = "Address"
12-
case privateKey = "Private Key"
10+
case phrase
11+
case address
12+
case privateKey
1313
}
1414

1515
extension WalletImportType {

Packages/Keystore/Sources/LocalKeystorePassword.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Primitives
77

88
public final class LocalKeystorePassword: KeystorePassword {
99
private struct Keys {
10-
static let password = "password"
10+
static let password = "password" // mobsf-ignore: ios_hardcoded_secret
1111
static let passwordAuthentication = "password_authentication"
1212
static let passwordAuthenticationPeriod = "password_authentication_period"
1313
static let passwordAuthenticationPrivacyLock = "password_authentication_privacy_lock"

Packages/Style/Sources/Emoji.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public struct Emoji {
8989
case ninja = "🥷"
9090
case hacker = "👨‍💻"
9191
case vault = "🛢"
92-
case key = "🔑"
92+
case keyEmoji = "🔑"
9393
case shield = "🛡"
9494
case upChart = "📈"
9595
case downChart = "📉"

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ If you want to contribute, you can use our [developers telegram](https://t.me/ge
6868

6969
If you're using a legacy Intel Mac, you need to pull latest `core` submodule and run `just generate-stone` to build `x86_64` arch Gemstone, the core library used by Gem iOS.
7070

71+
## 🔐 Security Scanning
72+
73+
We run [MobSF mobsfscan](https://github.com/MobSF/mobsfscan) to catch insecure patterns in Swift and Objective-C code.
74+
75+
- **Local usage**: Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) and run `uv tool install mobsfscan` once. After that, `just mobsfscan` (internally `uv tool run mobsfscan -- --type ios --config .mobsf --exit-warning`) scans the iOS source tree with the repo-wide `.mobsf` configuration and fails when it encounters `WARNING` or `ERROR` level findings.
76+
- **CI enforcement**: `.github/workflows/mobsfscan.yml` installs mobsfscan on every push/PR to `main`, uploads a SARIF report to GitHub code scanning, and fails the workflow when findings remain.
77+
78+
Suppress individual findings only when you fully understand the risk—either update the code or add a `// mobsf-ignore: rule_id` inline comment with context.
79+
7180
## 👨‍👧‍👦 Contributors
7281

7382
We love contributors! Feel free to contribute to this project but please read the [Contributing Guidelines](CONTRIBUTING.md) first!

justfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ test TARGET: show-simulator
110110
-jobs {{BUILD_THREADS}} \
111111
test | xcbeautify {{XCBEAUTIFY_ARGS}}
112112

113+
mobsfscan:
114+
@command -v uv >/dev/null || { \
115+
echo "uv is not installed. Install it via 'curl -LsSf https://astral.sh/uv/install.sh | sh'."; \
116+
exit 1; }
117+
uv tool run mobsfscan -- --type ios --config .mobsf --exit-warning
118+
113119
localize:
114120
@sh core/scripts/localize.sh ios Packages/Localization/Sources/Resources
115121
just generate-model
@@ -133,4 +139,4 @@ generate-stone:
133139
bump-version:
134140
@sh ./scripts/bump-version-and-commit.sh patch
135141

136-
mod core
142+
mod core

0 commit comments

Comments
 (0)