From 6277ab09563f34ca58b9c97b2ebeba87d98412a2 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Sat, 1 Jun 2024 04:59:29 +0000 Subject: [PATCH] [components] Closes https://github.com/mozilla-mobile/android-components/issues/7637: Add allowed redirect URL list for AppLinksInterceptor UltraBlame original commit: 2ba2e1c21936de6049eece2d4ab9c79eadd5e53e --- .../feature/app/links/AppLinksInterceptor.kt | 72 ++++++++++++++++++- .../app/links/AppLinksInterceptorTest.kt | 47 +++++++++++- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt b/mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt index 566035692076..e6f1b65298e4 100644 --- a/mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt +++ b/mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt @@ -470,6 +470,23 @@ if available . * +param +allowRedirectUrls +A +set +of +URLs +that +allows +intercept +when +onLoadRequest +is +triggered +by +redirect +. +* / Suppress ( @@ -546,6 +563,16 @@ launchFromInterceptor Boolean = false +private +val +allowRedirectUrls +: +Set +< +String +> += +ALLOW_REDIRECT_HOSTS ) : RequestInterceptor @@ -580,7 +607,7 @@ InterceptionResponse ? { val -uriScheme +encodedUri = Uri . @@ -588,6 +615,10 @@ parse ( uri ) +val +uriScheme += +encodedUri . scheme val @@ -600,6 +631,19 @@ contains uriScheme ) val +isAllowedRedirect += +( +isRedirect +& +& +encodedUri +. +host +in +allowRedirectUrls +) +val doNotIntercept = when @@ -620,6 +664,7 @@ from an user gesture +allowed redirect and direct @@ -653,7 +698,7 @@ hasUserGesture & & ! -isRedirect +isAllowedRedirect & & ! @@ -933,4 +978,27 @@ uri return null } +companion +object +{ +internal +val +ALLOW_REDIRECT_HOSTS +: +Set +< +String +> += +setOf +( +" +www +. +ubereats +. +com +" +) +} } diff --git a/mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt b/mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt index f6f9f4f775d7..42bc3f5b1fa7 100644 --- a/mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt +++ b/mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt @@ -515,6 +515,16 @@ true useCases = mockUseCases +allowRedirectUrls += +setOf +( +" +soundcloud +. +com +" +) ) } Test @@ -562,7 +572,8 @@ request is intercepted by -a +an +allowed redirect ( ) @@ -596,6 +607,40 @@ Test fun request is +not +intercepted +by +a +not +allowed +redirect +( +) +{ +val +response += +appLinksInterceptor +. +onLoadRequest +( +mockEngineSession +webUrl +false +false +true +false +) +assertEquals +( +null +response +) +} +Test +fun +request +is intercepted by direct