Skip to content

Commit

Permalink
Preventing FreeOTPPlus to share token to itself
Browse files Browse the repository at this point in the history
  • Loading branch information
helloworld1 committed Dec 25, 2022
1 parent 5b8e4ea commit e48e577
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/org/fedorahosted/freeotp/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ class MainActivity : AppCompatActivity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)

if (packageName == intent.extras?.getString(SHARE_FROM_PACKAGE_NAME_INTENT_EXTRA)) {
Log.i(TAG, "Intent shared from the same package name. Ignoring the intent and do not add the token")
return
}

val uri = intent.data
if (uri != null) {
lifecycleScope.launch {
Expand Down Expand Up @@ -460,5 +465,6 @@ class MainActivity : AppCompatActivity() {
const val READ_KEY_URI_REQUEST_CODE = 44
const val WRITE_KEY_URI_REQUEST_CODE = 45
const val SCREENSHOT_MODE_EXTRA = "screenshot_mode"
const val SHARE_FROM_PACKAGE_NAME_INTENT_EXTRA = "shareFromPackageName"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TokenViewHolder(private val activity: Activity,

R.id.action_share -> {
val i = Intent(Intent.ACTION_VIEW, Uri.parse(OtpTokenFactory.toUri(token).toString()))
i.putExtra(MainActivity.SHARE_FROM_PACKAGE_NAME_INTENT_EXTRA, activity.packageName)
activity.startActivity(Intent.createChooser(i, null))
}

Expand Down

0 comments on commit e48e577

Please sign in to comment.