Skip to content

Commit

Permalink
Fix inability to open Gmail when using reduce-tracking-mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
shamazmazum committed May 23, 2024
1 parent 63fa20d commit c9ad719
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions source/mode/reduce-tracking.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,36 @@ 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=1209600&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:-> 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."
(format
nil "~{~a~^&~}"
(reduce
(lambda (param acc)
(if (member (car param) forbidden-params :test #'string-equal) acc
(cons (format nil "~a=~a" (car param) (cdr param)) acc)))
(quri:url-decode-params params :lenient t)
:initial-value nil
:from-end t)))

(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 c9ad719

Please sign in to comment.