airtower-luna / referer-mod

Web Extension to modify the Referer header in HTTP requests
https://addons.mozilla.org/en-US/firefox/addon/referer-modifier/
GNU General Public License v3.0
48 stars 14 forks source link
firefox firefox-webextension webextension

referer-mod

referer-mod logo: cat ears peeking over an edge

Referer Modifier is a Web Extension for Firefox to modify the Referer header in HTTP requests, and the Javascript document.referrer property to match. For each target domain, one of five actions can be configured:

Rules can optionally be limited to apply only to requests from certain origin domains.

You can configure default actions for requests originating from the same domain, and any other request not matching a domain rule. The "replace" and "target" actions will create a Referer header if necessary, the others only modify or remove existing ones. The configuration can be exported as and imported from JSON files.

Installation

Users should install the add-on from the addons.mozilla.org page.

If you're working on the code you can load your work in progress as a temporary add-on using the Firefox about:debugging page.

Developer information

The following files implement the core functionality:

Settings are saved in the browser.storage.sync storage area, so if the user is using Firefox sync their settings will be synchronized automatically, otherwise the storage is local.

There is limited localization data in the _locales/ directory. The Makefile serves to build a ZIP archive for upload to AMO.

The repository contains a configuration file for ESLint. ESLint runs in CI (see the "Referer Mod / lint" job), please pay attention to its results when working on a pull request.

Internationalization

All user interface elements are internationalized using the WebExtensions i18n API. Additional translations are welcome! All you need to do is create a subdirectory for the locale in _locales/, and put whatever messages you'd like to translate into a messages.json file there.

When editing any of the HTML files note that elements with the i18n-text class are internationalized. Their text content (and title, if any) is used to look up the actual messages and replaced. If the replacement text contains linebreaks, each line becomes a paragraph and text enclosed in backticks is turned into <code> elements.

Testing

The testserver/ directory of this repository contains a test environment based on Go and containers that you can use locally. You can use it manually (see the README), or run test.py after starting it for automated tests. The automated tests require the Selenium Python client and Geckodriver.

Known issues

The document.referrer modification is a workaround for [Firefox bug

1601496](https://bugzilla.mozilla.org/show_bug.cgi?id=1601496), and

unfortunately not 100% reliable because there's no way to guarantee that the content script that does the modification always runs before page scripts.