├── .circleci └── config.yml ├── .eslintrc.yml ├── .github └── workflows │ ├── codeql-analysis.yml │ └── ossar-analysis.yml ├── .gitignore ├── .husky ├── .gitignore ├── post-merge ├── pre-commit └── pre-push ├── .lintstagedrc.yml ├── .npmignore ├── .npmrc ├── .nvmrc ├── .prettierrc.yml ├── LICENSE ├── README.md ├── bin └── normalize.js ├── data ├── README.md ├── __mocks__ │ └── loader.js ├── data.minify.json └── loader.js ├── esm-resolver.cjs ├── index.js ├── jest.config.cjs ├── package-lock.json ├── package.json ├── renovate.json └── utils ├── __fixtures__ └── empty-cache.js ├── __mocks__ └── strip-trackers.js ├── canonicize.js ├── canonicize.test.js ├── dns-lookup.js ├── http-client.js ├── logger.js ├── normalize-url.js ├── normalize-url.test.js ├── strip-trackers.js ├── strip-trackers.test.js └── url-is-amp.js /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | aliases: 4 | - &runner 5 | executor: 6 | name: node/default 7 | tag: << parameters.node-version >> 8 | - &size 9 | resource_class: small 10 | - ¶ms 11 | parameters: 12 | node-version: 13 | type: string 14 | 15 | orbs: 16 | node: circleci/node@5 17 | slack: circleci/slack@4 18 | codecov: codecov/codecov@4 19 | 20 | jobs: 21 | lint: 22 | <<: *runner 23 | <<: *size 24 | <<: *params 25 | steps: 26 | - checkout 27 | - node/install-packages 28 | - run: npm run lint:prettier 29 | - run: npm run lint:eslint -- --format junit --output-file reports/eslint/results.xml 30 | test: 31 | <<: *runner 32 | <<: *size 33 | <<: *params 34 | steps: 35 | - checkout 36 | - node/install-packages 37 | - run: npm test -- --ci --coverage # reports automatically generated 38 | 39 | workflows: 40 | build: 41 | jobs: 42 | - lint: 43 | node-version: lts 44 | post-steps: 45 | - &retrieve-junit 46 | store_test_results: 47 | path: reports 48 | - test: 49 | context: shared-vars 50 | requires: 51 | - lint 52 | matrix: 53 | parameters: 54 | node-version: 55 | - lts 56 | - current 57 | post-steps: 58 | - *retrieve-junit 59 | - codecov/upload # don't need token for public repos 60 | - slack/notify: 61 | event: fail 62 | template: basic_fail_1 63 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | extends: 2 | - '@janejeon' 3 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: 'CodeQL' 13 | 14 | on: 15 | push: 16 | branches: [master] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [master] 20 | schedule: 21 | - cron: '34 11 * * 0' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: ['javascript'] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v4 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v3 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v3 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v3 72 | -------------------------------------------------------------------------------- /.github/workflows/ossar-analysis.yml: -------------------------------------------------------------------------------- 1 | # This workflow integrates a collection of open source static analysis tools 2 | # with GitHub code scanning. For documentation, or to provide feedback, visit 3 | # https://github.com/github/ossar-action 4 | name: OSSAR 5 | 6 | on: 7 | push: 8 | branches: [master] 9 | pull_request: 10 | # The branches below must be a subset of the branches above 11 | branches: [master] 12 | schedule: 13 | - cron: '31 11 * * 1' 14 | 15 | jobs: 16 | OSSAR-Scan: 17 | # OSSAR runs on windows-latest. 18 | # ubuntu-latest and macos-latest support coming soon 19 | runs-on: windows-latest 20 | 21 | steps: 22 | - name: Checkout repository 23 | uses: actions/checkout@v4 24 | 25 | # Ensure a compatible version of dotnet is installed. 26 | # The [Microsoft Security Code Analysis CLI](https://aka.ms/mscadocs) is built with dotnet v3.1.201. 27 | # A version greater than or equal to v3.1.201 of dotnet must be installed on the agent in order to run this action. 28 | # GitHub hosted runners already have a compatible version of dotnet installed and this step may be skipped. 29 | # For self-hosted runners, ensure dotnet version 3.1.201 or later is installed by including this action: 30 | # - name: Install .NET 31 | # uses: actions/setup-dotnet@v1 32 | # with: 33 | # dotnet-version: '3.1.x' 34 | # Run open source static analysis tools 35 | - name: Run OSSAR 36 | uses: github/ossar-action@v1 37 | id: ossar 38 | 39 | # Upload results to the Security tab 40 | - name: Upload OSSAR results 41 | uses: github/codeql-action/upload-sarif@v3 42 | with: 43 | sarif_file: ${{ steps.ossar.outputs.sarifFile }} 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | reports/ 107 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/post-merge: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npm i 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /.husky/pre-push: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx skip-ci && echo "Skipping test..." || CI=1 npm test 5 | -------------------------------------------------------------------------------- /.lintstagedrc.yml: -------------------------------------------------------------------------------- 1 | '*': 2 | - prettier --write --ignore-unknown 3 | 4 | '*.js': 5 | - eslint --fix 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.cjs 3 | **/*.md 4 | **/*.yml 5 | **/*.test.js 6 | **/__mocks__ 7 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | audit=false 2 | fund=false 3 | engine-strict=true 4 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | lts/* 2 | -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | '@janejeon/prettier-config' 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Welcome to normalize-url-plus 👋

2 | 3 | [![CircleCI](https://circleci.com/gh/JaneJeon/normalize-url-plus/tree/master.svg?style=shield)](https://circleci.com/gh/JaneJeon/normalize-url-plus/tree/master) 4 | [![codecov](https://codecov.io/gh/JaneJeon/normalize-url-plus/branch/master/graph/badge.svg)](https://codecov.io/gh/JaneJeon/normalize-url-plus) 5 | [![Version](https://img.shields.io/npm/v/normalize-url-plus)](https://www.npmjs.com/package/normalize-url-plus) 6 | [![Downloads](https://img.shields.io/npm/dt/normalize-url-plus)](https://www.npmjs.com/package/normalize-url-plus) 7 | 8 | > normalize-url plus additional features to supercharge link normalization! 9 | 10 | While `normalize-url` is good enough for many normalization use cases, this library is akin to prettier or black in that it ABSOLUTELY normalizes links, including features like default www-stripping and default https (both of which fall back should such links do not exist - unlike `normalize-url`), stripping ALL trackers (courtesy of clearURLs), following redirects (even those that can't normally be automatically redirected without manual user intervention such as youtube redirect links), and even extracting canonical URLs, all the while securing your servers from SSRF! 11 | 12 | ### 🏠 [Homepage](https://github.com/JaneJeon/normalize-url-plus) 13 | 14 | ## Install 15 | 16 | ```sh 17 | npm i normalize-url-plus 18 | ``` 19 | 20 | ## Usage 21 | 22 | Note that this package is ESM-only; see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for what to do if you're using CJS (i.e. `require()`). 23 | 24 | ```js 25 | import gen from 'normalize-url-plus' 26 | const normalizeUrl = gen(normalizeUrlOptions, gotOptions) // it is recommended to fill out the caching options for got 27 | 28 | const longDisgustingTrackerFilledLink = 29 | 'https://www.amazon.com/Blanket-Fleece-Cartoon-Printing-Napping/dp/B089G4JDVB/ref=sr_1_1?keywords=hello%20kitty&sr=8-1' // eww 30 | await normalizeUrl(longDisgustingTrackerFilledLink) // https://amazon.com/Blanket-Fleece-Cartoon-Printing-Napping/dp/B089G4JDVB 31 | ``` 32 | 33 | ## Run tests 34 | 35 | ```sh 36 | npm test 37 | ``` 38 | 39 | ## Author 40 | 41 | 👤 **Jane Jeon ** 42 | 43 | - Website: janejeon.dev 44 | - Github: [@JaneJeon](https://github.com/JaneJeon) 45 | 46 | ## 🤝 Contributing 47 | 48 | Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/JaneJeon/normalize-url-plus/issues). 49 | 50 | ## Show your support 51 | 52 | Give a ⭐️ if this project helped you! 53 | 54 | ## 📝 License 55 | 56 | Copyright © 2022 [Jane Jeon ](https://github.com/JaneJeon).
57 | This project is [LGPL-3.0](https://github.com/JaneJeon/normalize-url-plus/blob/main/LICENSE) licensed. 58 | 59 | TL;DR: you are free to import and use this library "as-is" in your code, without needing to make your code source-available or to license it under the same license as this library; however, if you do change this library and you distribute it (directly or as part of your code consuming this library), please do contribute back any improvements for this library and this library alone. 60 | -------------------------------------------------------------------------------- /bin/normalize.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* eslint-disable no-console */ 3 | 4 | import gen from '../index.js' 5 | const normalize = gen() 6 | const [, , ...args] = process.argv 7 | 8 | ;(async () => { 9 | console.log(await normalize(args[0])) 10 | })() 11 | -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | The file `data.minify.json` is the "reference" version of the filter list provided by ClearURLs: https://rules2.clearurls.xyz/data.minify.json. 2 | 3 | You can update the file by running `npm run update-data` from the top level folder of this repository. 4 | -------------------------------------------------------------------------------- /data/__mocks__/loader.js: -------------------------------------------------------------------------------- 1 | export default function loadRuleset() { 2 | return [ 3 | { 4 | urlPattern: '^https://thisshouldthrow.com', 5 | completeProvider: true 6 | }, 7 | { 8 | urlPattern: '^https://thisshouldmatch.com', 9 | rules: ['fuckthis'], 10 | exceptions: ['^https://thisshouldmatch.com/butnotthis'] 11 | }, 12 | { 13 | urlPattern: '^https://trackerstripping.com', 14 | rules: ['rule'], 15 | referralMarketing: ['rawRule'] 16 | }, 17 | { 18 | urlPattern: '^https://www.amazon.com', 19 | rawRules: ['\\/ref=[^/?]*'] 20 | }, 21 | { 22 | urlPattern: '^https?:\\/\\/(?:[a-z0-9-]+\\.)*?youtube\\.com', 23 | rules: ['feature', 'gclid', 'kw'], 24 | redirections: [ 25 | '^https?:\\/\\/(?:[a-z0-9-]+\\.)*?youtube\\.com\\/redirect?.*?q=([^&]*)' 26 | ] 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /data/data.minify.json: -------------------------------------------------------------------------------- 1 | { 2 | "providers": { 3 | "amazon": { 4 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon(?:\\.[a-z]{2,}){1,}", 5 | "rules": [ 6 | "p[fd]_rd_[a-z]*", 7 | "qid", 8 | "srs?", 9 | "__mk_[a-z]{1,3}_[a-z]{1,3}", 10 | "spIA", 11 | "ms3_c", 12 | "[a-z%0-9]*ie", 13 | "refRID", 14 | "colii?d", 15 | "[^a-z%0-9]adId", 16 | "qualifier", 17 | "_encoding", 18 | "smid", 19 | "field-lbr_brands_browse-bin", 20 | "ref_?", 21 | "th", 22 | "sprefix", 23 | "crid", 24 | "keywords", 25 | "cv_ct_[a-z]+", 26 | "linkCode", 27 | "creativeASIN", 28 | "ascsubtag", 29 | "aaxitk", 30 | "hsa_cr_id", 31 | "sb-ci-[a-z]+", 32 | "rnid", 33 | "dchild", 34 | "camp", 35 | "creative", 36 | "s" 37 | ], 38 | "rawRules": ["\\/ref=[^/?]*"], 39 | "referralMarketing": ["tag"], 40 | "exceptions": [ 41 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon(?:\\.[a-z]{2,}){1,}\\/gp\\/.*?(?:redirector.html|cart\\/ajax-update.html|video\\/api\\/)", 42 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon(?:\\.[a-z]{2,}){1,}\\/(?:hz\\/reviews-render\\/ajax\\/|message-us\\?|s\\?)" 43 | ] 44 | }, 45 | "amazon search": { 46 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon(?:\\.[a-z]{2,}){1,}\\/s\\?", 47 | "rules": [ 48 | "p[fd]_rd_[a-z]*", 49 | "qid", 50 | "srs?", 51 | "__mk_[a-z]{1,3}_[a-z]{1,3}", 52 | "spIA", 53 | "ms3_c", 54 | "[a-z%0-9]*ie", 55 | "refRID", 56 | "colii?d", 57 | "[^a-z%0-9]adId", 58 | "qualifier", 59 | "_encoding", 60 | "smid", 61 | "field-lbr_brands_browse-bin", 62 | "ref_?", 63 | "th", 64 | "sprefix", 65 | "crid", 66 | "keywords", 67 | "cv_ct_[a-z]+", 68 | "linkCode", 69 | "creativeASIN", 70 | "ascsubtag", 71 | "aaxitk", 72 | "hsa_cr_id", 73 | "sb-ci-[a-z]+", 74 | "rnid", 75 | "dchild", 76 | "camp", 77 | "creative" 78 | ], 79 | "rawRules": ["\\/ref=[^/?]*"], 80 | "referralMarketing": ["tag"] 81 | }, 82 | "fls-na.amazon": { 83 | "completeProvider": true, 84 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?fls-na\\.amazon(?:\\.[a-z]{2,}){1,}" 85 | }, 86 | "google": { 87 | "forceRedirection": true, 88 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}", 89 | "rules": [ 90 | "ved", 91 | "bi[a-z]*", 92 | "gfe_[a-z]*", 93 | "ei", 94 | "source", 95 | "gs_[a-z]*", 96 | "site", 97 | "oq", 98 | "esrc", 99 | "uact", 100 | "cd", 101 | "cad", 102 | "gws_[a-z]*", 103 | "atyp", 104 | "vet", 105 | "zx", 106 | "_u", 107 | "je", 108 | "dcr", 109 | "ie", 110 | "sei", 111 | "sa", 112 | "dpr", 113 | "btn[a-z]*", 114 | "usg", 115 | "cd", 116 | "cad", 117 | "uact", 118 | "aqs", 119 | "sourceid", 120 | "sxsrf", 121 | "rlz", 122 | "i-would-rather-use-firefox" 123 | ], 124 | "referralMarketing": ["referrer"], 125 | "exceptions": [ 126 | "^https?:\\/\\/mail\\.google\\.com\\/mail\\/u\\/", 127 | "^https?:\\/\\/(?:docs|accounts)\\.google(?:\\.[a-z]{2,}){1,}", 128 | "^https?:\\/\\/drive\\.google\\.com\\/videoplayback", 129 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}(?:\\/upload)?\\/drive\\/", 130 | "^https?:\\/\\/news\\.google\\.com.*\\?hl=.", 131 | "^https?:\\/\\/hangouts\\.google\\.com\\/webchat.*?zx=.", 132 | "^https?:\\/\\/client-channel\\.google\\.com\\/client-channel.*?zx=.", 133 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}\\/s\\?tbm=map.*?gs_[a-z]*=.", 134 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}\\/(?:complete\\/search|setprefs|searchbyimage)", 135 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}\\/(?:appsactivity|aclk\\?)" 136 | ], 137 | "redirections": [ 138 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}\\/url\\?.*?(?:url|q)=(https?[^&]+)", 139 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}\\/.*?adurl=([^&]+)", 140 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}\\/amp\\/s\\/([^&]+)" 141 | ] 142 | }, 143 | "googleSearch": { 144 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?google(?:\\.[a-z]{2,}){1,}\\/search\\?", 145 | "rules": ["client", "sclient"] 146 | }, 147 | "googlesyndication": { 148 | "completeProvider": true, 149 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?googlesyndication\\.com" 150 | }, 151 | "doubleclick": { 152 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?doubleclick(?:\\.[a-z]{2,}){1,}", 153 | "redirections": [ 154 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?doubleclick(?:\\.[a-z]{2,}){1,}\\/.*?tag_for_child_directed_treatment=;%3F([^&]*)" 155 | ] 156 | }, 157 | "googleadservices": { 158 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?googleadservices\\.com", 159 | "redirections": [ 160 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?googleadservices\\.com\\/.*?adurl=([^&]*)" 161 | ] 162 | }, 163 | "globalRules": { 164 | "urlPattern": ".*", 165 | "rules": [ 166 | "(?:%3F)?utm(?:_[a-z_]*)?", 167 | "(?:%3F)?ga_[a-z_]+", 168 | "(?:%3F)?yclid", 169 | "(?:%3F)?_openstat", 170 | "(?:%3F)?fb_action_(?:types|ids)", 171 | "(?:%3F)?fb_(?:source|ref)", 172 | "(?:%3F)?fbclid", 173 | "(?:%3F)?action_(?:object|type|ref)_map", 174 | "(?:%3F)?gs_l", 175 | "(?:%3F)?mkt_tok", 176 | "(?:%3F)?hmb_(?:campaign|medium|source)", 177 | "(?:%3F)?ref_?", 178 | "(?:%3F)?referrer", 179 | "(?:%3F)?gclid", 180 | "(?:%3F)?otm_[a-z_]*", 181 | "(?:%3F)?cmpid", 182 | "(?:%3F)?os_ehash", 183 | "(?:%3F)?_ga", 184 | "(?:%3F)?__twitter_impression", 185 | "(?:%3F)?wt_?z?mc", 186 | "(?:%3F)?wtrid", 187 | "(?:%3F)?[a-z]?mc", 188 | "(?:%3F)?dclid", 189 | "Echobox", 190 | "(?:%3F)?spm", 191 | "(?:%3F)?vn(?:_[a-z]*)+", 192 | "(?:%3F)?tracking_source" 193 | ], 194 | "exceptions": [ 195 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?matrix\\.org\\/_matrix\\/", 196 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?(?:cloudflare\\.com|prismic\\.io|tangerine\\.ca|gitlab\\.com)", 197 | "^https?:\\/\\/myaccount.google(?:\\.[a-z]{2,}){1,}", 198 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?gcsip\\.(?:com|nl)[^?]*\\?.*?&?ref_?=.", 199 | "^https?:\\/\\/[^/]+/[^/]+/[^/]+\\/-\\/refs\\/switch[^?]*\\?.*?&?ref_?=.", 200 | "^https?:\\/\\/bugtracker\\.[^/]*\\/[^?]+\\?.*?&?ref_?=[^/?&]*", 201 | "^https?:\\/\\/comment-cdn\\.9gag\\.com\\/.*?comment-list.json\\?", 202 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?battle\\.net\\/login", 203 | "^https?:\\/\\/blizzard\\.com\\/oauth2", 204 | "^https?:\\/\\/kreditkarten-banking\\.lbb\\.de", 205 | "^https?:\\/\\/www\\.tinkoff\\.ru", 206 | "^https?:\\/\\/www\\.cyberport\\.de\\/adscript\\.php", 207 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tweakers\\.net\\/ext\\/lt\\.dsp\\?.*?(?:%3F)?&?ref_?=.", 208 | "^https?:\\/\\/git\\.[^/]*\\/[^?]+\\?.*?&?ref_?=[^/?&]*", 209 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon(?:\\.[a-z]{2,}){1,}\\/message-us\\?", 210 | "^https?:\\/\\/authorization\\.td\\.com", 211 | "^https?:\\/\\/support\\.steampowered\\.com", 212 | "^https?:\\/\\/privacy\\.vakmedianet\\.nl\\/.*?ref=", 213 | "^https?:\\/\\/sso\\.serverplan\\.com\\/manage2fa\\/check\\?ref=", 214 | "^https?:\\/\\/login\\.meijer\\.com\\/.*?\\?ref=", 215 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/(?:login_alerts|ajax|should_add_browser)/", 216 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/groups\\/member_bio\\/bio_dialog\\/", 217 | "^https?:\\/\\/api\\.taiga\\.io", 218 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?gog\\.com\\/click\\.html", 219 | "^https?:\\/\\/login\\.progressive\\.com", 220 | "^https?:\\/\\/www\\.sephora\\.com\\/api\\/", 221 | "^https?:\\/\\/www\\.contestgirl\\.com", 222 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?agenciatributaria\\.gob\\.es", 223 | "^https?:\\/\\/login\\.ingbank\\.pl", 224 | "^wss?:\\/\\/(?:[a-z0-9-]+\\.)*?zoom\\.us", 225 | "^https?:\\/\\/api\\.bilibili\\.com", 226 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?onet\\.pl\\/[^?]*\\?.*?utm_campaign=.", 227 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?stripe\\.com\\/[^?]+.*?&?referrer=[^/?&]*" 228 | ] 229 | }, 230 | "adtech": { 231 | "completeProvider": true, 232 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?adtech(?:\\.[a-z]{2,}){1,}" 233 | }, 234 | "contentpass": { 235 | "completeProvider": true, 236 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?contentpass\\.(?:net|de)" 237 | }, 238 | "bf-ad": { 239 | "completeProvider": true, 240 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bf-ad(?:\\.[a-z]{2,}){1,}" 241 | }, 242 | "amazon-adsystem": { 243 | "completeProvider": true, 244 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon-adsystem(?:\\.[a-z]{2,}){1,}", 245 | "exceptions": [ 246 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon-adsystem(?:\\.[a-z]{2,}){1,}\\/v3\\/oor\\?" 247 | ], 248 | "redirections": [ 249 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?amazon-adsystem(?:\\.[a-z]{2,}){1,}\\/x\\/c\\/.+?\\/([^&]+)" 250 | ] 251 | }, 252 | "adsensecustomsearchads": { 253 | "completeProvider": true, 254 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?adsensecustomsearchads(?:\\.[a-z]{2,}){1,}" 255 | }, 256 | "youtube": { 257 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?youtube\\.com", 258 | "rules": ["feature", "gclid", "kw"], 259 | "redirections": [ 260 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?youtube\\.com\\/redirect?.*?q=([^&]*)" 261 | ] 262 | }, 263 | "youtube_pagead": { 264 | "completeProvider": true, 265 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?youtube\\.com\\/pagead" 266 | }, 267 | "youtube_apiads": { 268 | "completeProvider": true, 269 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?youtube\\.com\\/api\\/stats\\/ads" 270 | }, 271 | "facebook": { 272 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com", 273 | "rules": [ 274 | "hc_[a-z_%\\[\\]0-9]*", 275 | "[a-z]*ref[a-z]*", 276 | "__tn__", 277 | "eid", 278 | "__xts__(?:\\[|%5B)\\d(?:\\]|%5D)", 279 | "comment_tracking", 280 | "dti", 281 | "app", 282 | "video_source", 283 | "ftentidentifier", 284 | "pageid", 285 | "padding", 286 | "ls_ref", 287 | "action_history" 288 | ], 289 | "exceptions": [ 290 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/.*?(plugins|ajax)\\/", 291 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/dialog\\/(?:share|send)", 292 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/groups\\/member_bio\\/bio_dialog\\/", 293 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/photo\\.php\\?", 294 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/privacy\\/specific_audience_selector_dialog\\/", 295 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?facebook\\.com\\/photo\\/download\\/" 296 | ], 297 | "redirections": [ 298 | "^https?:\\/\\/l[a-z]?\\.facebook\\.com/l\\.php\\?.*?u=(https?%3A%2F%2F[^&]*)" 299 | ] 300 | }, 301 | "twitter": { 302 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?twitter.com", 303 | "rules": ["(?:ref_?)?src", "s", "cn", "ref_url"] 304 | }, 305 | "reddit": { 306 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?reddit.com", 307 | "rules": [ 308 | "%24deep_link", 309 | "\\$deep_link", 310 | "correlation_id", 311 | "ref_campaign", 312 | "ref_source", 313 | "%243p", 314 | "\\$3p", 315 | "%24original_url", 316 | "\\$original_url", 317 | "_branch_match_id" 318 | ], 319 | "redirections": ["^https?:\\/\\/out\\.reddit\\.com\\/.*?url=([^&]*)"] 320 | }, 321 | "netflix": { 322 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?netflix.com", 323 | "rules": ["trackId", "tctx", "jb[a-z]*?"] 324 | }, 325 | "techcrunch": { 326 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?techcrunch\\.com", 327 | "rules": ["ncid", "sr", "sr_share"] 328 | }, 329 | "bing": { 330 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bing(?:\\.[a-z]{2,}){1,}", 331 | "rules": ["cvid", "form", "sk", "sp", "sc", "qs", "qp"], 332 | "exceptions": [ 333 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bing(?:\\.[a-z]{2,}){1,}\\/WS\\/redirect\\/" 334 | ] 335 | }, 336 | "tweakers": { 337 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tweakers\\.net", 338 | "rules": ["nb", "u"] 339 | }, 340 | "twitch": { 341 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?twitch\\.com", 342 | "rules": ["tt_medium", "tt_content"] 343 | }, 344 | "vivaldi": { 345 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?vivaldi\\.com", 346 | "rules": ["pk_campaign", "pk_kwd"] 347 | }, 348 | "indeed": { 349 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?indeed\\.com", 350 | "rules": ["from", "alid", "[a-z]*tk"], 351 | "exceptions": ["^https?:\\/\\/(?:[a-z0-9-]+\\.)*?indeed\\.com\\/rc\\/clk"] 352 | }, 353 | "hhdotru": { 354 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?hh\\.ru", 355 | "rules": ["vss", "t", "swnt", "grpos", "ptl", "stl", "exp", "plim"] 356 | }, 357 | "ebay": { 358 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?ebay(?:\\.[a-z]{2,}){1,}", 359 | "rules": ["_trkparms", "_trksid", "_from", "hash"], 360 | "redirections": [ 361 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?rover\\.ebay(?:\\.[a-z]{2,}){1,}\\/rover.*mpre=([^&]*)" 362 | ] 363 | }, 364 | "cnet": { 365 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?cnet\\.com", 366 | "rules": ["ftag"] 367 | }, 368 | "imdb.com": { 369 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?imdb\\.com", 370 | "rules": ["ref_", "pf_rd_[a-z]*"] 371 | }, 372 | "govdelivery.com": { 373 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?govdelivery\\.com", 374 | "redirections": [ 375 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?links\\.govdelivery\\.com.*\\/track\\?.*(https?:\\/\\/.*)" 376 | ] 377 | }, 378 | "walmart.com": { 379 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?walmart\\.com", 380 | "rules": ["u1", "ath[a-z]*"] 381 | }, 382 | "net-parade.it": { 383 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?net\\-parade\\.it", 384 | "rules": ["pl"] 385 | }, 386 | "prvnizpravy.cz": { 387 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?prvnizpravy\\.cz", 388 | "rules": ["xid"] 389 | }, 390 | "youku.com": { 391 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?youku\\.com", 392 | "rules": ["tpa"] 393 | }, 394 | "nytimes.com": { 395 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?nytimes\\.com", 396 | "rules": ["smid"] 397 | }, 398 | "tchibo.de": { 399 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tchibo\\.de", 400 | "rules": ["wbdcd"] 401 | }, 402 | "steampowered": { 403 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?steampowered\\.com", 404 | "rules": ["snr"] 405 | }, 406 | "steamcommunity": { 407 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?steamcommunity\\.com", 408 | "redirections": [ 409 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?steamcommunity\\.com\\/linkfilter\\/\\?url=([^&]*)" 410 | ] 411 | }, 412 | "mozaws.net": { 413 | "urlPattern": "https?:\\/\\/outgoing\\.prod\\.mozaws\\.net\\/", 414 | "redirections": ["https?:\\/\\/[^/]+\\/v1\\/[0-9a-f]{64}\\/(.*)"] 415 | }, 416 | "shutterstock.com": { 417 | "urlPattern": "https?:\\/\\/([a-z0-9-.]*\\.)shutterstock\\.com", 418 | "rules": ["src"] 419 | }, 420 | "mozilla.org": { 421 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?mozilla\\.org", 422 | "rules": ["src", "platform", "redirect_source"], 423 | "exceptions": ["^https?:\\/\\/(?:[a-z0-9-]+\\.)*?mozilla.org\\/api"] 424 | }, 425 | "readdc.com": { 426 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?readdc\\.com", 427 | "rules": ["ref"] 428 | }, 429 | "dailycodingproblem.com": { 430 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?dailycodingproblem\\.com", 431 | "rules": ["email"] 432 | }, 433 | "github.com": { 434 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?github\\.com", 435 | "rules": ["email_token", "email_source"] 436 | }, 437 | "deviantart.com": { 438 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?deviantart\\.com", 439 | "redirections": [ 440 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?deviantart\\.com\\/.*?\\/outgoing\\?(.*)" 441 | ] 442 | }, 443 | "site2.com": { 444 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?site2\\.com", 445 | "redirections": [ 446 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?site2\\.com.*?\\?.*=(.*)" 447 | ] 448 | }, 449 | "site.com": { 450 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?site\\.com", 451 | "redirections": [ 452 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?site\\.com.*?\\?to=([^&]*)" 453 | ] 454 | }, 455 | "site3.com": { 456 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?site3\\.com", 457 | "redirections": [ 458 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?site3\\.com.*?\\?r=([^&]*)" 459 | ] 460 | }, 461 | "aliexpress": { 462 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?aliexpress(?:\\.[a-z]{2,}){1,}", 463 | "rules": [ 464 | "ws_ab_test", 465 | "btsid", 466 | "algo_expid", 467 | "algo_pvid", 468 | "gps-id", 469 | "scm[_a-z-]*", 470 | "cv", 471 | "af", 472 | "mall_affr", 473 | "sk", 474 | "dp", 475 | "terminal_id", 476 | "aff_request_id" 477 | ] 478 | }, 479 | "mozillazine.org": { 480 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?mozillazine\\.org", 481 | "rules": ["sid"] 482 | }, 483 | "9gag.com": { 484 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?9gag\\.com", 485 | "rules": ["ref"], 486 | "exceptions": [ 487 | "^https?:\\/\\/comment-cdn\\.9gag\\.com\\/.*?comment-list.json\\?" 488 | ] 489 | }, 490 | "linksynergy.com": { 491 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?linksynergy\\.com", 492 | "redirections": [ 493 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?linksynergy\\.com\\/.*?murl=([^&]*)" 494 | ] 495 | }, 496 | "giphy.com": { 497 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?giphy\\.com", 498 | "rules": ["ref"] 499 | }, 500 | "gate.sc": { 501 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?gate\\.sc", 502 | "redirections": [ 503 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?gate\\.sc\\/.*?url=([^&]*)" 504 | ] 505 | }, 506 | "vk.com": { 507 | "urlPattern": "^https?:\\/\\/vk\\.com", 508 | "redirections": ["^https?:\\/\\/vk\\.com\\/away\\.php\\?to=([^&]*)"] 509 | }, 510 | "woot.com": { 511 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?woot\\.com", 512 | "rules": ["ref_?"] 513 | }, 514 | "vitamix.com": { 515 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?vitamix\\.com", 516 | "rules": ["_requestid", "cid", "dl", "di", "sd", "bi"] 517 | }, 518 | "curseforge.com": { 519 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?curseforge\\.com", 520 | "redirections": [ 521 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?curseforge\\.com\\/linkout\\?remoteUrl=([^&]*)" 522 | ] 523 | }, 524 | "messenger.com": { 525 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?messenger\\.com", 526 | "redirections": [ 527 | "^https?:\\/\\/l\\.messenger\\.com\\/l\\.php\\?u=([^&]*)" 528 | ] 529 | }, 530 | "nypost.com": { 531 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?nypost\\.com", 532 | "rules": ["__twitter_impression"] 533 | }, 534 | "ozon.ru": { 535 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?ozon\\.ru", 536 | "rules": ["partner"] 537 | }, 538 | "norml.org": { 539 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?norml\\.org", 540 | "rules": [ 541 | "link_id", 542 | "can_id", 543 | "source", 544 | "email_referrer", 545 | "email_subject" 546 | ] 547 | }, 548 | "LinkedIn": { 549 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?linkedin\\.com", 550 | "rules": ["refId", "trk", "li[a-z]{2}"] 551 | }, 552 | "LinkedIn Learning": { 553 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?linkedin\\.com\\/learning", 554 | "rules": ["u"] 555 | }, 556 | "smartredirect.de": { 557 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?smartredirect\\.de", 558 | "redirections": [ 559 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?smartredirect\\.de.*?url=([^&]*)" 560 | ] 561 | }, 562 | "SPIEGEL ONLINE": { 563 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?spiegel\\.de", 564 | "rules": ["b"] 565 | }, 566 | "rutracker.org": { 567 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?rutracker\\.org", 568 | "redirections": [".*url=([^&]*)"] 569 | }, 570 | "instagram": { 571 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?instagram\\.com", 572 | "rules": ["igshid"], 573 | "redirections": [".*u=([^&]*)"] 574 | }, 575 | "lazada.com.my": { 576 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?lazada\\.com\\.my", 577 | "rules": ["ad_src", "did", "pa", "mp", "impsrc", "cid", "pos"] 578 | }, 579 | "imgsrc.ru": { 580 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?imgsrc\\.ru", 581 | "redirections": [ 582 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?dlp\\.imgsrc\\.ru\\/go\\/\\d+\\/\\d+\\/\\d+\\/([^&]*)" 583 | ] 584 | }, 585 | "boredpanda.com": { 586 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?boredpanda\\.com", 587 | "rules": ["h"] 588 | }, 589 | "awstrack.me": { 590 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?awstrack\\.me", 591 | "redirections": [ 592 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?awstrack\\.me\\/.*\\/(https?.*)" 593 | ] 594 | }, 595 | "exactag.com": { 596 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?exactag\\.com", 597 | "redirections": [ 598 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?exactag\\.com.*url=([^&]*)" 599 | ] 600 | }, 601 | "bahn.de": { 602 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bahn\\.de", 603 | "rules": ["dbkanal_[0-9]{3}"] 604 | }, 605 | "disq.us": { 606 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?disq\\.us", 607 | "rules": ["cuid"], 608 | "redirections": [ 609 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?disq\\.us\\/.*?url=([^&]*)%3A" 610 | ] 611 | }, 612 | "anonym.to": { 613 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?anonym\\.to", 614 | "redirections": [ 615 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?anonym\\.to.*\\?([^&]*)" 616 | ] 617 | }, 618 | "moosejaw.com": { 619 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?moosejaw\\.com", 620 | "rules": [ 621 | "cm_lm", 622 | "cm_mmc", 623 | "webUserId", 624 | "spMailingID", 625 | "spUserID", 626 | "spJobID", 627 | "spReportId" 628 | ] 629 | }, 630 | "spotify.com": { 631 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?spotify\\.com", 632 | "rules": ["si"] 633 | }, 634 | "yandex": { 635 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?(?:yandex(?:\\.[a-z]{2,}){1,}|ya\\.ru)", 636 | "rules": ["lr", "redircnt"] 637 | }, 638 | "healio.com": { 639 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?healio\\.com", 640 | "rules": ["ecp", "m_bt"] 641 | }, 642 | "zoho.com": { 643 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?zoho\\.com", 644 | "rules": ["iref"] 645 | }, 646 | "snapchat.com": { 647 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?snapchat\\.com", 648 | "rules": ["sc_referrer", "sc_ua"] 649 | }, 650 | "medium.com": { 651 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?medium\\.com", 652 | "rules": ["source"] 653 | }, 654 | "swp.de": { 655 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?swp\\.de", 656 | "rules": ["source"] 657 | }, 658 | "wps.com": { 659 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?wps\\.com", 660 | "rules": ["from"] 661 | }, 662 | "accounts.firefox.com": { 663 | "urlPattern": "^https?:\\/\\/(?:accounts\\.)?firefox\\.com", 664 | "rules": ["context", "entrypoint", "form_type"] 665 | }, 666 | "support.mozilla.org": { 667 | "urlPattern": "^https?:\\/\\/(?:support\\.)?mozilla\\.org", 668 | "rules": ["as"] 669 | }, 670 | "ClearURLsTest": { 671 | "urlPattern": "^https?:\\/\\/kevinroebert\\.gitlab\\.io\\/ClearUrls\\/void\\/index\\.html", 672 | "rules": ["test"], 673 | "redirections": [ 674 | "^https?:\\/\\/kevinroebert\\.gitlab\\.io\\/ClearUrls\\/void\\/index\\.html\\?url=([^&]*)" 675 | ] 676 | }, 677 | "ClearURLsTestBlock": { 678 | "completeProvider": true, 679 | "urlPattern": "^https?:\\/\\/kevinroebert\\.gitlab\\.io\\/ClearUrls\\/void\\/block\\.svg" 680 | }, 681 | "ClearURLsTest2": { 682 | "urlPattern": "^https?:\\/\\/test\\.clearurls\\.xyz\\/void\\/index\\.html", 683 | "rules": ["test"], 684 | "redirections": [ 685 | "^https?:\\/\\/test\\.clearurls\\.xyz\\/void\\/index\\.html\\?url=([^&]*)" 686 | ] 687 | }, 688 | "ClearURLsTestBlock2": { 689 | "completeProvider": true, 690 | "urlPattern": "^https?:\\/\\/test\\.clearurls\\.xyz\\/void\\/block\\.svg" 691 | }, 692 | "diepresse.com": { 693 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?diepresse\\.com", 694 | "rules": ["from", "xtor", "xt_at"] 695 | }, 696 | "newsletter.lidl.com": { 697 | "urlPattern": "^https?:\\/\\/newsletter\\.lidl(?:\\.[a-z]{2,}){1,}", 698 | "rules": ["x"] 699 | }, 700 | "allegro.pl": { 701 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?allegro\\.pl", 702 | "rules": ["reco_id", "sid"] 703 | }, 704 | "backcountry.com": { 705 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?backcountry\\.com", 706 | "rules": [ 707 | "CMP_SKU", 708 | "MER", 709 | "mr:trackingCode", 710 | "mr:device", 711 | "mr:adType", 712 | "iv_", 713 | "CMP_ID", 714 | "k_clickid", 715 | "rmatt", 716 | "INT_ID", 717 | "ti", 718 | "fl" 719 | ], 720 | "referralMarketing": ["mr:referralID"] 721 | }, 722 | "meetup.com": { 723 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?meetup\\.com", 724 | "rules": ["rv", "_xtd"] 725 | }, 726 | "apple.com": { 727 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?apple\\.com", 728 | "rules": ["app", "ign-itsc[a-z]+"] 729 | }, 730 | "alabout.com": { 731 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?alabout\\.com", 732 | "redirections": [ 733 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?alabout\\.com.*url=([^&]*)" 734 | ] 735 | }, 736 | "newyorker.com": { 737 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?newyorker\\.com", 738 | "rules": ["source", "bxid", "cndid", "esrc", "mbid"] 739 | }, 740 | "gog.com": { 741 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?gog\\.com", 742 | "rules": ["track_click", "link_id"] 743 | }, 744 | "tradedoubler.com": { 745 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tradedoubler\\.com", 746 | "redirections": [ 747 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tradedoubler\\.com.*(?:url|_td_deeplink)=([^&]*)" 748 | ] 749 | }, 750 | "theguardian.com": { 751 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?theguardian\\.com", 752 | "rules": ["CMP"] 753 | }, 754 | "srvtrck.com": { 755 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?srvtrck\\.com", 756 | "redirections": [ 757 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?srvtrck\\.com.*url=([^&]*)" 758 | ] 759 | }, 760 | "mysku.ru": { 761 | "urlPattern": "^https?:\\/\\/mysku\\.ru", 762 | "redirections": ["^https?:\\/\\/mysku\\.ru.*r=([^&]*)"] 763 | }, 764 | "admitad.com": { 765 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?admitad\\.com", 766 | "redirections": [ 767 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?admitad\\.com.*ulp=([^&]*)" 768 | ] 769 | }, 770 | "taobao.com": { 771 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?taobao\\.com", 772 | "rules": [ 773 | "price", 774 | "sourceType", 775 | "suid", 776 | "ut_sk", 777 | "un", 778 | "share_crt_v", 779 | "sp_tk", 780 | "cpp", 781 | "shareurl", 782 | "short_name", 783 | "app", 784 | "scm[_a-z-]*", 785 | "pvid", 786 | "algo_expid", 787 | "algo_pvid", 788 | "ns", 789 | "abbucket", 790 | "ali_refid", 791 | "ali_trackid", 792 | "acm", 793 | "utparam", 794 | "pos", 795 | "abtest", 796 | "trackInfo", 797 | "utkn", 798 | "scene", 799 | "mytmenu", 800 | "turing_bucket", 801 | "lygClk", 802 | "impid", 803 | "bftTag", 804 | "bftRwd", 805 | "spm" 806 | ] 807 | }, 808 | "tmall.com": { 809 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tmall\\.com", 810 | "rules": [ 811 | "price", 812 | "sourceType", 813 | "suid", 814 | "ut_sk", 815 | "un", 816 | "share_crt_v", 817 | "sp_tk", 818 | "cpp", 819 | "shareurl", 820 | "short_name", 821 | "app", 822 | "scm[_a-z-]*", 823 | "pvid", 824 | "algo_expid", 825 | "algo_pvid", 826 | "ns", 827 | "abbucket", 828 | "ali_refid", 829 | "ali_trackid", 830 | "acm", 831 | "utparam", 832 | "pos", 833 | "abtest", 834 | "trackInfo", 835 | "user_number_id", 836 | "utkn", 837 | "scene", 838 | "mytmenu", 839 | "turing_bucket", 840 | "lygClk", 841 | "impid", 842 | "bftTag", 843 | "bftRwd", 844 | "activity_id" 845 | ] 846 | }, 847 | "tb.cn": { 848 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tb\\.cn", 849 | "rules": ["sm"] 850 | }, 851 | "bilibili.com": { 852 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bilibili\\.com", 853 | "rules": ["callback", "spm_id_from", "from_source", "from", "seid"], 854 | "exceptions": ["^https?:\\/\\/api\\.bilibili\\.com"] 855 | }, 856 | "marketscreener.com": { 857 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?marketscreener\\.com", 858 | "rules": [ 859 | "type_recherche", 860 | "mots", 861 | "noredirect", 862 | "RewriteLast", 863 | "lien", 864 | "aComposeInputSearch", 865 | "type_recherche_forum", 866 | "add_mots", 867 | "countview" 868 | ], 869 | "exceptions": [ 870 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?marketscreener\\.com\\/search\\/\\?" 871 | ] 872 | }, 873 | "marketscreener.com search": { 874 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?marketscreener\\.com\\/search\\/\\?", 875 | "rules": [ 876 | "type_recherche", 877 | "noredirect", 878 | "RewriteLast", 879 | "lien", 880 | "aComposeInputSearch", 881 | "type_recherche_forum", 882 | "countview" 883 | ] 884 | }, 885 | "bestbuy.com": { 886 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bestbuy\\.com", 887 | "rules": ["irclickid", "irgwc", "loc", "acampID", "mpid", "intl"] 888 | }, 889 | "digidip.net": { 890 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?digidip\\.net", 891 | "redirections": [ 892 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?digidip\\.net.*url=([^&]*)" 893 | ] 894 | }, 895 | "tiktok.com": { 896 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?tiktok\\.com", 897 | "rules": [ 898 | "u_code", 899 | "preview_pb", 900 | "_d", 901 | "timestamp", 902 | "user_id", 903 | "share_app_name", 904 | "share_iid", 905 | "source" 906 | ] 907 | }, 908 | "autoplus.fr": { 909 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?autoplus\\.fr", 910 | "rules": ["idprob", "hash", "sending_id", "site_id", "dr_tracker"] 911 | }, 912 | "bigfishgames.com": { 913 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bigfishgames\\.com", 914 | "rules": ["pc", "npc", "npv[0-9]+", "npi"], 915 | "rawRules": ["\\?pc$"] 916 | }, 917 | "dpbolvw.net": { 918 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?dpbolvw\\.net", 919 | "redirections": [ 920 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?dpbolvw\\.net.*url=([^&]*)" 921 | ] 922 | }, 923 | "humblebundle.com": { 924 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?humblebundle\\.com", 925 | "referralMarketing": ["partner"] 926 | }, 927 | "cafepedagogique.net": { 928 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?cafepedagogique\\.net", 929 | "rules": ["actId", "actCampaignType", "actSource"] 930 | }, 931 | "bloculus.com": { 932 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?bloculus\\.com", 933 | "rules": ["tl_[a-z_]+"] 934 | }, 935 | "mailpanion.com": { 936 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?mailpanion\\.com", 937 | "redirections": [ 938 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?mailpanion\\.com.*destination=([^&]*)" 939 | ] 940 | }, 941 | "signtr.website": { 942 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?signtr\\.website", 943 | "redirections": [ 944 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?signtr\\.website.*redirect=([^&]*)" 945 | ] 946 | }, 947 | "mailtrack.io": { 948 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?mailtrack\\.io", 949 | "redirections": [ 950 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?mailtrack\\.io.*url=([^&]*)" 951 | ] 952 | }, 953 | "zillow.com": { 954 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?zillow\\.com", 955 | "rules": ["rtoken"] 956 | }, 957 | "realtor.com": { 958 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?realtor\\.com", 959 | "rules": ["ex", "identityID", "MID", "RID"] 960 | }, 961 | "redfin.com": { 962 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?redfin\\.com", 963 | "rules": ["riftinfo"] 964 | }, 965 | "epicgames.com": { 966 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?epicgames\\.com", 967 | "rules": ["epic_affiliate", "epic_gameId"] 968 | }, 969 | "onet.pl": { 970 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?onet\\.pl", 971 | "rules": ["srcc", "utm_v", "utm_medium", "utm_source"] 972 | }, 973 | "allrecipes.com": { 974 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?allrecipes\\.com", 975 | "rules": [ 976 | "internalSource", 977 | "referringId", 978 | "referringContentType", 979 | "clickId" 980 | ] 981 | }, 982 | "europe1.fr": { 983 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?europe1\\.fr", 984 | "rules": ["xtor"] 985 | }, 986 | "effiliation.com": { 987 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?effiliation\\.com", 988 | "redirections": [ 989 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?effiliation\\.com.*url=([^&]*)" 990 | ] 991 | }, 992 | "argos.co.uk": { 993 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?argos\\.co\\.uk", 994 | "rules": [ 995 | "istCompanyId", 996 | "istFeedId", 997 | "istItemId", 998 | "istBid", 999 | "clickOrigin" 1000 | ] 1001 | }, 1002 | "hlserve.com": { 1003 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?hlserve\\.com", 1004 | "redirections": [ 1005 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?hlserve\\.com.*dest=([^&]*)" 1006 | ] 1007 | }, 1008 | "thunderbird.net": { 1009 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?thunderbird\\.net", 1010 | "rules": ["src"] 1011 | }, 1012 | "cnbc.com": { 1013 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?cnbc\\.com", 1014 | "rules": ["__source"] 1015 | }, 1016 | "roblox.com": { 1017 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?roblox\\.com", 1018 | "rules": ["refPageId"] 1019 | }, 1020 | "cell.com": { 1021 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?cell\\.com", 1022 | "rules": ["_returnURL"] 1023 | }, 1024 | "academic.oup.com": { 1025 | "urlPattern": "^https?:\\/\\/academic\\.oup\\.com", 1026 | "rules": ["redirectedFrom"] 1027 | }, 1028 | "flexlinkspro.com": { 1029 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?flexlinkspro\\.com", 1030 | "redirections": [ 1031 | "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?flexlinkspro\\.com.*url=([^&]*)" 1032 | ] 1033 | }, 1034 | "agata88.com": { 1035 | "urlPattern": "^https?:\\/\\/(?:[a-z0-9-]+\\.)*?agata88\\.com", 1036 | "rules": ["source"] 1037 | } 1038 | } 1039 | } 1040 | -------------------------------------------------------------------------------- /data/loader.js: -------------------------------------------------------------------------------- 1 | // Literally the only reason this is its own module is because I want to mock it for testing 2 | import { readFileSync } from 'fs' 3 | import { fileURLToPath } from 'url' 4 | import path from 'path' 5 | 6 | export default function loadRuleset() { 7 | const dirname = fileURLToPath(path.dirname(import.meta.url)) 8 | const filePath = path.join(dirname, 'data.minify.json') 9 | const file = readFileSync(filePath) 10 | return Object.values(JSON.parse(file).providers) 11 | } 12 | -------------------------------------------------------------------------------- /esm-resolver.cjs: -------------------------------------------------------------------------------- 1 | // temporary workaround while we wait for https://github.com/facebook/jest/issues/9771 2 | const resolver = require('enhanced-resolve').create.sync({ 3 | conditionNames: ['require', 'node', 'default'], 4 | extensions: ['.js', '.json', '.node', '.ts', '.tsx'] 5 | }) 6 | 7 | module.exports = function (request, options) { 8 | // This is an EXTREMELY hacky workaround for jest not being able to load manual mocks for ES Modules. 9 | // Man, fuck this shit. 10 | if (request.includes('data/loader')) 11 | request = request.replace('data/loader', 'data/__mocks__/loader') 12 | 13 | // list global module that must be resolved by defaultResolver here 14 | if ( 15 | [ 16 | 'dns/promises', 17 | 'dns', 18 | 'util', 19 | 'url', 20 | 'tls', 21 | 'http', 22 | 'https', 23 | 'stream', 24 | 'events', 25 | 'net', 26 | 'fs', 27 | 'path' 28 | ].includes(request) 29 | ) { 30 | return options.defaultResolver(request, options) 31 | } 32 | return resolver(options.basedir, request) 33 | } 34 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import QuickLRU from 'quick-lru' 2 | import pTimeout from 'p-timeout' 3 | import normalizeUrl from './utils/normalize-url.js' 4 | import httpClientGen from './utils/http-client.js' 5 | import dnsLookupGen from './utils/dns-lookup.js' 6 | import logger from './utils/logger.js' 7 | import CacheableLookup from 'cacheable-lookup' 8 | import { gotSsrf } from 'got-ssrf' 9 | import { PRESETS } from 'header-generator' 10 | 11 | const debug = logger('index.js') 12 | 13 | export default ( 14 | normalizeUrlOptions = { 15 | stripHash: true, 16 | removeQueryParameters: [] 17 | }, 18 | gotOptions = { 19 | https: { 20 | rejectUnauthorized: true 21 | }, 22 | followRedirect: true, 23 | maxRedirects: 10, 24 | throwHttpErrors: true, 25 | timeout: { 26 | request: 14000 // global timeout 27 | }, 28 | cache: new QuickLRU({ maxSize: 10000 }), 29 | dnsCache: new CacheableLookup({ cache: new QuickLRU({ maxSize: 100000 }) }), 30 | context: { 31 | insecureHTTPParser: false, 32 | proxyUrl: process.env.HTTP_PROXY_URL, 33 | headerGeneratorOptions: PRESETS.MODERN_WINDOWS_CHROME 34 | } 35 | }, 36 | timeoutMs = 15000, 37 | canonicizeMemOpts = { cache: new QuickLRU({ maxSize: 100000 }) }, 38 | stripTrackersMemOpts = { cache: new QuickLRU({ maxSize: 100000 }) } 39 | // The cache numbers are pulled from the most reliable source on the internet: my ass. 40 | ) => { 41 | const dnsLookup = dnsLookupGen(gotOptions) 42 | const normalize = normalizeUrl( 43 | normalizeUrlOptions, 44 | dnsLookup, 45 | gotSsrf.extend(gotOptions), // don't really need to mimic browser behaviour or canonicize shit 46 | stripTrackersMemOpts 47 | ) 48 | const httpClient = httpClientGen(normalize, gotOptions, canonicizeMemOpts) 49 | 50 | // Normalize URL so that we can search by URL. 51 | async function normalizePlus(url = '') { 52 | debug('Normalizing URL %s', url) 53 | 54 | // 1. "Base" normalization using normalize-url + stripping trackers 55 | // When an invalid link is passed, it will throw. 56 | const link = await normalize(url) 57 | debug('Normalization first pass: %s', url) 58 | 59 | // 2. Follow redirects to deal with "intermediate" links (such as the links on google search results) 60 | const res = await httpClient.get(link) 61 | debug('Normalization second pass: %s', res.url) 62 | 63 | // At this point, the link will be completely normalized based on canonical links (if one exists) 64 | return res.url 65 | } 66 | 67 | // global timeout for the ENTIRE function, because I'm afraid of blocking the event loop w/ some of the more compute-intensive shit 68 | return url => pTimeout(normalizePlus(url), timeoutMs) 69 | } 70 | -------------------------------------------------------------------------------- /jest.config.cjs: -------------------------------------------------------------------------------- 1 | process.env.JEST_JUNIT_OUTPUT_DIR = 'reports/jest' 2 | 3 | module.exports = { 4 | coverageThreshold: { 5 | global: { 6 | branches: 80 7 | } 8 | }, 9 | reporters: ['default', 'jest-junit'], 10 | errorOnDeprecated: true, 11 | notify: true, 12 | testEnvironment: 'jest-environment-node', 13 | transform: {}, 14 | resolver: '/esm-resolver.cjs' 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "normalize-url-plus", 3 | "version": "1.5.4", 4 | "description": "normalize-url plus additional features to supercharge link normalization!", 5 | "exports": "./index.js", 6 | "type": "module", 7 | "repository": "JaneJeon/normalize-url-plus", 8 | "author": "Jane Jeon ", 9 | "license": "LGPL-3.0", 10 | "bin": "bin/normalize.js", 11 | "engines": { 12 | "node": ">=16" 13 | }, 14 | "scripts": { 15 | "test": "NODE_OPTIONS=--experimental-vm-modules jest", 16 | "update-data": "curl -L -s https://rules2.clearurls.xyz/data.minify.json > data/data.minify.json", 17 | "lint": "run-s lint:*", 18 | "lint:prettier": "prettier --check .", 19 | "lint:eslint": "eslint .", 20 | "prepare": "husky install" 21 | }, 22 | "dependencies": { 23 | "cacheable-lookup": "^7.0.0", 24 | "cheerio": "^1.0.0-rc.10", 25 | "debug": "^4.3.2", 26 | "got": "^14.0.0", 27 | "got-scraping": "^4.0.0", 28 | "got-ssrf": "^3.0.0", 29 | "ipaddr.js": "^2.0.1", 30 | "leven": "^4.0.0", 31 | "lodash": "^4.17.21", 32 | "mem": "^9.0.1", 33 | "normalize-url": "^7.0.2", 34 | "p-timeout": "^5.0.0", 35 | "quick-lru": "^7.0.0", 36 | "re2": "^1.16.0", 37 | "tld-extract": "^2.0.1" 38 | }, 39 | "devDependencies": { 40 | "@janejeon/eslint-config": "^2.2.0", 41 | "@janejeon/prettier-config": "^1.1.0", 42 | "enhanced-resolve": "^5.8.3", 43 | "husky": "^6.0.0", 44 | "jest": "^29.0.0", 45 | "jest-junit": "^16.0.0", 46 | "lint-staged": "15.5.2", 47 | "nock": "^13.1.3", 48 | "node-notifier": "^10.0.0", 49 | "npm-run-all2": "^6.0.0", 50 | "skip-ci": "^1.0.4" 51 | }, 52 | "keywords": [ 53 | "normalize", 54 | "url", 55 | "uri", 56 | "address", 57 | "string", 58 | "normalization", 59 | "normalisation", 60 | "query", 61 | "querystring", 62 | "simplify", 63 | "strip", 64 | "trim", 65 | "canonical" 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["github>JaneJeon/dev//packages/renovate-config/default.json"] 4 | } 5 | -------------------------------------------------------------------------------- /utils/__fixtures__/empty-cache.js: -------------------------------------------------------------------------------- 1 | export default class EmptyCache { 2 | get() { 3 | // noop 4 | } 5 | 6 | set() { 7 | // noop 8 | } 9 | 10 | has() { 11 | return false 12 | } 13 | 14 | delete() { 15 | // noop 16 | } 17 | 18 | clear() { 19 | // noop 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /utils/__mocks__/strip-trackers.js: -------------------------------------------------------------------------------- 1 | export default function gen() { 2 | return function clearUrl(url) { 3 | return url // much function, very wow 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /utils/canonicize.js: -------------------------------------------------------------------------------- 1 | import cheerio from 'cheerio' 2 | import trim from 'lodash/trim.js' 3 | import leven from 'leven' 4 | import parseTld from 'tld-extract' 5 | import mem from 'mem' 6 | import urlIsAmp from './url-is-amp.js' 7 | import logger from './logger.js' 8 | 9 | const debug = logger('utils/canonicize.js') 10 | 11 | export default function canonicizeGen(normalize, memOpts) { 12 | // Look for the canonical link (also un-AMP-ifies the canonical link) 13 | // Not writing a separate metascraper-canonical library for this, as the "standard" way of determining 14 | // canonical link includes looking at the HTTP header: https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls 15 | async function getCanonical(res, normalizedUrl) { 16 | // Ripped from https://github.com/KilledMufasa/AmputatorBot/blob/master/helpers/canonical_methods.py 17 | const $ = cheerio.load(res.body) 18 | const matches = [] 19 | 20 | // 5.1: rel=canonical tag 21 | $('link[rel=canonical]').each(function () { 22 | const match = $(this).attr('href') 23 | matches.push(match) 24 | debug('Matched rel=canonical tag: %s', match) 25 | }) 26 | 27 | // 5.2: rel=canonical HTTP header 28 | if ('link' in res.headers) { 29 | debug('"Link" header exists, searching for rel=canonical...') 30 | 31 | // We're looking for something like: 32 | // Link: ; rel="canonical", ... 33 | res.headers.link.split(',').forEach(linkHeader => { 34 | const parts = linkHeader.split(';') 35 | if (parts.length !== 2) { 36 | debug('Not enough parts exist in the header: %s', linkHeader) 37 | return 38 | } 39 | 40 | const [linkStr, relStr] = parts 41 | debug('Extracted link fragment %s and rel fragment %s', linkStr, relStr) 42 | 43 | // rel="canonical", rel=canonical, rel canonical, etc. 44 | const relStrLower = relStr.toLowerCase() 45 | if (relStrLower.includes('rel') && relStrLower.includes('canonical')) { 46 | // , https://example.com, etc. 47 | const url = trim(linkStr.trim(), ['<', '>', ' ']) 48 | matches.push(url) 49 | debug('Found canonical in header: %s', url) 50 | } 51 | }) 52 | } 53 | 54 | // 5.3: AMP variant 55 | $('a.amp-canurl').each(function () { 56 | const match = $(this).attr('href') 57 | matches.push(match) 58 | debug('Found non-AMP variant: %s', match) 59 | }) 60 | 61 | // 5.4: OpenGraph 62 | $('meta[property="og:url"]').each(function () { 63 | const match = $(this).attr('content') 64 | matches.push(match) 65 | debug('Found OpenGraph og:url: %s', match) 66 | }) 67 | 68 | // 5.5: Sitemap (I'm not doing this shit) 69 | 70 | // The only reason we want canonical is to make our job with normalization easier; 71 | // So we need to make sure the canonical link IS for the url we're trying to normalize! 72 | 73 | const { hostname: domain } = new URL(normalizedUrl) 74 | const { domain: baseDomain } = parseTld(normalizedUrl) 75 | debug( 76 | 'Finding the best match for host %s and TLD %s...', 77 | domain, 78 | baseDomain 79 | ) 80 | 81 | let result = normalizedUrl 82 | let minDist = Number.POSITIVE_INFINITY 83 | 84 | for (const match of matches) { 85 | let link = match 86 | 87 | // turn relative to absolute URL 88 | if (match.startsWith('/')) link = `${domain}${match}` 89 | debug('Considering match %s...', link) 90 | 91 | // Skip invalid links 92 | try { 93 | link = await normalize(link) 94 | debug('Normalized match to %s', link) 95 | 96 | // Ensure that every match is a valid URL w/ a matching domain 97 | // In this case, we're only matching the "top-level" domain - 98 | // e.g. subdomain.(domain.com) - as a lot of sites host their shit on amp.(site.com) 99 | // so we want to include references to www.site.com (actually *prefer* those) 100 | const { domain: matchDomain } = parseTld(link) 101 | if (matchDomain !== baseDomain) { 102 | debug( 103 | 'The domain %s does not match the base domain %s', 104 | matchDomain, 105 | baseDomain 106 | ) 107 | continue 108 | } 109 | 110 | // Then, ensure that links aren't AMP'd 111 | if (urlIsAmp(link)) { 112 | debug('Link %s is AMP, skipping...', link) 113 | continue 114 | } 115 | } catch (err) { 116 | debug('Error %s while considering match %s', err, match) 117 | continue 118 | } 119 | 120 | // Then, sort by similarity to the normalized URL of the page we ended up in 121 | const dist = leven(normalizedUrl, link) 122 | if (dist < minDist) { 123 | minDist = dist 124 | result = link 125 | } 126 | } 127 | 128 | debug('Found best match %s', result) 129 | return result 130 | } 131 | 132 | const memCanonical = mem(getCanonical, { 133 | ...memOpts, 134 | cacheKey: args => args[1] // we want to cache by the normalized url in order to raise the hit rate 135 | }) 136 | 137 | return async function canonicizeHook(res) { 138 | // Normalize the "final" URL up front 139 | const normalizedUrl = await normalize(res.url) 140 | debug('Normalized res.url %s to %s', res.url, normalizedUrl) 141 | 142 | res.url = await memCanonical(res, normalizedUrl) 143 | 144 | return res 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /utils/canonicize.test.js: -------------------------------------------------------------------------------- 1 | import { expect, describe, it } from '@jest/globals' 2 | import got from 'got' 3 | import nock from 'nock' 4 | import hookGen from './canonicize.js' 5 | import EmptyCache from './__fixtures__/empty-cache.js' 6 | 7 | nock.disableNetConnect() 8 | 9 | async function mockNormalize(url) { 10 | // just append protocol, do nothing else 11 | return url.startsWith('http') || url.startsWith('https') 12 | ? url 13 | : `http://${url}` 14 | } 15 | 16 | describe('extracting canonical links', () => { 17 | const httpClient = got.extend({ 18 | hooks: { 19 | afterResponse: [ 20 | hookGen(mockNormalize, { 21 | cache: new EmptyCache() 22 | }) 23 | ] 24 | } 25 | }) 26 | 27 | it('picks up rel=canonical in HTML body', async () => { 28 | nock('http://asdf.com') 29 | .get('/somepage') 30 | .reply( 31 | 200, 32 | ` 33 | 34 | 35 | 36 | Simple HTML document 37 | 38 | 39 |

Hello World!

40 | 41 | ` 42 | ) 43 | 44 | const { url } = await httpClient.get('http://asdf.com/somepage') 45 | expect(url).toBe('http://asdf.com/canonical') 46 | }) 47 | 48 | it('picks up rel=canonical in HTTP header', async () => { 49 | nock('http://asdf.com') 50 | .get('/somepage') 51 | .reply( 52 | 200, 53 | ` 54 | 55 | 56 | Simple HTML document 57 | 58 | 59 |

Hello World!

60 | 61 | `, 62 | { 63 | link: '< http://asdf.com/canonical>; rel="canonical"' 64 | } 65 | ) 66 | 67 | const { url } = await httpClient.get('http://asdf.com/somepage') 68 | expect(url).toBe('http://asdf.com/canonical') 69 | }) 70 | 71 | it("picks up de-AMP'd links", async () => { 72 | nock('http://asdf.com') 73 | .get('/somepage') 74 | .reply( 75 | 200, 76 | ` 77 | 78 | 79 | Simple HTML document 80 | 81 | 82 | 83 |

Hello World!

84 | 85 | ` 86 | ) 87 | 88 | const { url } = await httpClient.get('http://asdf.com/somepage') 89 | expect(url).toBe('http://asdf.com/canonical') 90 | }) 91 | 92 | it('picks up opengraph links', async () => { 93 | nock('http://asdf.com') 94 | .get('/somepage') 95 | .reply( 96 | 200, 97 | ` 98 | 99 | 100 | Simple HTML document 101 | 102 | 103 | 104 |

Hello World!

105 | 106 | ` 107 | ) 108 | 109 | const { url } = await httpClient.get('http://asdf.com/somepage') 110 | expect(url).toBe('http://asdf.com/canonical') 111 | }) 112 | 113 | it('puts all relative links in absolute form', async () => { 114 | nock('http://sub.asdf.com') 115 | .get('/somepage') 116 | .reply( 117 | 200, 118 | ` 119 | 120 | 121 | 122 | Simple HTML document 123 | 124 | 125 |

Hello World!

126 | 127 | ` 128 | ) 129 | 130 | const { url } = await httpClient.get('http://sub.asdf.com/somepage') 131 | expect(url).toBe('http://sub.asdf.com/canonical') 132 | }) 133 | 134 | it('ignores invalid matches (domain)', async () => { 135 | nock('http://sub.asdf.com') 136 | .get('/somepage') 137 | .reply( 138 | 200, 139 | ` 140 | 141 | 142 | 143 | Simple HTML document 144 | 145 | 146 |

Hello World!

147 | 148 | ` 149 | ) 150 | 151 | const { url } = await httpClient.get('http://sub.asdf.com/somepage') 152 | expect(url).toBe('http://sub.asdf.com/somepage') 153 | }) 154 | 155 | it('ignores invalid matches (amp)', async () => { 156 | nock('http://asdf.com') 157 | .get('/somepage') 158 | .reply( 159 | 200, 160 | ` 161 | 162 | 163 | 164 | Simple HTML document 165 | 166 | 167 |

Hello World!

168 | 169 | ` 170 | ) 171 | 172 | const { url } = await httpClient.get('http://asdf.com/somepage') 173 | expect(url).toBe('http://asdf.com/somepage') 174 | }) 175 | 176 | it('returns the most "relevant" link', async () => { 177 | nock('http://amp.asdf.com') 178 | .get('/somepage') 179 | .reply( 180 | 200, 181 | ` 182 | 183 | 184 | 185 | Simple HTML document 186 |
187 | 188 | 189 | 190 |

Hello World!

191 | 192 | `, 193 | { 194 | link: '< http://asdf.com/canonical>; rel="canonical"' 195 | } 196 | ) 197 | 198 | const { url } = await httpClient.get('http://amp.asdf.com/somepage') 199 | expect(url).toBe('http://asdf.com/somepage') 200 | }) 201 | }) 202 | -------------------------------------------------------------------------------- /utils/dns-lookup.js: -------------------------------------------------------------------------------- 1 | import { URL } from 'url' 2 | import { lookup as nativeLookup } from 'dns/promises' 3 | import { promisify } from 'util' 4 | import logger from './logger.js' 5 | 6 | const debug = logger('utils/dns-lookup.js') 7 | 8 | export default gotOptions => { 9 | let lookup 10 | if (gotOptions.dnsCache) { 11 | debug('Using dnsCache.lookupAsync for DNS lookups') 12 | lookup = gotOptions.dnsCache.lookupAsync 13 | } else if (gotOptions.dnsLookup) { 14 | debug('Promisifying user-provided dnsLookup') 15 | lookup = promisify(gotOptions.dnsLookup) 16 | } else { 17 | debug('dnsCache does not exist, falling back to dns/promises') 18 | lookup = nativeLookup 19 | } 20 | 21 | return async url => { 22 | debug('Looking up DNS for %s', url) 23 | try { 24 | const { hostname } = new URL(url) 25 | await lookup(hostname) 26 | debug('Lookup of host %s successful', hostname) 27 | return true 28 | } catch (err) { 29 | debug('Lookup of %s unsuccessful', url) 30 | return false 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /utils/http-client.js: -------------------------------------------------------------------------------- 1 | import { got } from 'got' 2 | import { gotScraping } from 'got-scraping' 3 | import { gotSsrf } from 'got-ssrf' 4 | import canonicizeHookGen from './canonicize.js' 5 | 6 | export default function httpClient(normalize, gotOptions, canonicizeMemOpts) { 7 | return got 8 | .extend(gotOptions) 9 | .extend(gotSsrf) 10 | .extend(gotScraping) 11 | .extend({ 12 | hooks: { 13 | afterResponse: [canonicizeHookGen(normalize, canonicizeMemOpts)] 14 | } 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /utils/logger.js: -------------------------------------------------------------------------------- 1 | import debug from 'debug' 2 | 3 | const BASE = 'normalize' 4 | export default function (name) { 5 | const fullName = `${BASE}:${name}` 6 | return debug(fullName) 7 | } 8 | -------------------------------------------------------------------------------- /utils/normalize-url.js: -------------------------------------------------------------------------------- 1 | import normalizeUrl from 'normalize-url' 2 | import stripTrackersGen from './strip-trackers.js' 3 | import { URL } from 'url' 4 | import logger from './logger.js' 5 | 6 | const debug = logger('utils/normalize-url.js') 7 | 8 | export default function gen( 9 | normalizeUrlOptions, 10 | dnsLookup, 11 | httpClient, 12 | memOpts 13 | ) { 14 | const stripTrackers = stripTrackersGen(memOpts) 15 | 16 | return async function normalize(originalUrl) { 17 | // We default to non-www, https links 18 | const preferredOptions = { 19 | stripWWW: true, 20 | forceHttps: true 21 | } 22 | 23 | // Pass 1: try to force as much normalization as possible, knowing that this may break some links 24 | let url = normalizeUrl(originalUrl, { 25 | ...normalizeUrlOptions, 26 | ...preferredOptions 27 | }) 28 | debug('Normalization pass 1: %s', url) 29 | 30 | // Check 1: if the www-stripped domain exists... 31 | if (originalUrl.includes('www')) { 32 | debug('Checking if www-stripped domain exists...') 33 | const { hostname } = new URL(url) 34 | try { 35 | await dnsLookup(hostname) 36 | debug('www-stripped domain exists!') 37 | } catch (err) { 38 | // Pass 2: we can't resolve the www-stripped host at the DNS level, so we enable it 39 | preferredOptions.stripWWW = false 40 | url = normalizeUrl(originalUrl, { 41 | ...normalizeUrlOptions, 42 | ...preferredOptions 43 | }) 44 | debug('non-www domain does not exist, using %s', url) 45 | } 46 | } 47 | 48 | // Check 2: if the site doesn't support HTTPS... 49 | debug('Checking if https version exists...') 50 | try { 51 | await httpClient.head(url) 52 | debug('https version exists!') 53 | } catch (err) { 54 | // Pass 3: we can't reach the URL via HTTP HEAD request, so try downgrading to http 55 | preferredOptions.forceHttps = false 56 | url = normalizeUrl(originalUrl, { 57 | ...normalizeUrlOptions, 58 | ...preferredOptions 59 | }) 60 | debug('https version does not exist, using %s', url) 61 | } 62 | 63 | // always strip trackers for consistency (even if it means worse performance)! 64 | // And don't forget to normalize the end result of stripping tracking for consistency! 65 | debug('stripping trackers from %s', url) 66 | return normalizeUrl(stripTrackers(url), { 67 | ...normalizeUrlOptions, 68 | ...preferredOptions 69 | }) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /utils/normalize-url.test.js: -------------------------------------------------------------------------------- 1 | import { expect, describe, it } from '@jest/globals' 2 | import gen from './normalize-url.js' 3 | import EmptyCache from './__fixtures__/empty-cache.js' 4 | 5 | const normalize = gen( 6 | { stripHash: true, removeQueryParameters: [] }, 7 | async hostname => { 8 | // throw if non-WWW versions aren't available 9 | if (hostname === 'test2.com' || hostname === 'test3.com') throw new Error() 10 | }, 11 | { 12 | head: async url => { 13 | // throw if site doesn't support HTTPS 14 | if (url === 'https://www.test3.com/asdf') throw new Error() 15 | } 16 | }, 17 | { cache: new EmptyCache() } 18 | ) 19 | 20 | describe('link normalization', () => { 21 | it('defaults to non-www, https', async () => { 22 | const url = await normalize('http://www.test1.com/asdf') 23 | expect(url).toBe('https://test1.com/asdf') 24 | }) 25 | 26 | it('falls back to www if DNS cannot be resolved', async () => { 27 | const url = await normalize('www.test2.com/asdf') 28 | expect(url).toBe('https://www.test2.com/asdf') 29 | }) 30 | 31 | it('falls back to http if https version cannot be reached', async () => { 32 | const url = await normalize('www.test3.com/asdf') 33 | expect(url).toBe('http://www.test3.com/asdf') 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /utils/strip-trackers.js: -------------------------------------------------------------------------------- 1 | import { URL } from 'url' 2 | import mem from 'mem' 3 | import load from '../data/loader.js' 4 | import logger from './logger.js' 5 | 6 | const providers = load() 7 | const debug = logger('utils/strip-trackers.js') 8 | 9 | const cachedRegex = mem(pattern => new RegExp(pattern)) 10 | 11 | function clearUrl(url) { 12 | debug('Stripping trackers for %s', url) 13 | 14 | // Clean the given URL with the provided rules data. 15 | // URLs matching a provider's `urlPattern` and one or more of that 16 | // provider's redirection patterns will cause the URL to be replaced 17 | // with the match's first matched group 18 | 19 | // Shamelessly adopted from https://gitlab.com/CrunchBangDev/cbd-cogs/-/blob/master/Scrub/scrub.py 20 | // TODO: benchmark regex search 21 | 22 | providers.forEach(provider => { 23 | // Check provider urlPattern against provided URI 24 | if (!cachedRegex(provider.urlPattern).test(url)) return 25 | debug('Matched a provider %s', provider.urlPattern) 26 | 27 | // completeProvider is a boolean that determines if every url that 28 | // matches will be blocked. If you want to specify rules, exceptions 29 | // and/or redirections, the value of completeProvider must be false. 30 | if (provider.completeProvider) throw new Error('Link is blocked') 31 | 32 | // If any exceptions are matched, this provider is skipped 33 | for (const exception of provider.exceptions || []) { 34 | if (cachedRegex(exception).test(url)) { 35 | debug('Matched an exception %s. Skipping...', exception) 36 | return 37 | } 38 | } 39 | 40 | // the redirections from this handles cases like youtube redirects where you literally CAN'T be redirected by an HTTP call because youtube is a piece of fucking shit 41 | for (const redir of provider.redirections || []) { 42 | const regex = cachedRegex(redir) 43 | const match = regex.exec(url) 44 | if (match && match.length > 1) { 45 | url = decodeURIComponent(match[1]) 46 | debug('Matched a redirect! %s', url) 47 | } 48 | } 49 | 50 | // Explode query paramters to be checked against rules 51 | const parsedUrl = new URL(url) 52 | 53 | // Check regular rules and referral marketing rules 54 | for (const rule of provider.rules || []) { 55 | const regex = cachedRegex(rule) 56 | for (const param of parsedUrl.searchParams.keys()) { 57 | if (regex.test(param)) { 58 | parsedUrl.searchParams.delete(param) 59 | debug('Deleting a query parameter %s', param) 60 | } 61 | } 62 | } 63 | for (const rule of provider.referralMarketing || []) { 64 | const regex = cachedRegex(rule) 65 | for (const param of parsedUrl.searchParams.keys()) { 66 | if (regex.test(param)) { 67 | parsedUrl.searchParams.delete(param) 68 | debug('Debugging a marketing query parameter %s', param) 69 | } 70 | } 71 | } 72 | 73 | // At this point, all of the querystrings *should* be sorted by normalize-url (the vanilla one) 74 | 75 | // Rebuild valid URI string with remaining query parameters 76 | url = parsedUrl.toString() 77 | debug('Reformed URL %s', url) 78 | 79 | // Strip raw fragments with rawRules 80 | for (const rule of provider.rawRules || []) { 81 | const regex = cachedRegex(rule) 82 | url = url.replace(regex, '') 83 | debug('Stripped raw fragment %s to get %s', rule, url) 84 | } 85 | }) 86 | 87 | return url 88 | } 89 | 90 | export default function clearUrlGen(memOpts) { 91 | return mem(clearUrl, memOpts) 92 | } 93 | -------------------------------------------------------------------------------- /utils/strip-trackers.test.js: -------------------------------------------------------------------------------- 1 | import { expect, describe, it } from '@jest/globals' 2 | import clearUrlGen from './strip-trackers.js' 3 | import EmptyCache from './__fixtures__/empty-cache.js' 4 | 5 | const clearUrl = clearUrlGen({ cache: new EmptyCache() }) 6 | 7 | describe('stripping trackers', () => { 8 | it('blocks "complete providers"', () => { 9 | expect(() => clearUrl('https://thisshouldthrow.com/asdf')).toThrow( 10 | 'Link is blocked' 11 | ) 12 | }) 13 | 14 | it('skips on exceptions', () => { 15 | // This is one of the things I'm not sure on and I probably *won't* be sure on; 16 | // but I'm not sure where in the processing pipeline exception comes. 17 | // For now, I'm putting it right after completeProvider stage. 18 | expect( 19 | clearUrl('https://thisshouldmatch.com/butnotthis?fuckthis=true') 20 | ).toBe('https://thisshouldmatch.com/butnotthis?fuckthis=true') 21 | }) 22 | 23 | it('strips querystrings, marketing or not', () => { 24 | expect( 25 | clearUrl('https://trackerstripping.com/asdf?red=sus&rule=1&rawRule=2') 26 | ).toBe('https://trackerstripping.com/asdf?red=sus') 27 | }) 28 | 29 | it('strips on raw rules', () => { 30 | expect( 31 | clearUrl( 32 | 'https://www.amazon.com/Upgrade-Massager-Waterproof-Dillidos-Cellulite/dp/B09668ZY89/ref=sr_1_1?keywords=dildo&sr=8-1' 33 | ) 34 | ).toBe( 35 | 'https://www.amazon.com/Upgrade-Massager-Waterproof-Dillidos-Cellulite/dp/B09668ZY89?keywords=dildo&sr=8-1' 36 | ) 37 | }) 38 | 39 | it('deals with redirects that CANNOT be resolved by HTTP semantics because webdevs are assholes and do not want you to auto-redirect', () => { 40 | expect( 41 | clearUrl( 42 | 'https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbGdRQXRVT01hNk1pWjU4Ulh6a0ltbnRYT1BMd3xBQ3Jtc0trblJ5aU5KRjdXZTI3YzJyME5BcnQydmd6UnVFTW1pUmFqNkZZbDNJNUtXWm1RTmE0MTRYTUoyc25kbVU5ZUlmbzBQWmpRMUptaXRyLW1hYmNEMV9rZUFpLUgwV045enFVM0RpclB4a1VkR3RFaC1IRQ&q=https%3A%2F%2Fstore.gamersnexus.net%2F' 43 | ) 44 | ).toBe('https://store.gamersnexus.net/') 45 | }) 46 | }) 47 | -------------------------------------------------------------------------------- /utils/url-is-amp.js: -------------------------------------------------------------------------------- 1 | // Ripped from https://github.com/KilledMufasa/AmputatorBot/blob/7ee5760e653392e383fe22c4a82155300ff80c9a/static/static.txt 2 | const AMP_KEYWORDS = [ 3 | '/amp', 4 | 'amp/', 5 | '.amp', 6 | 'amp.', 7 | '?amp', 8 | 'amp?', 9 | '=amp', 10 | 'amp=', 11 | '&', 12 | 'amp&', 13 | '%amp', 14 | 'amp%', 15 | '_amp', 16 | 'amp_' 17 | ] 18 | 19 | export default function urlIsAmp(url) { 20 | return AMP_KEYWORDS.some(kw => url.includes(kw)) 21 | } 22 | --------------------------------------------------------------------------------