Skip to content

Commit

Permalink
Fix google hijacking (#69)
Browse files Browse the repository at this point in the history
* For google searches, double-check that we’re on the `/search` path.

Google tracks outgoing external links through urls like https://www.google.com/url?q=https://nytimes.com

By checking that the url path starts with `/search` if we detect a google url, we can prevent other paths from being hijacked by the extension.

Tested the following urls:
https://www.google.com/url?q=https://nytimes.com/ => does not redirect
https://www.google.com/search?q=https://nytimes.com/ => does redirect

Verified that using Bing and DuckDuckGo continues to work as before.

Fixes: https://kagifeedback.org/d/3120-safari-extension-is-starting-to-hijack-all-google-links-again

* Bump version
  • Loading branch information
workwithnano authored Feb 16, 2024
1 parent 4662daf commit 29d3c2a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions safari/Universal/MainConfig.xcconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MARKETING_VERSION = 2.2.0
CURRENT_PROJECT_VERSION = 21 // this needs to be increased with each version change as well (not set to 1 when version is updated)
MARKETING_VERSION = 2.2.1
CURRENT_PROJECT_VERSION = 22 // this needs to be increased with each version change as well (not set to 1 when version is updated)
PRODUCT_NAME = Kagi for Safari
4 changes: 3 additions & 1 deletion safari/Universal/Shared (Extension)/Resources/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ function captureQuery(a) {
var b = a.host;
b.startsWith(www) && (b = b.slice(www.length));
b.endsWith(yahoo) && (b = yahoo);
if (b in builtInEngines && (a = (new URLSearchParams(a.search)).get(builtInEngines[b]))) return a;
const path = a.pathname;
var shouldBlockGoogleNonSearch = (b in googleUrls && !(path.startsWith("/search")));
if (b in builtInEngines && !(shouldBlockGoogleNonSearch) && (a = (new URLSearchParams(a.search)).get(builtInEngines[b]))) return a;
}

function rewriteQueryURL(a, b) {
Expand Down

0 comments on commit 29d3c2a

Please sign in to comment.