From 416089921d63a3550482556a9a9deea2e8ae1599 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 30 Jul 2023 12:39:52 +0200 Subject: [PATCH] white list all google.* and google.(com|co).* --- .../exarhteam/iitc_mobile/IITC_Mobile.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_Mobile.java b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_Mobile.java index 87dd95620..934a62072 100644 --- a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_Mobile.java +++ b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_Mobile.java @@ -118,6 +118,7 @@ public class IITC_Mobile extends AppCompatActivity private String debugInputStore = ""; private Map mAllowedHostnames = new HashMap<>(); private Set mInternalHostnames = new HashSet<>(); + private final Pattern mGoogleHostnamePattern = Pattern.compile("(^|\\.)google(\\.com|\\.co)?\\.\\w+$"); private String mIITCDefaultUA; private final String mDesktopUA = "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130810 Firefox/17.0 Iceweasel/17.0.8"; @@ -1287,11 +1288,26 @@ public boolean isInternalHostname(String hostname) { return mInternalHostnames.contains(hostname); } + /** + * @param hostname host name + * @return true if host name is google.* or google.com?.* domain + */ + public boolean isGoogleHostname(String hostname) { + if (hostname.startsWith("google.") || hostname.contains(".google.")) { + return mGoogleHostnamePattern.matcher(hostname).find(); + } + return false; + } + /** * @param hostname host name. * @return true if a host name allowed to be load in IITC. */ public boolean isAllowedHostname(String hostname) { + // shortcut for .google.* hostnames + if (isGoogleHostname(hostname)) { + return true; + } for (String key : mAllowedHostnames.keySet()) { if (hostname.equals(key)) return true; if (hostname.endsWith("." + key)) return true; @@ -1306,6 +1322,10 @@ public boolean isAllowedHostname(String hostname) { public String getUserAgentForHostname(String hostname) { if (mSharedPrefs.getBoolean("pref_fake_user_agent", false)) return mDesktopUA; + // shortcut for .google.* hostnames + if (isGoogleHostname(hostname)) { + hostname = "google.com"; + } for (Map.Entry e : mAllowedHostnames.entrySet()) { final String key = e.getKey(); if (hostname.equals(key)) return e.getValue();