Skip to content

Commit

Permalink
mode/reduce-tracking: Fix inability to open Gmail when using reduce-t…
Browse files Browse the repository at this point in the history
…racking-mode.
  • Loading branch information
shamazmazum committed May 23, 2024
1 parent 63fa20d commit a59d1c9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions nyxt.asd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
plump
clss
spinneret
split-sequence
slynk
slynk/arglists
slynk/fancy-inspector
Expand Down
44 changes: 38 additions & 6 deletions source/mode/reduce-tracking.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,47 @@ still being less noticeable in the crowd.")
:export nil
:documentation "The timezone the system had before enabling this mode.")))

;; NB: QURI:URL-ENCODE-PARAMS is not applicable for filtering a
;; query. For example, when opening Gmail a query may look like
;; "https://accounts.google.com/ServiceLogin?service=mail&passive=XXXXXX&osid=1&continue=https://mail.google.com"
;; and quri will percent-encode it to
;; https://accounts.google.com/ServiceLogin?service=mail&passive=1209600&osid=1&continue=https%3A%2F%2Fmail.google.com
;; This is incorrect and will result in inability to load the
;; page. This function does not add an extra level of percent
;; encoding.
(serapeum:-> decode-params-lite (string)
(values list &optional))
(defun decode-params-lite (query)
(mapcar
(alex:curry #'split-sequence:split-sequence #\=)
(split-sequence:split-sequence #\& query)))

(serapeum:-> encode-params-lite (list)
(values string &optional))
(defun encode-params-lite (string)
(format
nil "~{~a~^&~}"
(mapcar
(alex:curry #'format nil "~{~a~^=~}")
string)))

(serapeum:-> url-filter-params (string list)
(values string &optional))
(defun url-filter-params (params forbidden-params)
"Accept a query parameters (as a string), remove parameters from a
black list and return them back as a string."
(encode-params-lite
(remove-if (rcurry #'member forbidden-params :test #'string-equal)
(decode-params-lite params)
:key #'first)))

(defun strip-tracking-parameters (request-data)
(let ((mode (find-submode 'reduce-tracking-mode)))
(when (and mode (not (uiop:emptyp (quri:uri-query (url request-data)))))
(setf (quri:uri-query-params (url request-data))
(remove-if (rcurry #'member (query-tracking-parameters mode)
:test #'string-equal)
(quri:url-decode-params (quri:uri-query (url request-data)) :lenient t)
:key #'first)))
request-data))
(setf (quri:uri-query (url request-data))
(url-filter-params (quri:uri-query (url request-data))
(query-tracking-parameters mode)))))
request-data)

(defmethod enable ((mode reduce-tracking-mode) &key)
(setf (old-timezone mode) (uiop:getenv "TZ")
Expand Down

0 comments on commit a59d1c9

Please sign in to comment.