14

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
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 '13 at 16:13
  • 1
    The link is broken Sep 9 '14 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 '14 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 '17 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 '17 at 0:50
  • 2
    This extension is defunct with Firefox 57. Jul 11 '18 at 20:34
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 ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.