From edbfba85c79b9b26290a11249e425016770e01b6 Mon Sep 17 00:00:00 2001 From: dadachi Date: Fri, 27 Mar 2026 17:14:48 +0900 Subject: [PATCH] Fix security vulnerabilities from audit - Disable cleartext traffic and add network_security_config.xml (debug override allows local dev) - Disable app backup to prevent auth token extraction via adb backup - Encrypt DataStore tokens at rest using Tink AEAD with Android Keystore - Add certificate pinning for api.nativeapptemplate.com (leaf + intermediate CA) - Validate NDEF URL origin before extracting intent data - Restrict to debug builds only - Remove unused mailto intent filter from MainActivity Co-Authored-By: Claude Opus 4.6 (1M context) --- app/build.gradle.kts | 1 + app/src/debug/AndroidManifest.xml | 7 ++++ .../debug/res/xml/network_security_config.xml | 7 ++++ app/src/main/AndroidManifest.xml | 16 +++------ .../datastore/UserPreferencesSerializer.kt | 34 +++++++++++++----- .../di/modules/CryptoModule.kt | 35 +++++++++++++++++++ .../di/modules/NetModule.kt | 9 +++++ .../nativeapptemplatefree/utils/Utility.kt | 4 +++ app/src/main/res/xml/backup_rules.xml | 8 +++++ .../main/res/xml/data_extraction_rules.xml | 17 +++++++++ .../main/res/xml/network_security_config.xml | 6 ++++ .../UserPreferencesSerializerTest.kt | 35 +++++++++++++++++-- .../datastoreTest/TestCryptoModule.kt | 27 ++++++++++++++ gradle/libs.versions.toml | 2 ++ 14 files changed, 185 insertions(+), 23 deletions(-) create mode 100644 app/src/debug/AndroidManifest.xml create mode 100644 app/src/debug/res/xml/network_security_config.xml create mode 100644 app/src/main/kotlin/com/nativeapptemplate/nativeapptemplatefree/di/modules/CryptoModule.kt create mode 100644 app/src/main/res/xml/backup_rules.xml create mode 100644 app/src/main/res/xml/data_extraction_rules.xml create mode 100644 app/src/main/res/xml/network_security_config.xml create mode 100644 app/src/test/kotlin/com/nativeapptemplate/nativeapptemplatefree/datastoreTest/TestCryptoModule.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5949925..e036eae 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -113,6 +113,7 @@ dependencies { implementation(libs.sandwich) implementation(libs.sandwich.retrofit) implementation(libs.sandwich.retrofit.serialization) + implementation(libs.tink.android) ksp(libs.hilt.compiler) diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..2d15fee --- /dev/null +++ b/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/app/src/debug/res/xml/network_security_config.xml b/app/src/debug/res/xml/network_security_config.xml new file mode 100644 index 0000000..d3e3084 --- /dev/null +++ b/app/src/debug/res/xml/network_security_config.xml @@ -0,0 +1,7 @@ + + + + + api.nativeapptemplate.com + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 880d741..fb13ed3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,17 +10,17 @@ - -