Ashrafiucse android code security

From jiayaoqijia/cryptoskill · View interactive version

Ashrafiucse android code security is an AI agent skill from the GitHub repository jiayaoqijia/cryptoskill. Audits native Android app code in Kotlin AND Java — tokens outside EncryptedSharedPreferences/Keystore, local SQLi via execSQL/rawQuery interpolation, TLS bypass in code (empty X509TrustManager, always-true HostnameVerifier, OkHttp trust-all), WebView @JavascriptInterface methods reaching sensitive

How to use this skill

Skill file

Android Code Security (Kotlin + Java)

App-code shapes for native Android. The manifest/platform half (exported

components, allowBackup, cleartext policy, network security config) stays

with ../mobile-security/SKILL.md — run both; this skill owns what lives in

app/src/main/**. Sibling: ../flutter-security/SKILL.md (same classes,

Dart shapes).

Kotlin and Java share every platform API — most rules fire on both with one

grep; the divergent shapes (lambdas vs anonymous classes, string templates vs

concatenation) get their own pattern lines below.

Step 0 — Detect

rg --files -g 'build.gradle*' -g '*.kt' -g '*.java' | head -5
rg -n "com.android.application" -g 'build.gradle*'
rg --files -g 'google-services.json'

Record: security-crypto (EncryptedSharedPreferences) present? OkHttp/Retrofit?

WebView? Kotlin-only or mixed with Java legacy files?

Step 1 — Storage census (persona: device thief / rooted / adb backup)

rg -n "getSharedPreferences\(" -g '*.kt' -g '*.java' app/src/
rg -n "writeText\(|FileOutputStream\(" -g '*.kt' -g '*.java' app/src/
rg -n "SQLiteOpenHelper|execSQL\(|rawQuery\(" -g '*.kt' -g '*.java' app/src/

Census discipline: every hit dispositioned (credential-class → finding;

theme/flags → verified-safe). Credential-class = tokens, keys, passwords,

PII. Plaintext SharedPreferences is world-readable to anything with the

device/userdata. Safe shape: EncryptedSharedPreferences.create(...) with a

MasterKey — presence alone doesn't clean a hit of getSharedPreferences

on a DIFFERENT name; check which store the token write targets.

Step 2 — Local SQLi (the app's own DB)

rg -n 'execSQL\(.*\$' -g '*.kt' app/src/        # Kotlin string templates
rg -n 'execSQL\(.*\+' -g '*.kt' -g '*.java' app/src/   # concatenation (both langs)
rg -n 'rawQuery\(.*(\$|\+)' -g '*.kt' -g '*.java' app/src/

Interpolated/concatenated values = injection; the local DB often mirrors

server data and is readable by backups. Safe: bind args —

execSQL(sql, arrayOf(v)), rawQuery(sql, selectionArgs). Note: SQL

literals legitimately contain parens (VALUES (?), WHERE (a AND b)) —

the vuln signal is $/+ reaching the statement, not parens. Trace the

value: deeplink/intent-controlled input raises severity (other-app persona).

Step 3 — TLS bypass in code

rg -n 'checkServerTrusted[^{]*\{\}' -g '*.kt' -g '*.java' app/src/
rg -n 'HostnameVerifier\s*\{[^}]*true' -g '*.kt' app/src/
rg -n -A1 "boolean verify" -g '*.java' app/src/   # Java twin is TWO lines: signature, then `return true;`
rg -n "http://" -g '*.kt' -g '*.java' app/src/

anonymous class) → Critical when wired into a client (look for

sslSocketFactory(...) nearby). The empty method IS the trust kill.

localhost/test-config is the common safe near-miss — disposition it.

Step 4 — WebView bridge depth

rg -n "addJavascriptInterface|@JavascriptInterface" -g '*.kt' -g '*.java' app/src/
rg -n "loadUrl\((url|target|[a-z]+Url)" -g '*.kt' -g '*.java' app/src/
rg -n "javaScriptEnabled = true|setJavaScriptEnabled\(true\)" -g '*.kt' -g '*.java' app/src/

../mobile-security/SKILL.md flags bridge existence from the manifest side;

HERE you open every @JavascriptInterface method body: file reads, payment,

token access, intent launching → Critical when the URL is external

(deeplink/intent-sourced). loadUrl( with a constant https string is the

safe near-miss; a variable is the vuln shape.

Step 5 — Intent & deep-link flow (persona: any other app on the device)

rg -n "getStringExtra\(|getData\(|getParcelableExtra\(" -g '*.kt' -g '*.java' app/src/
rg -n "Class\.forName|setComponent\(|setPackage\(" -g '*.kt' -g '*.java' app/src/
rg -n "PendingIntent\.getActivity\(" -g '*.kt' -g '*.java' app/src/

app instantiates any class another app names (private activities,

side-effectful receivers) → High.

pending intent → High (hijack/rewrite by other apps pre-12 semantics).

Safe: PendingIntent.FLAG_IMMUTABLE in the flags argument — same call,

flags differ; check the LAST argument, not the call itself.

Step 6 — Crypto

rg -n "SecretKeySpec\(" -g '*.kt' -g '*.java' app/src/
rg -n 'Cipher\.getInstance\("AES"\)' -g '*.kt' -g '*.java' app/src/
rg -n 'getInstance\("(MD5|SHA-1)"\)' -g '*.kt' -g '*.java' app/src/
rg -n "setSeed\(" -g '*.kt' -g '*.java' app/src/

APK, never rotatable. Safe: AndroidKeyStore KeyGenParameterSpec.

"AES/GCM/NoPadding" = safe.

password/token = Critical).

Step 7 — Secrets artifacts & logcat

rg -n "current_key|api_key" -g 'google-services.json'
rg -n 'Log\.[dvi]\([^)]*[Tt]oken' -g '*.kt' -g '*.java' app/src/
rg -n -i "(api[_-]?key|secret|token)\s*=\s*\"[^\"]{8,}" -g '*.kt' -g '*.java' -g 'strings.xml' -g 'build.gradle*'

check Firebase key restrictions + which APIs are enabled before rating

higher; unrestricted keys are attacker-budget risks.

crash dumps). if (BuildConfig.DEBUG) gate + static message = safe.

Step 8 — Dependencies & build hygiene

build.gradle deps: dependency-vulns' osv_scan parses gradle.lockfile

(maven ecosystem) — plain implementation coordinates need manual OSV

lookup by group:artifact:version; note as limitation in the report.

minifyEnabled false in release + no resource obfuscation → informational.

Reporting

Severity table as in steps. Fixes are short: EncryptedSharedPreferences

create-call, bind-args execSQL, FLAG_IMMUTABLE, Keystore keygen. Manifest

findings → ../mobile-security/SKILL.md; Flutter equivalents →

../flutter-security/SKILL.md; dep CVEs → ../dependency-vulns/SKILL.md.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.