CVE-2020-26230: Exposure of Sensitive Information to an Unauthorized Actor (CWE-200)
value: Radar COVID is the official COVID-19 exposure notification app for Spain. In affected versions of Radar COVID, identification and de-anonymization of COVID-19 positive users that upload Radar COVID TEKs to the Radar COVID server is possible. This vulnerability enables the identification and de-anonymization of COVID-19 positive users when using Radar COVID. The vulnerability is caused by the fact that Radar COVID connections to the server (uploading of TEKs to the backend) are only made by COVID-19 positives. Therefore, any on-path observer with the ability to monitor traffic between the app and the server can identify which users had a positive test. Such an adversary can be the mobile network operator (MNO) if the connection is done through a mobile network, the Internet Service Provider (ISP) if the connection is done through the Internet (e.g., a home network), a VPN provider used by the user, the local network operator in the case of enterprise networks, or any eavesdropper with access to the same network (WiFi or Ethernet) as the user as could be the case of public WiFi hotspots deployed at shopping centers, airports, hotels, and coffee shops. The attacker may also de-anonymize the user. For this additional stage to succeed, the adversary needs to correlate Radar COVID traffic to other identifiable information from the victim. This could be achieved by associating the connection to a contract with the name of the victim or by associating Radar COVID traffic to other user-generated flows containing identifiers in the clear (e.g., HTTP cookies or other mobile flows sending unique identifiers like the IMEI or the AAID without encryption). The former can be executed, for instance, by the Internet Service Provider or the MNO. The latter can be executed by any on-path adversary, such as the network provider or even the cloud provider that hosts more than one service accessed by the victim. The farther the adversary is either from the victim (the client) or the end-point (the server), the less likely it may be that the adversary has access to re-identification information. The vulnerability has been mitigated with the injection of dummy traffic from the application to the backend. Dummy traffic is generated by all users independently of whether they are COVID-19 positive or not. The issue was fixed in iOS in version 1.0.8 (uniform distribution), 1.1.0 (exponential distribution), Android in version 1.0.7 (uniform distribution), 1.1.0 (exponential distribution), Backend in version 1.1.2-RELEASE. For more information see the referenced GitHub Security Advisory.
CWE description: The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
CVSS v3 base score: 5.3
Published: 2020-11-13T19:15Z
Repository: https://github.com/RadarCOVID/radar-covid-android
Language: Kotlin
Files changed: app/src/main/java/es/gob/radarcovid/RadarCovidApplication.kt, app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepository.kt, app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepositoryImpl.kt, app/src/main/java/es/gob/radarcovid/features/worker/FakeInfectionReportWorker.kt
Commit date: 2020-10-08 10:27:13 +0200
Commit message: *Added exponential interval for fake request

Diff: diff --git a/app/src/main/java/es/gob/radarcovid/RadarCovidApplication.kt b/app/src/main/java/es/gob/radarcovid/RadarCovidApplication.kt
index 5c92dad..cc74578 100644
--- a/app/src/main/java/es/gob/radarcovid/RadarCovidApplication.kt
+++ b/app/src/main/java/es/gob/radarcovid/RadarCovidApplication.kt
@@ -12,10 +12,11 @@ package es.gob.radarcovid
 
 import dagger.android.AndroidInjector
 import dagger.android.support.DaggerApplication
 import es.gob.radarcovid.common.base.broadcast.ExposureStatusChangeBroadcastReceiver
 import es.gob.radarcovid.common.di.component.DaggerApplicationComponent
+import es.gob.radarcovid.datamanager.repository.PreferencesRepository
 import es.gob.radarcovid.features.worker.FakeInfectionReportWorker
 import io.reactivex.rxjava3.plugins.RxJavaPlugins
 import okhttp3.CertificatePinner
 import org.dpppt.android.sdk.DP3T
 import org.dpppt.android.sdk.models.ApplicationInfo
@@ -27,10 +28,13 @@ import javax.inject.Named
 class RadarCovidApplication : DaggerApplication() {
 
     @Inject
     lateinit var certificatePinner: CertificatePinner
 
+    @Inject
+    lateinit var preferencesRepository: PreferencesRepository
+
     @Inject
     @Named("userAgent")
     lateinit var userAgent: String
 
     override fun onCreate() {
@@ -45,11 +49,11 @@ class RadarCovidApplication : DaggerApplication() {
             BuildConfig.DEBUG
         )
         DP3T.setCertificatePinner(certificatePinner)
         DP3T.setUserAgent(userAgent)
 
-        FakeInfectionReportWorker.start(this)
+        FakeInfectionReportWorker.start(this, preferencesRepository)
 
         registerReceiver(ExposureStatusChangeBroadcastReceiver(), DP3T.getUpdateIntentFilter())
 
     }
 
diff --git a/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepository.kt b/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepository.kt
index eda8e61..e6ae8f3 100644
--- a/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepository.kt
+++ b/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepository.kt
@@ -55,6 +55,10 @@ interface PreferencesRepository {
 
     fun setHealingTime(healingTime: HealingTime)
 
     fun getHealingTime(): HealingTime
 
+    fun getTDummy(): Long
+
+    fun setTDummy(time: Long)
+
 }
\ No newline at end of file
diff --git a/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepositoryImpl.kt b/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepositoryImpl.kt
index 09f36b7..dda1248 100644
--- a/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepositoryImpl.kt
+++ b/app/src/main/java/es/gob/radarcovid/datamanager/repository/PreferencesRepositoryImpl.kt
@@ -34,10 +34,11 @@ class PreferencesRepositoryImpl @Inject constructor(@Named("applicationContext")
         private const val KEY_CURRENT_REGION = "key_current_region"
         private const val KEY_CURRENT_LANGUAGE = "key_current_language"
         private const val KEY_REGIONS = "key_regions"
         private const val KEY_LANGUAGES = "key_languages"
         private const val KEY_HEALING_TIME = "key_healing_time"
+        private const val KEY_T_DUMMY = "KEY_T_DUMMY"
     }
 
     private val preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)
 
     override fun isOnBoardingCompleted(): Boolean =
@@ -165,6 +166,14 @@ class PreferencesRepositoryImpl @Inject constructor(@Named("applicationContext")
                     "    }"
         )
         return Gson().fromJson(healingTimeJson, HealingTime::class.java)
     }
 
+    override fun getTDummy(): Long {
+        return preferences.getLong(KEY_T_DUMMY, -1)
+    }
+
+    override fun setTDummy(time: Long) {
+        preferences.edit().putLong(KEY_T_DUMMY, time).apply()
+    }
+
 }
\ No newline at end of file
diff --git a/app/src/main/java/es/gob/radarcovid/features/worker/FakeInfectionReportWorker.kt b/app/src/main/java/es/gob/radarcovid/features/worker/FakeInfectionReportWorker.kt
index 321cc1d..a34be4b 100644
--- a/app/src/main/java/es/gob/radarcovid/features/worker/FakeInfectionReportWorker.kt
+++ b/app/src/main/java/es/gob/radarcovid/features/worker/FakeInfectionReportWorker.kt
@@ -11,16 +11,25 @@
 package es.gob.radarcovid.features.worker
 
 import android.content.Context
 import androidx.work.*
 import dagger.android.HasAndroidInjector
+import es.gob.radarcovid.datamanager.repository.PreferencesRepository
 import es.gob.radarcovid.datamanager.usecase.ReportFakeInfectionUseCase
 import org.dpppt.android.sdk.BuildConfig
 import org.dpppt.android.sdk.DP3T
+import java.security.SecureRandom
 import java.util.concurrent.TimeUnit
 import javax.inject.Inject
-import kotlin.random.Random
+
+
+private const val FACTOR_HOUR_MILLIS = 60 * 60 * 1000L
+private const val FACTOR_DAY_MILLIS: Long = 24 * FACTOR_HOUR_MILLIS
+private const val MAX_DELAY_HOURS: Long = 48
+private val SAMPLING_RATE =
+    if (BuildConfig.DEBUG) 1.0f else 0.2f
+private const val KEY_T_DUMMY = "KEY_T_DUMMY"
 
 class FakeInfectionReportWorker(context: Context, workerParams: WorkerParameters) :
     Worker(context, workerParams) {
 
     init {
@@ -29,45 +38,95 @@ class FakeInfectionReportWorker(context: Context, workerParams: WorkerParameters
             ?.inject(this)
     }
 
     companion object {
 
+        private var clock: Clock = ClockImpl()
+
         private const val TAG = "FakeInfectionReportWorker"
 
-        fun start(context: Context) {
-            start(context, getRandomDelay(), ExistingWorkPolicy.KEEP)
+        fun start(context: Context, preferencesRepository: PreferencesRepository) {
+            var tDummy: Long = preferencesRepository.getTDummy()
+            if (tDummy == -1L) {
+                tDummy = clock.currentTimeMillis() + clock.syncInterval()
+                preferencesRepository.setTDummy(tDummy)
+            }
+            start(context, tDummy, ExistingWorkPolicy.KEEP)
         }
 
         private fun start(
             context: Context,
-            delayInMinutes: Long,
+            tDummy: Long,
             existingWorkPolicy: ExistingWorkPolicy
         ) {
+
+            val now = clock.currentTimeMillis()
+            val executionDelay = 0L.coerceAtLeast(tDummy - now)
+            val executionDelayDays =
+                executionDelay / FACTOR_DAY_MILLIS
+
             val constraints = Constraints.Builder()
                 .setRequiredNetworkType(NetworkType.CONNECTED)
                 .build()
             val work =
                 OneTimeWorkRequest
                     .Builder(FakeInfectionReportWorker::class.java)
-                    .setInitialDelay(delayInMinutes, TimeUnit.MINUTES)
+                    .setInitialDelay(executionDelayDays, TimeUnit.MINUTES)
                     .setConstraints(constraints)
+                    .setInputData(Data.Builder().putLong(KEY_T_DUMMY, tDummy).build())
                     .build()
             WorkManager.getInstance(context)
                 .enqueueUniqueWork(TAG, existingWorkPolicy, work)
         }
 
-        private fun getRandomDelay(): Long = Random.nextLong(180, 360)
+        //private fun getRandomDelay(): Long = Random.nextLong(180, 360)
 
     }
 
     @Inject
     lateinit var reportFakeInfectionUseCase: ReportFakeInfectionUseCase
 
+    @Inject
+    lateinit var preferencesRepository: PreferencesRepository
+
     override fun doWork(): Result {
-        if (BuildConfig.DEBUG)
-            DP3T.addWorkerStartedToHistory(applicationContext, TAG)
-        reportFakeInfectionUseCase.reportFakeInfection().subscribe()
-        start(applicationContext, getRandomDelay(), ExistingWorkPolicy.APPEND)
+        val now = clock.currentTimeMillis()
+        var tDummy = inputData.getLong(KEY_T_DUMMY, now)
+        while (tDummy < now) {
+            if (tDummy >= now - FACTOR_HOUR_MILLIS * MAX_DELAY_HOURS) {
+                if (BuildConfig.DEBUG)
+                    DP3T.addWorkerStartedToHistory(applicationContext, TAG)
+                reportFakeInfectionUseCase.reportFakeInfection().subscribe()
+            }
+            tDummy += clock.syncInterval();
+            preferencesRepository.setTDummy(tDummy)
+        }
+
+        start(applicationContext, tDummy, ExistingWorkPolicy.APPEND)
         return Result.success()
     }
-    
+
+    interface Clock {
+        fun syncInterval(): Long
+        fun currentTimeMillis(): Long
+    }
+
+    class ClockImpl : Clock {
+        override fun syncInterval(): Long {
+            val newDelayDays: Double =
+                ExponentialDistribution.sampleFromStandard() / SAMPLING_RATE
+            return (newDelayDays * FACTOR_DAY_MILLIS) as Long
+        }
+
+        override fun currentTimeMillis(): Long {
+            return System.currentTimeMillis()
+        }
+    }
+
+    object ExponentialDistribution {
+        fun sampleFromStandard(): Double {
+            val random = SecureRandom()
+            return -Math.log(1.0 - random.nextDouble())
+        }
+    }
+
 }
\ No newline at end of file

Vulnerable code:         FakeInfectionReportWorker.start(this)
import kotlin.random.Random
        fun start(context: Context) {
            start(context, getRandomDelay(), ExistingWorkPolicy.KEEP)
            delayInMinutes: Long,
                    .setInitialDelay(delayInMinutes, TimeUnit.MINUTES)
        private fun getRandomDelay(): Long = Random.nextLong(180, 360)
        if (BuildConfig.DEBUG)
            DP3T.addWorkerStartedToHistory(applicationContext, TAG)
        reportFakeInfectionUseCase.reportFakeInfection().subscribe()
        start(applicationContext, getRandomDelay(), ExistingWorkPolicy.APPEND)
    
Fixed code: import es.gob.radarcovid.datamanager.repository.PreferencesRepository
    @Inject
    lateinit var preferencesRepository: PreferencesRepository

        FakeInfectionReportWorker.start(this, preferencesRepository)
    fun getTDummy(): Long

    fun setTDummy(time: Long)

        private const val KEY_T_DUMMY = "KEY_T_DUMMY"
    override fun getTDummy(): Long {
        return preferences.getLong(KEY_T_DUMMY, -1)
    }

    override fun setTDummy(time: Long) {
        preferences.edit().putLong(KEY_T_DUMMY, time).apply()
    }

import es.gob.radarcovid.datamanager.repository.PreferencesRepository
import java.security.SecureRandom


private const val FACTOR_HOUR_MILLIS = 60 * 60 * 1000L
private const val FACTOR_DAY_MILLIS: Long = 24 * FACTOR_HOUR_MILLIS
private const val MAX_DELAY_HOURS: Long = 48
private val SAMPLING_RATE =
    if (BuildConfig.DEBUG) 1.0f else 0.2f
private const val KEY_T_DUMMY = "KEY_T_DUMMY"
        private var clock: Clock = ClockImpl()

        fun start(context: Context, preferencesRepository: PreferencesRepository) {
            var tDummy: Long = preferencesRepository.getTDummy()
            if (tDummy == -1L) {
                tDummy = clock.currentTimeMillis() + clock.syncInterval()
                preferencesRepository.setTDummy(tDummy)
            }
            start(context, tDummy, ExistingWorkPolicy.KEEP)
            tDummy: Long,

            val now = clock.currentTimeMillis()
            val executionDelay = 0L.coerceAtLeast(tDummy - now)
            val executionDelayDays =
                executionDelay / FACTOR_DAY_MILLIS

                    .setInitialDelay(executionDelayDays, TimeUnit.MINUTES)
                    .setInputData(Data.Builder().putLong(KEY_T_DUMMY, tDummy).build())
        //private fun getRandomDelay(): Long = Random.nextLong(180, 360)
    @Inject
    lateinit var preferencesRepository: PreferencesRepository

        val now = clock.currentTimeMillis()
        var tDummy = inputData.getLong(KEY_T_DUMMY, now)
        while (tDummy < now) {
            if (tDummy >= now - FACTOR_HOUR_MILLIS * MAX_DELAY_HOURS) {
                if (BuildConfig.DEBUG)
                    DP3T.addWorkerStartedToHistory(applicationContext, TAG)
                reportFakeInfectionUseCase.reportFakeInfection().subscribe()
            }
            tDummy += clock.syncInterval();
            preferencesRepository.setTDummy(tDummy)
        }

        start(applicationContext, tDummy, ExistingWorkPolicy.APPEND)

    interface Clock {
        fun syncInterval(): Long
        fun currentTimeMillis(): Long
    }

    class ClockImpl : Clock {
        override fun syncInterval(): Long {
            val newDelayDays: Double =
                ExponentialDistribution.sampleFromStandard() / SAMPLING_RATE
            return (newDelayDays * FACTOR_DAY_MILLIS) as Long
        }

        override fun currentTimeMillis(): Long {
            return System.currentTimeMillis()
        }
    }

    object ExponentialDistribution {
        fun sampleFromStandard(): Double {
            val random = SecureRandom()
            return -Math.log(1.0 - random.nextDouble())
        }
    }