android-skills 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -58
- package/android-ui/SKILL.md +187 -0
- package/android-ui/references/anti-slop-checklist.md +61 -0
- package/android-ui/references/checklist.md +95 -0
- package/android-ui/references/clarifying-questions.md +55 -0
- package/android-ui/references/color-and-contrast.md +104 -0
- package/android-ui/references/components-intents.md +74 -0
- package/android-ui/references/compose-patterns.md +120 -0
- package/android-ui/references/compose-risks.md +86 -0
- package/android-ui/references/input-and-state.md +77 -0
- package/android-ui/references/network-storage.md +87 -0
- package/android-ui/references/reconstruction-workflow.md +74 -0
- package/android-ui/references/report-template.md +71 -0
- package/android-ui/references/sensitive-data-ui.md +73 -0
- package/android-ui/references/typography-spacing.md +93 -0
- package/android-ui/references/webview.md +105 -0
- package/{android-ui-minimal → android-ui}/scripts/contrast.py +8 -8
- package/{android-ui-minimal → android-ui}/scripts/gen_tokens.py +11 -11
- package/{android-ui-minimal → android-ui}/scripts/lint_ui.py +29 -29
- package/{android-ui-security-review → android-ui}/scripts/scan.py +146 -146
- package/bin/android-skills.js +10 -10
- package/install.py +79 -65
- package/opencode/commands/ui.md +13 -0
- package/package.json +3 -4
- package/android-ui-minimal/SKILL.md +0 -98
- package/android-ui-minimal/references/anti-slop-checklist.md +0 -61
- package/android-ui-minimal/references/clarifying-questions.md +0 -55
- package/android-ui-minimal/references/color-and-contrast.md +0 -104
- package/android-ui-minimal/references/compose-patterns.md +0 -120
- package/android-ui-minimal/references/reconstruction-workflow.md +0 -74
- package/android-ui-minimal/references/typography-spacing.md +0 -93
- package/android-ui-security-review/SKILL.md +0 -93
- package/android-ui-security-review/references/checklist.md +0 -95
- package/android-ui-security-review/references/components-intents.md +0 -74
- package/android-ui-security-review/references/compose-risks.md +0 -86
- package/android-ui-security-review/references/input-and-state.md +0 -77
- package/android-ui-security-review/references/network-storage.md +0 -87
- package/android-ui-security-review/references/report-template.md +0 -71
- package/android-ui-security-review/references/sensitive-data-ui.md +0 -73
- package/android-ui-security-review/references/webview.md +0 -105
- package/opencode/commands/ui-minimal.md +0 -9
- package/opencode/commands/ui-security.md +0 -9
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
2
|
+
"""Static scanner for Android frontend/UI security risks (Kotlin, Java, XML, Manifest).
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
This is a pattern-based scanner, not data-flow analysis. Every finding must
|
|
5
|
+
be verified manually. Rule IDs match references/checklist.md.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Usage:
|
|
8
8
|
python3 scan.py <path> [--format text|md|json] [--out FILE]
|
|
9
9
|
[--min-severity info|low|medium|high|critical]
|
|
10
10
|
[--fail-on high] [--include-tests]
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
(
|
|
14
|
-
|
|
12
|
+
Suppress a finding with a comment (reason required): // sec-ignore: RULE_ID reason
|
|
13
|
+
(in AndroidManifest.xml: <!-- sec-ignore: RULE_ID reason -->, directly above the element)
|
|
14
|
+
Exit code: 1 if any finding >= --fail-on, else 0.
|
|
15
15
|
"""
|
|
16
16
|
import argparse
|
|
17
17
|
import json
|
|
@@ -43,131 +43,131 @@ class Rule:
|
|
|
43
43
|
I = re.I
|
|
44
44
|
RULES = [
|
|
45
45
|
# WebView
|
|
46
|
-
Rule("W-JS", "medium", "JavaScript
|
|
46
|
+
Rule("W-JS", "medium", "JavaScript enabled in WebView",
|
|
47
47
|
r"setJavaScriptEnabled\(\s*true\s*\)|javaScriptEnabled\s*=\s*true",
|
|
48
|
-
"
|
|
48
|
+
"Enable only when needed and only for trusted content. Restrict the origins loaded."),
|
|
49
49
|
Rule("W-INTERFACE", "high", "addJavascriptInterface",
|
|
50
50
|
r"addJavascriptInterface\(",
|
|
51
|
-
"
|
|
52
|
-
Rule("W-FILE", "high", "
|
|
51
|
+
"Only for trusted local content. Annotate a minimal set of methods with @JavascriptInterface, or use a WebMessageListener with allowedOriginRules."),
|
|
52
|
+
Rule("W-FILE", "high", "WebView file access too loose",
|
|
53
53
|
r"(setAllowUniversalAccessFromFileURLs|setAllowFileAccessFromFileURLs)\(\s*true|allow(UniversalAccessFromFileURLs|FileAccessFromFileURLs)\s*=\s*true",
|
|
54
|
-
"
|
|
55
|
-
Rule("W-FILE2", "medium", "allowFileAccess
|
|
54
|
+
"Disable. Load local assets through WebViewAssetLoader."),
|
|
55
|
+
Rule("W-FILE2", "medium", "allowFileAccess enabled",
|
|
56
56
|
r"setAllowFileAccess\(\s*true|allowFileAccess\s*=\s*true",
|
|
57
|
-
"
|
|
58
|
-
Rule("W-CONTENT", "medium", "allowContentAccess
|
|
57
|
+
"Turn off, or use WebViewAssetLoader."),
|
|
58
|
+
Rule("W-CONTENT", "medium", "allowContentAccess enabled",
|
|
59
59
|
r"setAllowContentAccess\(\s*true|allowContentAccess\s*=\s*true",
|
|
60
|
-
"
|
|
61
|
-
Rule("W-MIXED", "high", "Mixed content
|
|
62
|
-
r"MIXED_CONTENT_ALWAYS_ALLOW", "
|
|
63
|
-
Rule("W-DEBUG", "medium", "WebView debugging
|
|
60
|
+
"Turn off unless content providers are needed."),
|
|
61
|
+
Rule("W-MIXED", "high", "Mixed content allowed",
|
|
62
|
+
r"MIXED_CONTENT_ALWAYS_ALLOW", "Use MIXED_CONTENT_NEVER_ALLOW and HTTPS only."),
|
|
63
|
+
Rule("W-DEBUG", "medium", "WebView debugging enabled",
|
|
64
64
|
r"setWebContentsDebuggingEnabled\(\s*true",
|
|
65
|
-
"
|
|
66
|
-
Rule("W-LOADURL-HTTP", "high", "WebView
|
|
67
|
-
r"(loadUrl|loadDataWithBaseURL)\(\s*\"http://", "
|
|
68
|
-
Rule("W-LOADURL-DYN", "low", "loadUrl
|
|
69
|
-
r"\.loadUrl\(\s*[^\"\s)]", "
|
|
65
|
+
"Guard with BuildConfig.DEBUG or (applicationInfo.flags and FLAG_DEBUGGABLE)."),
|
|
66
|
+
Rule("W-LOADURL-HTTP", "high", "WebView loads an http URL",
|
|
67
|
+
r"(loadUrl|loadDataWithBaseURL)\(\s*\"http://", "Use HTTPS."),
|
|
68
|
+
Rule("W-LOADURL-DYN", "low", "loadUrl with a dynamic value",
|
|
69
|
+
r"\.loadUrl\(\s*[^\"\s)]", "Make sure the URL is validated against a scheme and host allowlist before loading.",
|
|
70
70
|
neg=r"javascript:", conf="low"),
|
|
71
|
-
Rule("W-LOADDATA", "medium", "loadData
|
|
71
|
+
Rule("W-LOADDATA", "medium", "loadData with interpolation",
|
|
72
72
|
r"(loadData|loadDataWithBaseURL)\(.*(\$\{?\w|\+\s*\w)",
|
|
73
|
-
"Escape
|
|
74
|
-
Rule("W-EVALJS", "medium", "evaluateJavascript
|
|
73
|
+
"Escape, or avoid interpolating untrusted data into HTML."),
|
|
74
|
+
Rule("W-EVALJS", "medium", "evaluateJavascript with interpolation",
|
|
75
75
|
r"evaluateJavascript\(.*(\$\{?\w|\"\s*\+|\+\s*\")",
|
|
76
|
-
"
|
|
77
|
-
Rule("W-SSL", "critical", "
|
|
78
|
-
r"onReceivedSslError", "
|
|
76
|
+
"Send data via escaped JSON or postWebMessage, do not build strings."),
|
|
77
|
+
Rule("W-SSL", "critical", "SSL error ignored in WebView",
|
|
78
|
+
r"onReceivedSslError", "Do not call handler.proceed(). Call cancel().",
|
|
79
79
|
need=r"\.proceed\(\)", window=6),
|
|
80
|
-
#
|
|
81
|
-
Rule("C-REDIRECT", "medium", "
|
|
80
|
+
# Components and intents
|
|
81
|
+
Rule("C-REDIRECT", "medium", "Possible intent redirection",
|
|
82
82
|
r"getParcelableExtra(<Intent>)?\(|getParcelable(<Intent>)?\(.*Intent",
|
|
83
|
-
"
|
|
83
|
+
"Do not launch an Intent received from outside. Validate the target component and strip URI permission flags.",
|
|
84
84
|
need=r"Intent", conf="low"),
|
|
85
|
-
Rule("C-PENDING", "high", "PendingIntent
|
|
85
|
+
Rule("C-PENDING", "high", "PendingIntent without a mutability flag",
|
|
86
86
|
r"PendingIntent\.get(Activity|Broadcast|Service|Activities|ForegroundService)\(",
|
|
87
|
-
"
|
|
87
|
+
"Add FLAG_IMMUTABLE (or FLAG_MUTABLE only when truly needed) and an explicit Intent.",
|
|
88
88
|
neg=r"FLAG_IMMUTABLE|FLAG_MUTABLE", window=3),
|
|
89
|
-
Rule("C-RECEIVER", "medium", "registerReceiver
|
|
90
|
-
r"registerReceiver\(", "
|
|
89
|
+
Rule("C-RECEIVER", "medium", "registerReceiver without an export flag",
|
|
90
|
+
r"registerReceiver\(", "On Android 13+ set RECEIVER_NOT_EXPORTED unless it is meant for other apps.",
|
|
91
91
|
neg=r"RECEIVER_NOT_EXPORTED|RECEIVER_EXPORTED", window=2),
|
|
92
|
-
Rule("C-BROADCAST", "low", "sendBroadcast
|
|
93
|
-
r"sendBroadcast\(", "
|
|
92
|
+
Rule("C-BROADCAST", "low", "sendBroadcast without a receiver limit",
|
|
93
|
+
r"sendBroadcast\(", "Use setPackage or a receiver permission so data does not leak to other apps.",
|
|
94
94
|
neg=r"setPackage|permission|Permission", window=2, conf="low"),
|
|
95
|
-
Rule("C-IMPLICIT", "medium", "startActivity
|
|
95
|
+
Rule("C-IMPLICIT", "medium", "startActivity with an implicit Intent from dynamic data",
|
|
96
96
|
r"Intent\(\s*Intent\.ACTION_VIEW\s*,\s*Uri\.parse\(\s*[^\"\s)]",
|
|
97
|
-
"
|
|
98
|
-
Rule("C-FILEPROVIDER", "high", "FileProvider
|
|
99
|
-
r"<root-path|<external-path\s+[^>]*path=\"\.?/?\"", "
|
|
100
|
-
#
|
|
101
|
-
Rule("U-LOG", "high", "
|
|
97
|
+
"Validate the Uri scheme and host before opening. Handle ActivityNotFoundException.", conf="low"),
|
|
98
|
+
Rule("C-FILEPROVIDER", "high", "FileProvider opens a root path",
|
|
99
|
+
r"<root-path|<external-path\s+[^>]*path=\"\.?/?\"", "Restrict FileProvider paths to a specific subfolder.", kinds="xml"),
|
|
100
|
+
# Sensitive data in the UI
|
|
101
|
+
Rule("U-LOG", "high", "Sensitive data written to logs",
|
|
102
102
|
r"(Log\.[dviwe]|Timber\.[dviwe]|println)\s*\(.*" + SENS,
|
|
103
|
-
"
|
|
104
|
-
Rule("U-STACKTRACE", "low", "printStackTrace
|
|
103
|
+
"Remove the log or do not include sensitive values. Make sure debug logging is stripped in release.", flags=I),
|
|
104
|
+
Rule("U-STACKTRACE", "low", "printStackTrace and exception messages to the UI",
|
|
105
105
|
r"printStackTrace\(\)|Toast\.makeText\(.*(\.message|\.localizedMessage|\.toString\(\))",
|
|
106
|
-
"Log
|
|
107
|
-
Rule("U-CLIPBOARD", "medium", "
|
|
106
|
+
"Log concisely via a logger disabled in release. Show a generic message to the user."),
|
|
107
|
+
Rule("U-CLIPBOARD", "medium", "Sensitive data copied to the clipboard",
|
|
108
108
|
r"(setPrimaryClip|ClipData\.newPlainText)\(.*" + SENS,
|
|
109
|
-
"
|
|
110
|
-
Rule("U-SAVEABLE", "medium", "
|
|
109
|
+
"Avoid copying sensitive data. If needed, mark ClipDescription.EXTRA_IS_SENSITIVE and clear it automatically.", flags=I),
|
|
110
|
+
Rule("U-SAVEABLE", "medium", "Sensitive data stored in rememberSaveable",
|
|
111
111
|
r"(rememberSaveable.*" + SENS + r"|" + SENS + r".*rememberSaveable)",
|
|
112
|
-
"State
|
|
113
|
-
Rule("U-PWFIELD", "medium", "
|
|
114
|
-
r"\b(Outlined)?(Basic)?TextField\(", "
|
|
112
|
+
"State is persisted to the Bundle and can survive process death. Use plain remember for secrets.", flags=I),
|
|
113
|
+
Rule("U-PWFIELD", "medium", "Password field without transformation or keyboard type",
|
|
114
|
+
r"\b(Outlined)?(Basic)?TextField\(", "Use PasswordVisualTransformation and KeyboardType.Password. Consider a temporary show toggle.",
|
|
115
115
|
need=r"password|passwd|kata sandi", neg=r"PasswordVisualTransformation|KeyboardType\.(Password|NumberPassword)",
|
|
116
116
|
window=25, flags=I),
|
|
117
|
-
Rule("U-INPUTTYPE", "medium", "EditText
|
|
118
|
-
r"<EditText|<com\.google\.android\.material\.textfield\.TextInputEditText", "Set android:inputType=\"textPassword\"
|
|
117
|
+
Rule("U-INPUTTYPE", "medium", "Sensitive EditText without a password inputType",
|
|
118
|
+
r"<EditText|<com\.google\.android\.material\.textfield\.TextInputEditText", "Set android:inputType=\"textPassword\" for secret fields.",
|
|
119
119
|
kinds="xml", need=r"password|pin|otp", neg=r"inputType=\"[^\"]*(Password|numberPassword)", window=8, flags=I, conf="low"),
|
|
120
|
-
Rule("U-AUTOFILL", "info", "AutoFill
|
|
121
|
-
r"importantForAutofill\s*=\s*\"yes\"", "
|
|
122
|
-
#
|
|
123
|
-
Rule("S-SECRET", "high", "
|
|
120
|
+
Rule("U-AUTOFILL", "info", "AutoFill enabled manually",
|
|
121
|
+
r"importantForAutofill\s*=\s*\"yes\"", "Make sure sensitive fields do not send data to an unwanted third-party autofill service.", kinds="xml"),
|
|
122
|
+
# Secrets
|
|
123
|
+
Rule("S-SECRET", "high", "Hardcoded secret",
|
|
124
124
|
r"(api[_-]?key|secret|passwd|password|token|bearer|client[_-]?secret)\w*\s*(=|:)\s*\"(?=[A-Za-z_\-/+=.]*\d)(?=[0-9_\-/+=.]*[A-Za-z])[A-Za-z0-9_\-/+=.]{16,}\"",
|
|
125
|
-
"
|
|
125
|
+
"Do not store secrets in the APK. Move them to the backend or a proxy. Rotate any key that was already committed.",
|
|
126
126
|
kinds="all", neg=r"BuildConfig|R\.string|getString|stringResource|example|your_|changeme|xxxx", flags=I, conf="low"),
|
|
127
|
-
Rule("S-PRIVKEY", "critical", "
|
|
128
|
-
r"-----BEGIN (RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----", "
|
|
129
|
-
Rule("S-AWS", "critical", "
|
|
130
|
-
r"\bAKIA[0-9A-Z]{16}\b", "
|
|
131
|
-
Rule("S-GOOGLEKEY", "medium", "API key
|
|
132
|
-
r"\bAIza[0-9A-Za-z_\-]{35}\b", "
|
|
133
|
-
Rule("S-TOKENFMT", "high", "Token
|
|
134
|
-
r"\b(ghp_[A-Za-z0-9]{36}|xox[baprs]-[A-Za-z0-9-]{10,}|sk-[A-Za-z0-9]{32,})\b", "
|
|
135
|
-
#
|
|
136
|
-
Rule("S-PREFS", "medium", "
|
|
137
|
-
r"(putString|edit\(\).*put\w+)\(\s*\"[^\"]*" + SENS, "
|
|
138
|
-
Rule("S-WORLD", "high", "
|
|
139
|
-
r"MODE_WORLD_(READABLE|WRITEABLE)", "
|
|
140
|
-
Rule("S-EXTERNAL", "low", "
|
|
141
|
-
r"getExternalStorageDirectory\(|Environment\.getExternalStorage", "
|
|
142
|
-
#
|
|
143
|
-
Rule("N-HTTP", "medium", "URL
|
|
144
|
-
r"\"http://(?!localhost|127\.0\.0\.1|10\.0\.2\.2|schemas\.android\.com|www\.w3\.org|schemas\.microsoft)", "
|
|
145
|
-
Rule("N-HOSTNAME", "critical", "HostnameVerifier
|
|
127
|
+
Rule("S-PRIVKEY", "critical", "Private key in source",
|
|
128
|
+
r"-----BEGIN (RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----", "Remove from the repo, rotate, and clean git history.", kinds="all"),
|
|
129
|
+
Rule("S-AWS", "critical", "AWS access key",
|
|
130
|
+
r"\bAKIA[0-9A-Z]{16}\b", "Revoke and rotate immediately.", kinds="all"),
|
|
131
|
+
Rule("S-GOOGLEKEY", "medium", "Google API key in source",
|
|
132
|
+
r"\bAIza[0-9A-Za-z_\-]{35}\b", "Restrict the key in the console (package name + SHA-1, API allowlist). Do not use an unrestricted key.", kinds="all"),
|
|
133
|
+
Rule("S-TOKENFMT", "high", "Token in a known format",
|
|
134
|
+
r"\b(ghp_[A-Za-z0-9]{36}|xox[baprs]-[A-Za-z0-9-]{10,}|sk-[A-Za-z0-9]{32,})\b", "Revoke and rotate.", kinds="all"),
|
|
135
|
+
# Storage
|
|
136
|
+
Rule("S-PREFS", "medium", "Sensitive data in plain SharedPreferences",
|
|
137
|
+
r"(putString|edit\(\).*put\w+)\(\s*\"[^\"]*" + SENS, "Store secrets with Android Keystore-backed encryption (check the current recommendation for the encryption library in use).", flags=I),
|
|
138
|
+
Rule("S-WORLD", "high", "World-readable/writable file mode",
|
|
139
|
+
r"MODE_WORLD_(READABLE|WRITEABLE)", "Use MODE_PRIVATE."),
|
|
140
|
+
Rule("S-EXTERNAL", "low", "External storage",
|
|
141
|
+
r"getExternalStorageDirectory\(|Environment\.getExternalStorage", "Do not store sensitive data on external storage. Use the app's private storage."),
|
|
142
|
+
# Network
|
|
143
|
+
Rule("N-HTTP", "medium", "http URL (cleartext)",
|
|
144
|
+
r"\"http://(?!localhost|127\.0\.0\.1|10\.0\.2\.2|schemas\.android\.com|www\.w3\.org|schemas\.microsoft)", "Use HTTPS.", kinds="all"),
|
|
145
|
+
Rule("N-HOSTNAME", "critical", "HostnameVerifier accepts everything",
|
|
146
146
|
r"ALLOW_ALL_HOSTNAME_VERIFIER|HostnameVerifier\s*\{[^}]*\btrue\b|hostnameVerifier\s*\{\s*_\s*,\s*_\s*->\s*true",
|
|
147
|
-
"
|
|
148
|
-
Rule("N-TRUSTALL", "critical", "TrustManager
|
|
149
|
-
r"object\s*:\s*X509TrustManager|implements\s+X509TrustManager|new\s+X509TrustManager", "
|
|
147
|
+
"Remove. Use the default verification."),
|
|
148
|
+
Rule("N-TRUSTALL", "critical", "TrustManager accepts everything",
|
|
149
|
+
r"object\s*:\s*X509TrustManager|implements\s+X509TrustManager|new\s+X509TrustManager", "Do not implement a custom TrustManager that bypasses validation. Use network_security_config or CertificatePinner.",
|
|
150
150
|
need=r"checkServerTrusted\s*\([^)]*\)\s*(:\s*\w+\s*)?\{\s*(//[^\n]*\n\s*)*\}", window=12),
|
|
151
|
-
Rule("N-PINNING", "info", "OkHttp
|
|
152
|
-
r"OkHttpClient\.Builder\(\)", "
|
|
151
|
+
Rule("N-PINNING", "info", "OkHttp without a CertificatePinner (check manually)",
|
|
152
|
+
r"OkHttpClient\.Builder\(\)", "For high-risk apps, consider certificate pinning with a rotation strategy.",
|
|
153
153
|
neg=r"certificatePinner|CertificatePinner", window=15, conf="low"),
|
|
154
|
-
#
|
|
155
|
-
Rule("I-SQL", "high", "SQL
|
|
156
|
-
r"(rawQuery|execSQL|SimpleSQLiteQuery)\(.*(\+\s*\w|\$\{?\w)", "
|
|
157
|
-
Rule("I-PATH", "medium", "
|
|
158
|
-
r"File\(.*(getStringExtra|getQueryParameter|lastPathSegment|\.path\b|getString\()",
|
|
159
|
-
"
|
|
160
|
-
Rule("I-DEEPLINK", "info", "
|
|
161
|
-
r"getQueryParameter\(|intent\??\.data\b|intent\??\.getStringExtra\(", "
|
|
162
|
-
Rule("I-HTML", "low", "Html.fromHtml
|
|
163
|
-
r"Html\.fromHtml\(\s*[^\"\s)]", "
|
|
164
|
-
Rule("I-RANDOM", "medium", "Random
|
|
165
|
-
r"\bjava\.util\.Random\(|\bRandom\(\)|Math\.random\(\)", "
|
|
154
|
+
# Inputs and injection
|
|
155
|
+
Rule("I-SQL", "high", "SQL built from strings",
|
|
156
|
+
r"(rawQuery|execSQL|SimpleSQLiteQuery)\(.*(\+\s*\w|\$\{?\w)", "Use parameter binding (?) or Room with a parameterized @Query."),
|
|
157
|
+
Rule("I-PATH", "medium", "File path from external input",
|
|
158
|
+
r"File\(.*( getStringExtra|getQueryParameter|lastPathSegment|\.path\b|getString\()",
|
|
159
|
+
"Normalize with canonicalPath and make sure it stays inside an allowed directory. Reject '..'.", conf="low"),
|
|
160
|
+
Rule("I-DEEPLINK", "info", "Deep link parameter used",
|
|
161
|
+
r"getQueryParameter\(|intent\??\.data\b|intent\??\.getStringExtra\(", "Validate type, length, and value. Do not use it directly for navigation or queries.", conf="low"),
|
|
162
|
+
Rule("I-HTML", "low", "Html.fromHtml from dynamic data",
|
|
163
|
+
r"Html\.fromHtml\(\s*[^\"\s)]", "Make sure the source is trusted. Avoid rendering HTML from user input.", conf="low"),
|
|
164
|
+
Rule("I-RANDOM", "medium", "Non-crypto Random for security values",
|
|
165
|
+
r"\bjava\.util\.Random\(|\bRandom\(\)|Math\.random\(\)", "Use SecureRandom for tokens, OTPs, nonces.",
|
|
166
166
|
need=r"token|otp|session|password|nonce|key", window=3, flags=I),
|
|
167
|
-
Rule("I-HASH", "medium", "
|
|
168
|
-
r"MessageDigest\.getInstance\(\s*\"(MD5|SHA-?1)\"\s*\)", "
|
|
169
|
-
Rule("I-CIPHER", "high", "
|
|
170
|
-
r"Cipher\.getInstance\(\s*\"(AES|DES|DESede|RC4|Blowfish)(/ECB/\w+)?\"\s*\)", "
|
|
167
|
+
Rule("I-HASH", "medium", "Weak hash",
|
|
168
|
+
r"MessageDigest\.getInstance\(\s*\"(MD5|SHA-?1)\"\s*\)", "Use SHA-256 or stronger. For passwords use a server-side KDF."),
|
|
169
|
+
Rule("I-CIPHER", "high", "Weak cipher or ECB mode",
|
|
170
|
+
r"Cipher\.getInstance\(\s*\"(AES|DES|DESede|RC4|Blowfish)(/ECB/\w+)?\"\s*\)", "Use AES/GCM/NoPadding with a random IV per message."),
|
|
171
171
|
]
|
|
172
172
|
|
|
173
173
|
PROJECT_NOTES = []
|
|
@@ -235,7 +235,7 @@ def scan_manifest(path, text, findings):
|
|
|
235
235
|
return
|
|
236
236
|
if is_debug_path(path) and sev in ("high", "medium"):
|
|
237
237
|
sev = "info"
|
|
238
|
-
title += " (source set
|
|
238
|
+
title += " (debug source set)"
|
|
239
239
|
findings.append(dict(rule=rid, severity=sev, title=title, file=path, line=ln,
|
|
240
240
|
snippet=needle[:160], advice=advice, confidence=conf))
|
|
241
241
|
|
|
@@ -246,12 +246,12 @@ def scan_manifest(path, text, findings):
|
|
|
246
246
|
app = root.find("application")
|
|
247
247
|
if app is not None:
|
|
248
248
|
if app.get(ANDROID_NS + "debuggable") == "true":
|
|
249
|
-
add("M-DEBUGGABLE", "high", "debuggable=true", "android:debuggable", "
|
|
249
|
+
add("M-DEBUGGABLE", "high", "debuggable=true", "android:debuggable", "Remove the attribute. Let the build type decide.")
|
|
250
250
|
if app.get(ANDROID_NS + "allowBackup") == "true":
|
|
251
251
|
add("M-BACKUP", "medium", "allowBackup=true", "android:allowBackup",
|
|
252
|
-
"Set false
|
|
252
|
+
"Set false, or define dataExtractionRules and fullBackupContent that exclude sensitive data.")
|
|
253
253
|
if app.get(ANDROID_NS + "usesCleartextTraffic") == "true":
|
|
254
|
-
add("M-CLEARTEXT", "high", "usesCleartextTraffic=true", "android:usesCleartextTraffic", "Set false
|
|
254
|
+
add("M-CLEARTEXT", "high", "usesCleartextTraffic=true", "android:usesCleartextTraffic", "Set false and use HTTPS.")
|
|
255
255
|
for comp in app:
|
|
256
256
|
tag = comp.tag
|
|
257
257
|
if tag not in ("activity", "activity-alias", "service", "receiver", "provider"):
|
|
@@ -263,22 +263,22 @@ def scan_manifest(path, text, findings):
|
|
|
263
263
|
launcher = any(c.get(ANDROID_NS + "name") == "android.intent.category.LAUNCHER"
|
|
264
264
|
for f in filters for c in f.findall("category"))
|
|
265
265
|
if filters and exported is None:
|
|
266
|
-
add("M-EXPORT-IMPLICIT", "high", f"{tag}
|
|
267
|
-
"Android 12+
|
|
266
|
+
add("M-EXPORT-IMPLICIT", "high", f"{tag} with an intent-filter and no android:exported ({name})", name,
|
|
267
|
+
"Android 12+ requires the attribute explicitly. Set true only if it is meant for other apps.")
|
|
268
268
|
if exported == "true" and not launcher:
|
|
269
269
|
if tag == "activity" or tag == "activity-alias":
|
|
270
|
-
add("M-EXPORT", "medium", f"
|
|
271
|
-
"
|
|
270
|
+
add("M-EXPORT", "medium", f"Exported activity ({name})", name,
|
|
271
|
+
"Validate all intent extras and data. Consider a permission or exported=false.", "medium")
|
|
272
272
|
elif not perm and tag != "provider":
|
|
273
|
-
add("M-EXPORT", "high", f"{tag} exported
|
|
274
|
-
"Set exported=false
|
|
273
|
+
add("M-EXPORT", "high", f"{tag} exported without a permission ({name})", name,
|
|
274
|
+
"Set exported=false or protect it with a signature-level permission.")
|
|
275
275
|
if tag == "provider":
|
|
276
276
|
if exported == "true":
|
|
277
|
-
add("M-PROVIDER", "high", f"ContentProvider
|
|
278
|
-
"Set exported=false,
|
|
277
|
+
add("M-PROVIDER", "high", f"Exported ContentProvider ({name})", name,
|
|
278
|
+
"Set exported=false, or protect it with readPermission/writePermission and restrict the paths.")
|
|
279
279
|
if comp.get(ANDROID_NS + "grantUriPermissions") == "true":
|
|
280
280
|
add("M-GRANT", "medium", f"grantUriPermissions=true ({name})", name,
|
|
281
|
-
"
|
|
281
|
+
"Restrict with <grant-uri-permission> on specific paths.", "medium")
|
|
282
282
|
for f in filters:
|
|
283
283
|
cats = {c.get(ANDROID_NS + "name") for c in f.findall("category")}
|
|
284
284
|
datas = f.findall("data")
|
|
@@ -286,39 +286,39 @@ def scan_manifest(path, text, findings):
|
|
|
286
286
|
schemes = {d.get(ANDROID_NS + "scheme") for d in datas if d.get(ANDROID_NS + "scheme")}
|
|
287
287
|
web = bool(schemes & {"http", "https"})
|
|
288
288
|
if web and f.get(ANDROID_NS + "autoVerify") != "true":
|
|
289
|
-
add("M-APPLINK", "low", f"
|
|
290
|
-
"
|
|
289
|
+
add("M-APPLINK", "low", f"Web link without autoVerify ({name})", name,
|
|
290
|
+
"Use verified Android App Links (assetlinks.json) so it cannot be hijacked by another app.", "medium")
|
|
291
291
|
add("M-DEEPLINK", "info", f"Deep link {sorted(schemes)} ({name})", name,
|
|
292
|
-
"
|
|
292
|
+
"Treat all parameters as untrusted input.", "medium")
|
|
293
293
|
risky = {
|
|
294
|
-
"SYSTEM_ALERT_WINDOW": ("medium", "
|
|
295
|
-
"MANAGE_EXTERNAL_STORAGE": ("medium", "
|
|
296
|
-
"REQUEST_INSTALL_PACKAGES": ("low", "
|
|
297
|
-
"READ_EXTERNAL_STORAGE": ("low", "
|
|
298
|
-
"WRITE_EXTERNAL_STORAGE": ("low", "
|
|
299
|
-
"READ_SMS": ("medium", "
|
|
300
|
-
"RECEIVE_SMS": ("medium", "
|
|
294
|
+
"SYSTEM_ALERT_WINDOW": ("medium", "The overlay permission increases tapjacking and UI phishing risk."),
|
|
295
|
+
"MANAGE_EXTERNAL_STORAGE": ("medium", "All-files access. Use SAF or MediaStore."),
|
|
296
|
+
"REQUEST_INSTALL_PACKAGES": ("low", "Make sure installing packages is truly needed."),
|
|
297
|
+
"READ_EXTERNAL_STORAGE": ("low", "Consider the Photo Picker or SAF."),
|
|
298
|
+
"WRITE_EXTERNAL_STORAGE": ("low", "Consider MediaStore or SAF."),
|
|
299
|
+
"READ_SMS": ("medium", "Use the SMS Retriever API for OTPs."),
|
|
300
|
+
"RECEIVE_SMS": ("medium", "Use the SMS Retriever API for OTPs."),
|
|
301
301
|
}
|
|
302
302
|
for up in root.findall("uses-permission"):
|
|
303
303
|
n = (up.get(ANDROID_NS + "name") or "").split(".")[-1]
|
|
304
304
|
if n in risky:
|
|
305
305
|
sev, adv = risky[n]
|
|
306
|
-
add("M-PERM", sev, f"
|
|
306
|
+
add("M-PERM", sev, f"Permission {n}", n, adv, "medium")
|
|
307
307
|
|
|
308
308
|
|
|
309
309
|
def scan_nsc(path, text, findings):
|
|
310
310
|
debug_start = text.find("<debug-overrides")
|
|
311
311
|
debug_end = text.find("</debug-overrides>")
|
|
312
312
|
for m in re.finditer(r'cleartextTrafficPermitted\s*=\s*"true"', text):
|
|
313
|
-
findings.append(dict(rule="N-NSC-CLEAR", severity="high", title="network_security_config
|
|
313
|
+
findings.append(dict(rule="N-NSC-CLEAR", severity="high", title="network_security_config allows cleartext",
|
|
314
314
|
file=path, line=text.count("\n", 0, m.start()) + 1, snippet=m.group(0),
|
|
315
|
-
advice="Set false.
|
|
315
|
+
advice="Set false. Only exclude specific dev domains in debug-overrides.", confidence="high"))
|
|
316
316
|
for m in re.finditer(r'<certificates\s+src\s*=\s*"user"', text):
|
|
317
317
|
in_debug = debug_start != -1 and debug_start < m.start() < (debug_end if debug_end != -1 else len(text))
|
|
318
318
|
findings.append(dict(rule="N-NSC-USER", severity="info" if in_debug else "medium",
|
|
319
|
-
title="
|
|
319
|
+
title="User certificate trust anchor" + (" (debug-overrides)" if in_debug else ""),
|
|
320
320
|
file=path, line=text.count("\n", 0, m.start()) + 1, snippet=m.group(0),
|
|
321
|
-
advice="
|
|
321
|
+
advice="Do not trust user CAs in release.", confidence="high"))
|
|
322
322
|
|
|
323
323
|
|
|
324
324
|
def project_checks(files_text, findings):
|
|
@@ -327,14 +327,14 @@ def project_checks(files_text, findings):
|
|
|
327
327
|
if sensitive:
|
|
328
328
|
all_text = "\n".join(files_text.values())
|
|
329
329
|
if "FLAG_SECURE" not in all_text and "setSecure" not in all_text:
|
|
330
|
-
findings.append(dict(rule="U-SECURE", severity="medium", title="
|
|
331
|
-
file=sensitive[0], line=1, snippet="(
|
|
332
|
-
advice="Set WindowManager.LayoutParams.FLAG_SECURE
|
|
330
|
+
findings.append(dict(rule="U-SECURE", severity="medium", title="Sensitive screen without FLAG_SECURE",
|
|
331
|
+
file=sensitive[0], line=1, snippet="(project level: FLAG_SECURE not found)",
|
|
332
|
+
advice="Set WindowManager.LayoutParams.FLAG_SECURE on login, OTP, PIN, and payment screens to block screenshots and the recents preview.",
|
|
333
333
|
confidence="medium"))
|
|
334
334
|
if not re.search(r"filterTouchesWhenObscured|FLAG_WINDOW_IS_OBSCURED|MotionEvent\.FLAG_WINDOW_IS_PARTIALLY_OBSCURED", all_text):
|
|
335
|
-
findings.append(dict(rule="U-TAPJACK", severity="low", title="
|
|
336
|
-
file=sensitive[0], line=1, snippet="(
|
|
337
|
-
advice="
|
|
335
|
+
findings.append(dict(rule="U-TAPJACK", severity="low", title="No tapjacking protection",
|
|
336
|
+
file=sensitive[0], line=1, snippet="(project level)",
|
|
337
|
+
advice="For sensitive action buttons, set filterTouchesWhenObscured=true (Views) or check the obscured flags on touch events in Compose.",
|
|
338
338
|
confidence="low"))
|
|
339
339
|
|
|
340
340
|
|
|
@@ -372,17 +372,17 @@ def main():
|
|
|
372
372
|
if a.format == "json":
|
|
373
373
|
body = json.dumps({"counts": counts, "files_scanned": len(files_text), "findings": findings}, indent=2, ensure_ascii=False)
|
|
374
374
|
elif a.format == "md":
|
|
375
|
-
out = ["#
|
|
376
|
-
f"
|
|
377
|
-
"|
|
|
375
|
+
out = ["# Android UI security scan report", "",
|
|
376
|
+
f"Files scanned: {len(files_text)}", "",
|
|
377
|
+
"| Severity | Count |", "|---|---|"]
|
|
378
378
|
out += [f"| {s} | {counts.get(s, 0)} |" for s in reversed(SEV)]
|
|
379
|
-
out += ["", "
|
|
379
|
+
out += ["", "This scanner is pattern-based. Verify every finding manually before drawing conclusions.", ""]
|
|
380
380
|
for f in findings:
|
|
381
381
|
out += [f"## [{f['severity'].upper()}] {f['rule']}: {f['title']}", "",
|
|
382
|
-
f"-
|
|
383
|
-
f"-
|
|
384
|
-
f"-
|
|
385
|
-
f"-
|
|
382
|
+
f"- Location: `{f['file']}:{f['line']}`",
|
|
383
|
+
f"- Confidence: {f['confidence']}",
|
|
384
|
+
f"- Snippet: `{f['snippet']}`",
|
|
385
|
+
f"- Fix: {f['advice']}", ""]
|
|
386
386
|
body = "\n".join(out)
|
|
387
387
|
else:
|
|
388
388
|
out = []
|
|
@@ -392,14 +392,14 @@ def main():
|
|
|
392
392
|
out.append(f" > {f['snippet']}")
|
|
393
393
|
out.append(f" -> {f['advice']}")
|
|
394
394
|
out.append("")
|
|
395
|
-
out.append("
|
|
396
|
-
+ f" |
|
|
395
|
+
out.append("Summary: " + ", ".join(f"{counts.get(s, 0)} {s}" for s in reversed(SEV))
|
|
396
|
+
+ f" | files scanned: {len(files_text)}")
|
|
397
397
|
body = "\n".join(out)
|
|
398
398
|
|
|
399
399
|
if a.out:
|
|
400
400
|
with open(a.out, "w", encoding="utf-8") as fh:
|
|
401
401
|
fh.write(body + "\n")
|
|
402
|
-
print(f"
|
|
402
|
+
print(f"Report written to {a.out} ({len(findings)} findings)")
|
|
403
403
|
else:
|
|
404
404
|
print(body)
|
|
405
405
|
|
package/bin/android-skills.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* npx wrapper for android-skills.
|
|
5
|
+
* Runs install.py with the same arguments.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Examples:
|
|
8
8
|
* npx tamvanpr/android-skills --target claude --project .
|
|
9
9
|
* npx tamvanpr/android-skills --target cursor
|
|
10
10
|
* npm i -g android-skills && android-skills --help
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Note: the installer is written in Python (requires python3 on the machine).
|
|
13
|
+
* If python3 is missing, an installation message is shown.
|
|
14
14
|
*/
|
|
15
15
|
const { spawnSync } = require("child_process");
|
|
16
16
|
const fs = require("fs");
|
|
@@ -27,18 +27,18 @@ function findPython() {
|
|
|
27
27
|
const py = findPython();
|
|
28
28
|
if (!py) {
|
|
29
29
|
console.error(
|
|
30
|
-
"python3
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"python3 not found in PATH.\n" +
|
|
31
|
+
"The android-skills installer is written in Python.\n" +
|
|
32
|
+
"Options:\n" +
|
|
33
33
|
" 1) Install Python: pkg install python / apt install python3 / winget install Python.Python.3.12\n" +
|
|
34
|
-
" 2)
|
|
34
|
+
" 2) Or clone the repo directly: git clone https://github.com/tamvanpr/android-skills && python3 install.py --help"
|
|
35
35
|
);
|
|
36
36
|
process.exit(1);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const script = path.join(__dirname, "..", "install.py");
|
|
40
40
|
if (!fs.existsSync(script)) {
|
|
41
|
-
console.error("install.py
|
|
41
|
+
console.error("install.py not found at " + script);
|
|
42
42
|
process.exit(1);
|
|
43
43
|
}
|
|
44
44
|
|