about summary refs log tree commit diff
path: root/app/lib/sanitize_config.rb
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-19 10:16:33 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-19 10:16:33 -0500
commitbc22ab034bb9bbb48fb2cc93c1a617cbcd14ff9d (patch)
treebc54ec5e2e2dc59fc756ee229444a2103d1be3f3 /app/lib/sanitize_config.rb
parent23c36c2d7cdd02106f30fa3d9e049212b08ae5cd (diff)
move query string sanitizer to its own module & sanitize link cards as well
Diffstat (limited to 'app/lib/sanitize_config.rb')
-rw-r--r--app/lib/sanitize_config.rb33
1 files changed, 4 insertions, 29 deletions
diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb
index c3b0504e4..38dcd87b7 100644
--- a/app/lib/sanitize_config.rb
+++ b/app/lib/sanitize_config.rb
@@ -1,6 +1,8 @@
 # frozen_string_literal: true
 
 class Sanitize
+  extend UrlHelper
+
   module Config
     HTTP_PROTOCOLS ||= ['http', 'https', 'dat', 'dweb', 'ipfs', 'ipns', 'ssb', 'gopher', :relative].freeze
 
@@ -91,35 +93,8 @@ class Sanitize
       node = env[:node]
       ['href', 'src', 'cite'].each do |attr|
         next if node[attr].blank?
-        url = Addressable::URI.parse(node[attr])
-        next if url.query.blank?
-        params = CGI.parse(url.query)
-        params.delete_if do |key|
-          k = key.downcase
-          next true if k.start_with?(
-            '_hs',
-            'ic',
-            'mc_',
-            'mkt_',
-            'ns_',
-            'sr_',
-            'utm',
-            'vero_',
-            'nr_',
-            'ref',
-          )
-          next true if 'track'.in?(k)
-          next true if [
-            'fbclid',
-            'gclid',
-            'ncid',
-            'ocid',
-            'r',
-            'spm',
-          ].include?(k)
-          false
-        end
-        url.query = URI.encode_www_form(params)
+        url = Sanitize::sanitize_query_string(node[attr])
+        next if url.blank?
         node[attr] = url
       end
     end