Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect cross-origin visit request attempts #180

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class RNSession(
visitableView?.visitLocationStarted(location)
}

override fun visitProposedToCrossOriginRedirect(location: String) {
visitableView?.visitProposedToCrossOriginRedirect(location)
}

override fun visitProposedToLocation(location: String, options: TurboVisitOptions) {
visitableView?.visitProposedToLocation(location, options)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscrib
}
}

override fun visitProposedToCrossOriginRedirect(location: String) {
sendEvent(RNVisitableViewEvent.OPEN_EXTERNAL_URL, Arguments.createMap().apply {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce a new property

putString("url", location)
})
}

override fun handleAlert(message: String, callback: () -> Unit) {
sendEvent(RNVisitableViewEvent.WEB_ALERT, Arguments.createMap().apply {
putString("message", message)
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"react-native": "src/index.tsx",
"hotwiredTurbo": {
"ios": "7.1.0",
"android": "7.1.0"
"android": "7.1.2"
},
"scripts": {
"build": "bob build && sh ./scripts/build.sh $npm_package_hotwiredTurbo_ios $npm_package_hotwiredTurbo_android && yarn link",
Expand Down
18 changes: 9 additions & 9 deletions packages/turbo/patches/turbo-android-react-native-support.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSession.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSession.kt
index 77a8b3c..c873aef 100644
index 4214499..188dc49 100644
--- a/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSession.kt
+++ b/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSession.kt
@@ -39,12 +39,13 @@ import java.util.*
@@ -42,12 +42,13 @@ import java.util.*
* @property webView An instance of a [TurboWebView] to be shared/managed.
*/
@Suppress("unused")
Expand All @@ -18,15 +18,15 @@ index 77a8b3c..c873aef 100644
internal var coldBootVisitIdentifier = ""
internal var previousOverrideUrlTime = 0L
internal var isColdBooting = false
@@ -55,6 +56,7 @@ class TurboSession internal constructor(
@@ -58,6 +59,7 @@ class TurboSession internal constructor(
internal val httpRepository = TurboHttpRepository(activity.lifecycleScope)
internal val requestInterceptor = TurboWebViewRequestInterceptor(this)
internal val fileChooserDelegate = TurboFileChooserDelegate(this)
+ var isRunningInAndroidNavigation = true

// User accessible

@@ -129,7 +131,7 @@ class TurboSession internal constructor(
@@ -132,7 +134,7 @@ class TurboSession internal constructor(

// Internal

Expand All @@ -35,7 +35,7 @@ index 77a8b3c..c873aef 100644
this.currentVisit = visit
callback { it.visitLocationStarted(visit.location) }

@@ -149,7 +151,7 @@ class TurboSession internal constructor(
@@ -152,7 +154,7 @@ class TurboSession internal constructor(
* visit request. This is used when restoring a Fragment destination from the backstack,
* but the WebView's current location hasn't changed from the destination's location.
*/
Expand All @@ -44,7 +44,7 @@ index 77a8b3c..c873aef 100644
val visit = currentVisit ?: return false
val restorationIdentifier = restorationIdentifiers[visit.destinationIdentifier]

@@ -627,7 +629,7 @@ class TurboSession internal constructor(
@@ -656,7 +658,7 @@ class TurboSession internal constructor(
private fun callback(action: (TurboSessionCallback) -> Unit) {
context.runOnUiThread {
currentVisit?.callback?.let { callback ->
Expand All @@ -54,11 +54,11 @@ index 77a8b3c..c873aef 100644
}
}
diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionCallback.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionCallback.kt
index 0bbaa01..7d8cc6c 100644
index cb8c905..101fad9 100644
--- a/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionCallback.kt
+++ b/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionCallback.kt
@@ -5,7 +5,7 @@ import dev.hotwire.turbo.nav.TurboNavDestination
import dev.hotwire.turbo.errors.TurboVisitError
@@ -5,7 +5,7 @@ import dev.hotwire.turbo.errors.TurboVisitError
import dev.hotwire.turbo.nav.TurboNavDestination
import dev.hotwire.turbo.visit.TurboVisitOptions

-internal interface TurboSessionCallback {
Expand Down
68 changes: 34 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8634,7 +8634,7 @@ react-native-turbo@*:
integrity sha512-l7WcDaVTQD6S611MmFwvdgQawAACs43SVDKUs92pqBCQw3j7xXfW4bc5OoiIG6c/5qSsb3DNQj5XC6MnlkLPqQ==

"react-native-turbo@file:packages/turbo":
version "1.0.0-beta.2"
version "1.0.0-beta.5"

"react-native-web-screen@file:packages/navigation":
version "1.0.0-beta.3"
Expand Down Expand Up @@ -9912,47 +9912,47 @@ tslib@^2.0.1, tslib@^2.1.0, tslib@^2.4.0, tslib@^2.6.2:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

turbo-darwin-64@1.12.5:
version "1.12.5"
resolved "https://registry.yarnpkg.com/turbo-darwin-64/-/turbo-darwin-64-1.12.5.tgz#bcc2833b4c9e9a02085088cc72f9db04bf45d48e"
integrity sha512-0GZ8reftwNQgIQLHkHjHEXTc/Z1NJm+YjsrBP+qhM/7yIZ3TEy9gJhuogDt2U0xIWwFgisTyzbtU7xNaQydtoA==
turbo-darwin-64@1.13.2:
version "1.13.2"
resolved "https://registry.yarnpkg.com/turbo-darwin-64/-/turbo-darwin-64-1.13.2.tgz#34c8c8a06e9c38ed9cbd219b2ade6e83f02bc7b3"
integrity sha512-CCSuD8CfmtncpohCuIgq7eAzUas0IwSbHfI8/Q3vKObTdXyN8vAo01gwqXjDGpzG9bTEVedD0GmLbD23dR0MLA==

turbo-darwin-arm64@1.12.5:
version "1.12.5"
resolved "https://registry.yarnpkg.com/turbo-darwin-arm64/-/turbo-darwin-arm64-1.12.5.tgz#42ccd0e0a188780351fa76b7bc243f7a3dadb8e0"
integrity sha512-8WpOLNNzvH6kohQOjihD+gaWL+ZFNfjvBwhOF0rjEzvW+YR3Pa7KjhulrjWyeN2yMFqAPubTbZIGOz1EVXLuQA==
turbo-darwin-arm64@1.13.2:
version "1.13.2"
resolved "https://registry.yarnpkg.com/turbo-darwin-arm64/-/turbo-darwin-arm64-1.13.2.tgz#2fd380e13b8cd75d1514c433d196ea4be097230c"
integrity sha512-0HySm06/D2N91rJJ89FbiI/AodmY8B3WDSFTVEpu2+8spUw7hOJ8okWOT0e5iGlyayUP9gr31eOeL3VFZkpfCw==

turbo-linux-64@1.12.5:
version "1.12.5"
resolved "https://registry.yarnpkg.com/turbo-linux-64/-/turbo-linux-64-1.12.5.tgz#77cd4aa4fd8a911178924a3d2866e841a61545a1"
integrity sha512-INit73+bNUpwqGZCxgXCR3I+cQsdkQ3/LkfkgSOibkpg+oGqxJRzeXw3sp990d7SCoE8QOcs3iw+PtiFX/LDAA==
turbo-linux-64@1.13.2:
version "1.13.2"
resolved "https://registry.yarnpkg.com/turbo-linux-64/-/turbo-linux-64-1.13.2.tgz#a861fb4180e0a601459b79837b4e2ded27c7ffa7"
integrity sha512-7HnibgbqZrjn4lcfIouzlPu8ZHSBtURG4c7Bedu7WJUDeZo+RE1crlrQm8wuwO54S0siYqUqo7GNHxu4IXbioQ==

turbo-linux-arm64@1.12.5:
version "1.12.5"
resolved "https://registry.yarnpkg.com/turbo-linux-arm64/-/turbo-linux-arm64-1.12.5.tgz#d576cb2fbaecfc086e20cccd276f89ace1ebc889"
integrity sha512-6lkRBvxtI/GQdGtaAec9LvVQUoRw6nXFp0kM+Eu+5PbZqq7yn6cMkgDJLI08zdeui36yXhone8XGI8pHg8bpUQ==
turbo-linux-arm64@1.13.2:
version "1.13.2"
resolved "https://registry.yarnpkg.com/turbo-linux-arm64/-/turbo-linux-arm64-1.13.2.tgz#e0d290ea338eb8e5fb8905547954d36f81d8d7fa"
integrity sha512-sUq4dbpk6SNKg/Hkwn256Vj2AEYSQdG96repio894h5/LEfauIK2QYiC/xxAeW3WBMc6BngmvNyURIg7ltrePg==

turbo-windows-64@1.12.5:
version "1.12.5"
resolved "https://registry.yarnpkg.com/turbo-windows-64/-/turbo-windows-64-1.12.5.tgz#2c44f177b4a9b9bc0ae0975caca139895d222313"
integrity sha512-gQYbOhZg5Ww0bQ/bC0w/4W6yQRwBumUUnkB+QPo15VznwxZe2a7bo6JM+9Xy9dKLa/kn+p7zTqme4OEp6M3/Yg==
turbo-windows-64@1.13.2:
version "1.13.2"
resolved "https://registry.yarnpkg.com/turbo-windows-64/-/turbo-windows-64-1.13.2.tgz#c9821ea0d34204d3bed28ccfb096c520dbe3c209"
integrity sha512-DqzhcrciWq3dpzllJR2VVIyOhSlXYCo4mNEWl98DJ3FZ08PEzcI3ceudlH6F0t/nIcfSItK1bDP39cs7YoZHEA==

turbo-windows-arm64@1.12.5:
version "1.12.5"
resolved "https://registry.yarnpkg.com/turbo-windows-arm64/-/turbo-windows-arm64-1.12.5.tgz#3ee01dc956477d306591a8fbe24ef6c9b7dff470"
integrity sha512-auvhZ9FrhnvQ4mgBlY9O68MT4dIfprYGvd2uPICba/mHUZZvVy5SGgbHJ0KbMwaJfnnFoPgLJO6M+3N2gDprKw==
turbo-windows-arm64@1.13.2:
version "1.13.2"
resolved "https://registry.yarnpkg.com/turbo-windows-arm64/-/turbo-windows-arm64-1.13.2.tgz#07d6a01a1bfc6293ee8365cf3639914244f6f0b9"
integrity sha512-WnPMrwfCXxK69CdDfS1/j2DlzcKxSmycgDAqV0XCYpK/812KB0KlvsVAt5PjEbZGXkY88pCJ1BLZHAjF5FcbqA==

turbo@^1.12.5:
version "1.12.5"
resolved "https://registry.yarnpkg.com/turbo/-/turbo-1.12.5.tgz#63b390ce4df14315d6c72a46379d6ee29556f5d4"
integrity sha512-FATU5EnhrYG8RvQJYFJnDd18DpccDjyvd53hggw9T9JEg9BhWtIEoeaKtBjYbpXwOVrJQMDdXcIB4f2nD3QPPg==
version "1.13.2"
resolved "https://registry.yarnpkg.com/turbo/-/turbo-1.13.2.tgz#c45919cb1cebc86390516184396247eedf65e232"
integrity sha512-rX/d9f4MgRT3yK6cERPAkfavIxbpBZowDQpgvkYwGMGDQ0Nvw1nc0NVjruE76GrzXQqoxR1UpnmEP54vBARFHQ==
optionalDependencies:
turbo-darwin-64 "1.12.5"
turbo-darwin-arm64 "1.12.5"
turbo-linux-64 "1.12.5"
turbo-linux-arm64 "1.12.5"
turbo-windows-64 "1.12.5"
turbo-windows-arm64 "1.12.5"
turbo-darwin-64 "1.13.2"
turbo-darwin-arm64 "1.13.2"
turbo-linux-64 "1.13.2"
turbo-linux-arm64 "1.13.2"
turbo-windows-64 "1.13.2"
turbo-windows-arm64 "1.13.2"

type-check@^0.4.0, type-check@~0.4.0:
version "0.4.0"
Expand Down
Loading