Merged
Conversation
…etection, domain age & clipboard monitoring - UrlExpander: follow redirect chain for 21 known shorteners (bit.ly, t.co, tinyurl, goo.gl, rb.gy, lnkd.in, etc.) before any analysis. Removed all shortener domains from the static whitelist — they were silently passing phishing-via-shortener as SAFE. - HomographDetector: flag Punycode (xn--) labels, non-ASCII characters in domain, and zero-width invisible characters injected into URLs. Check runs before the whitelist so a spoofed domain can never slip through as trusted. - DomainAgeChecker: query RDAP (free, no API key) for domain registration date. Lowers ONNX decision threshold to 0.20 for domains <7 days old and 0.35 for domains <30 days old. Results cached in-memory (LRU, 24h TTL). - ClipboardMonitorService: foreground service that monitors clipboard changes and scans extracted URLs. Two-path strategy for Android 10+ background restriction. Real-time protection toggle now starts/stops the service. - DB migration: replaced fallbackToDestructiveMigration() with fallbackToDestructiveMigrationFrom(1..7) — version 8+ never wipes user data. - ProGuard: enabled isMinifyEnabled + isShrinkResources in release build. Added keep rules for Room, Retrofit/Gson, OkHttp, Hilt, ONNX Runtime, Compose, WorkManager, and all Android service/receiver components. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Merges fix/phishing worktree branch containing: - URL shortener expansion (bit.ly, t.co, tinyurl etc.) - Homograph / Unicode spoofing detection - Domain age check via RDAP (free, no API key) - Clipboard monitoring foreground service - ProGuard enabled for release builds - Safe DB migration strategy (no more destructive wipe on schema change) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…to fix/phishing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛡️ Phishing Module — False Positive & Security Fixes
What & Why
The phishing scanner had critical gaps that allowed real attacks to slip through as safe, and shipped with zero code protection in release builds. This PR closes all of them.
Changes at a Glance
UrlExpander.kt·PhishingRepositoryImpl.ktHomographDetector.kt·PhishingRepositoryImpl.ktDomainAgeChecker.kt·PhishingRepositoryImpl.ktClipboardMonitorService.kt·PhishingViewModel.kt·NotificationHelper.ktbuild.gradle.kts·proguard-rules.proCyberShieldDatabase.ktFix 1 — URL Shortener Expansion
Problem:
bit.ly,t.co,tinyurl.com,goo.gl,ow.lywere hardcoded in the trusted whitelist. Any phishing URL hidden behind a shortener was instantly marked ✅ SAFE — ONNX and Safe Browsing never ran.Fix: New
UrlExpander.ktfollows the redirect chain (HEAD → GET fallback, 6s timeout) for 21 known shorteners before any analysis. Shortener domains removed from whitelist. Expansion happens as the first step incheckUrl(), before Safe Browsing or ONNX. Scan history shows"expanded from bit.ly/xxx"so users know what was checked. Falls back silently on network failure — scan always continues.Fix 2 — Homograph / Unicode Spoofing Detection
Problem: Domains like
аpple.com(Cyrillicа) orpаypal.comare visually identical to their legitimate counterparts but resolve to completely different servers. The old code had no defence against this — these URLs passed right through.Fix: New
HomographDetector.ktruns before the whitelist, checking for:\u200B,\uFEFF, etc.) injected into the URLxn--) — already IDN-encoded Unicode domainsURISyntaxExceptionfromjava.net.URI— itself a signal of illegal UnicodeReturns
CRITICALimmediately with 0.99 confidence. No ONNX inference needed.Fix 3 — Domain Age Check via RDAP
Problem: A brand-new
secure-paypal-login-2024.com(registered yesterday) got the same ONNX threshold aspaypal.com(registered 25 years ago). ~60% of phishing domains are under 30 days old at time of use — this signal was completely ignored.Fix: New
DomainAgeChecker.ktqueriesrdap.org(free, no API key, RFC 7483). Results cached in LRU for 24h. Domain age now directly lowers the ONNX decision threshold:Never blocks — RDAP failures are swallowed silently.
Fix 4 — Clipboard Monitoring
Problem: The DB schema had a
"CLIPBOARD"source field but no service populated it. Phishing URLs copy-pasted from WhatsApp, Telegram, or SMS were never scanned.Fix: New
ClipboardMonitorService.kt— foreground service (silentIMPORTANCE_MINnotification) registered withforegroundServiceType="specialUse". Two-path strategy required by Android 10+ privacy restriction:PhishingViewModel.checkFromClipboard()auto-scansThe real-time protection toggle in
PhishingViewModelnow actually starts/stops the service (previously it only updated UI state).Fix 5 — ProGuard Enabled
Problem:
isMinifyEnabled = falsein release. The full un-obfuscated APK was shippable — anyone could decompile it withjadxand read the exact detection thresholds, whitelist patterns, and ONNX feature logic to build evasion.Fix:
isMinifyEnabled = true+isShrinkResources = truein release.proguard-rules.prorewritten with keep rules for every library: Room entities, Retrofit/Gson models, Hilt, ONNX Runtime JNI, WorkManager, all Services/Receivers, and Kotlin metadata.Fix 6 — Safe Database Migration
Problem:
fallbackToDestructiveMigration()was active. Any future schema bump would silently delete all user scan history with no warning — unacceptable for a Play Store app.Fix: Replaced with
fallbackToDestructiveMigrationFrom(1, 2, 3, 4, 5, 6, 7). Dev databases (v1–7) can still be wiped. Version 8+ (production) will throwIllegalStateExceptionif no migration is provided — forcing a properMigrationobject before any schema change ships.Files Changed
Fix 7 — CI / Test Compilation Fixes
Problem: The Android CI build (
testDebugUnitTest) was failing due to three compile-time mismatches introduced during the phishing refactor.Fixes:
PhishingOnnxScanner(private ctor) instead ofPhishingScannerinterfacePhishingRepositoryTest.ktPhishingScannernetworkMonitor.isCurrentlyConnected()mock in whitelist testPhishingRepositoryTest.ktevery { networkMonitor.isCurrentlyConnected() } returns falsePhishingViewModelconstructor gainedContextparam but test wasn't updatedPhishingViewModelTest.ktContextmock, fixed constructor callbuild.gradle.ktsusedid()instead of version catalogalias()for Hilt pluginbuild.gradle.ktsalias(libs.plugins.hilt)Out of Scope (Separate PRs)