-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from cyb3rko/intent-url-protection
Protection of intentURL attack using interactive dialog confirmation
- Loading branch information
Showing
8 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
app/src/main/kotlin/com/github/gotify/messages/IntentUrlDialogActivity.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.gotify.messages | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.github.gotify.databinding.ActivityDialogIntentUrlBinding | ||
|
||
internal class IntentUrlDialogActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setFinishOnTouchOutside(false) | ||
val binding = ActivityDialogIntentUrlBinding.inflate(layoutInflater) | ||
val intentUrl = intent.getStringExtra(EXTRA_KEY_URL) | ||
assert(intentUrl != null) { "intentUrl may not be empty" } | ||
|
||
binding.urlView.text = intentUrl | ||
binding.openButton.setOnClickListener { | ||
finish() | ||
Intent(Intent.ACTION_VIEW).apply { | ||
data = Uri.parse(intentUrl) | ||
flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
startActivity(this) | ||
} | ||
} | ||
binding.cancelButton.setOnClickListener { finish() } | ||
setContentView(binding.root) | ||
} | ||
|
||
companion object { | ||
const val EXTRA_KEY_URL = "url" | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:maxWidth="560dp" | ||
android:minWidth="280dp" | ||
android:orientation="vertical" | ||
android:padding="24dp"> | ||
|
||
<com.google.android.material.textview.MaterialTextView | ||
android:id="@+id/message_view" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/action_dialog_message" | ||
android:textSize="18sp" /> | ||
|
||
<com.google.android.material.textview.MaterialTextView | ||
android:id="@+id/url_view" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_horizontal" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_marginTop="8dp" | ||
android:textSize="18sp" | ||
android:textStyle="italic" | ||
tools:text="https://gotify.net" /> | ||
|
||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="end" | ||
android:layout_marginTop="24dp"> | ||
|
||
<com.google.android.material.button.MaterialButton | ||
style="@style/Widget.Material3.Button.TextButton.Dialog" | ||
android:id="@+id/cancel_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/action_dialog_button_cancel" /> | ||
|
||
<com.google.android.material.button.MaterialButton | ||
style="@style/Widget.Material3.Button.TextButton.Dialog" | ||
android:id="@+id/open_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/action_dialog_button_open" /> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains 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
This file contains 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
This file contains 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