16

Is there a way (Firefox add-on or about:config setting) to send a custom HTTP header for requests to a certain host?

Example: Send the header Foobar: true if (and only if) I request a resource from the host foo.example.com.

Bonus points if the protocol can be specified, too (e.g. only send the header when requesting over HTTPS).

(see my question Use additional “password” in Referer to hide private site? on IT Security SE on why I’d like to do it)

What I found so far

0

5 Answers 5

6

If you are not restricted with Firefox, you can use Google Chrome's extension Header Hacker.

It provides:

  1. custom request headers (you're able either add new headers or override existing ones)
  2. permanent headers for specified hosts (you're able either add new headers or override existing ones)

So that you can solve your problem with second feature.

I'm using the extension a lot and it works fine for me.

4
  • Thanks. I’m restricted to Firefox, but your answer might of course be helpful for others. :)
    – unor
    Aug 22, 2013 at 16:13
  • 1
    The link is broken Sep 9, 2014 at 8:10
  • 1
    @TahaJahangir the extension's maintainer have changed the name of the app recently. I have updated the broken link. And yes, the extensions is really helpful -- I'm using it on daily basis
    – ajukraine
    Sep 16, 2014 at 13:23
  • what if the extension has a bug, or the extension does not work with the browser version you'd like or if the developers simply stopped updating the extensions ? I see this happening for most, if not all Firefox extensions which let you add/modify request headers.
    – MasterJoe
    Dec 28, 2017 at 0:50
5

The Firefox add-on, Header Tool, does what you are looking for: https://addons.mozilla.org/en-us/firefox/addon/header-tool/

I just tried it out to restrict my custom request header to localhost.

2
  • 1
    what if the extension has a bug, or the extension does not work with the browser version you'd like or if the developers simply stopped updating the extensions ? I see this happening for most, if not all Firefox extensions which let you add/modify request headers.
    – MasterJoe
    Dec 28, 2017 at 0:50
  • 2
    This extension is defunct with Firefox 57. Jul 11, 2018 at 20:34
3

You can do this very easily by creating a header rule in Requestly. It is an open-source extension + desktop app that lets you modify your network requests using easy-to-create rules.

Install the addon on firefox and then navigate to https://app.requestly.io

Click on New Rule and select the Modify Headers Rule. This should open the rule editor.

New header rule

To apply the rule only on foo.example.com you can set the destination option to be Host equals foo.example.com

Rule destination using host

You can also do advanced matching based on the requested resource type, method type, etc. using the advanced filters

Although there is no way to specify the protocol, you can still only target https requests either with the contains option

URL contains

or using regex

URL match regex

Now click on Add Request Header and enter the header values that you want to add

Save the Rule and go to the target site. You should now see the header being added to every request that matches the condition.

And these rules can be easily synced across any browser, so you just have to create the rule once and this will work anywhere you have requestly installed.

You can read more about Modify Headers rule, in the docs

FYI: I actively contribute to Requestly. So this solution, although a little biased, is the simplest that I know of

2

Since the release of Firefox 57, I've found the plugin Modify Header Value does the trick.

Modify Header Value can add, modify or remove an HTTP-request-header for all requests on a desired website or url.

0

in case you need to spoof your user-agent:

Custom UserAgent String: "Add a custom useragent string for desired URLs or domains."
this addon will not change your javascript user-agent.

to also change the JS UA, add this user-script to greasemonkey:

// ==UserScript==
// @name        Change navigator.userAgent
// @namespace   Rob W
// @description Changes navigator.userAgent to IE on IEGallery.com
// @match       http://www.iegallery.com/*
// @run-at      document-start
// @grant       none
// @version     1
// ==/UserScript==

Object.defineProperty(navigator, 'userAgent', {
    value: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'
});

these outdated addons do not work with current firefox:

  • UAControl: This extension will allow you to control what string is sent as the User-Agent in HTTP header, per each site (domain).
    Note this cannot control the native User-Agent string used by JavaScript (e.g. navigator.userAgent).
  • ua-site-switch: change the User Agent for the current domain.
    The UA is only changed in the request HTTP header, so it does not prevent Javascript to determine the real UA.
    If you need to change the UA at the javascript level, you can use a nice addon called User-Agent JS Fixer.
  • User-Agent JS Fixer: This addon can change the JavaScript User-Agent on a per-site basis, rather than changing for the whole session.
    It does nothing by itself, but it complements the functionality of another addon like UAControl or ua-site-switch. No additional configuration is required, it uses the same settings from them.
    All it does is to redefine the User-Agent for JavaScript code (navigator.userAgent) using the same string that was sent on the HTTP header.

[ .... as a starting point, if someone wants to write a better addon ]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .