Skip to content

Commit

Permalink
Fix #45: Proper tapjacking protection init
Browse files Browse the repository at this point in the history
  • Loading branch information
hvge committed May 26, 2023
1 parent d8c18b7 commit 48d66aa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun ReadableMap.toAppProtectionConfig(context: Context, javaPackagePath: String)
it.boolOptAt("block", jsTapjacking)?.let { raspBuilder.blockTapjacking(it) }
it.stringOptAt("blockSensitivity", jsTapjacking)?.let {
try {
ThreatIndex.valueOf(it)
raspBuilder.blockTapjackingSensitivity(ThreatIndex.valueOf(it))
} catch (t: Throwable) {
throw InvalidConfigException("blockSensitivity", jsTapjacking)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.wultra.android.malwarelytics.reactnative

import android.content.Context
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.os.Handler
import android.util.Base64.encodeToString
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactApplicationContext
Expand Down Expand Up @@ -179,6 +181,17 @@ class MalwarelyticsModule(reactContext: ReactApplicationContext) :
changeState(State.READY)
moduleInitResult = initializationResult
service.getRaspManager().registerRaspObserver(raspObserver)
executeOnMainThread {
// Make sure that service is still initialized.
if (service.isInitialized()) {
// Get the current activity from RN context.
val activity = reactApplicationContext.currentActivity
if (activity != null) {
service.getRaspManager().protectActivity(activity)
}
}
}
// Resolve the promise with initialization result
initializationResult.name
}
}
Expand Down Expand Up @@ -626,6 +639,16 @@ class MalwarelyticsModule(reactContext: ReactApplicationContext) :
}
}

/**
* Execute action on the main application's thread.
*/
private fun executeOnMainThread(action: () -> Unit) {
val handler = Handler(reactApplicationContext.mainLooper)
handler.post {
action()
}
}

/**
* Identifier of thread used by the serial executor.
*/
Expand Down
5 changes: 4 additions & 1 deletion example/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ const defaultConfig: MalwarelyticsConfig = {
// signaturePublicKey: "your-sign-pk-for-android-app"
// },
rasp: {
root: { action: 'NOTIFY' }
root: { action: 'NOTIFY' },
tapjacking: {
blockSensitivity: 'SAFE'
}
},
antivirus: {
enableSilentMode: false
Expand Down

0 comments on commit 48d66aa

Please sign in to comment.