Disable firefox same origin policy
Asked Answered
O

8

134

I'm developing a local research tool that requires me to turn off Firefox's same origin policy (in terms of script access, I don't really care about cross domain requests).

More specifically, I want scripts in the host domain to be able to access arbitrary elements in any iframes embedded in the page, regardless of their domain.

I'm aware previous Q&As which mentioned the CORS FF extension, but that is not what I need, since it only allows CORS, but not script access.

If it cannot be done easily, I would also appreciate any insights that point me to specific part of FF src code that I can modify to disable SOP, so that I can recompile FF.

Ovular answered 13/6, 2013 at 13:41 Comment(3)
It would be an interesting thing with developers. Since the same origin policy is designed for the security of the users and not the developers, it should be made possible to allow the scripts from the given site to go across the restrictions. But developers are also people, so you could loose your personal information as well.Constancy
I believe it's not possible right now, here is related bug report in Firefox Bugzilla: bugzilla.mozilla.org/show_bug.cgi?id=1039678Quixote
Only good solution is to inject the headers by plugin based on domains: https://mcmap.net/q/54974/-disable-firefox-same-origin-policy Everthing else is insecure...Scapegrace
P
93

There's a Firefox extension that adds the CORS headers to any HTTP response working on the latest Firefox (build 36.0.1) released March 5, 2015. I tested it and it's working on both Windows 7 and Mavericks. I'll guide you throught the steps to get it working.

1) Getting the extension

You can either download the xpi from here (author builds) or from here (mirror, may not be updated).

Or download the files from GitHub. Now it's also on Firefox Marketplace: Download here. In this case, the addon is installed after you click install and you can skip to step 4.

If you downloaded the xpi you can jump to step 3. If you downloaded the zip from GitHub, go to step 2.

2) Building the xpi

You need to extract the zip, get inside the "cors-everywhere-firefox-addon-master" folder, select all the items and zip them. Then, rename the created zip as *.xpi

Note: If you are using the OS X gui, it may create some hidden files, so you 'd be better using the command line.

3) Installing the xpi

You can just drag and drop the xpi to firefox, or go to: "about:addons", click on the cog on the top right corner and select "install add on from file", then select you .xpi file. Now, restart firefox.

4) Getting it to work

Now, the extension won't be working by default. You need to drag the extension icon to the extension bar, but don't worry. There are pictures!

  • Click on the Firefox Menu
  • Click on Customise

p1

  • Drag CorsE to the bar
  • Now, click on the icon, when it's green the CORS headers will be added to any HTTP response

p2

5) Testing if it's working

jQuery

$.get( "http://example.com/", function( data ) {
  console.log (data);
});

JavaScript

xmlhttp=new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
        console.log(xmlhttp.responseText);
    }
}

xmlhttp.open("GET","http://example.com/");
xmlhttp.send();

6) Final considerations

Note that https to http is not allowed.

There may be a way around it, but it's behind the scope of the question.

Pentagram answered 17/3, 2015 at 10:4 Comment(13)
You can disable HTTP/HTTPS mixed content protection by setting security.mixed_content.block_active_content to false and security.mixed_content.block_display_content to true. Keep in mind you are disabling some security and this should be a temporary solution.Fado
As the author of this addon, I'm not actually convinced it would solve this particular question. It's nice to get a mention though.Enfilade
@Enfilade - you should get your add on signed - I can't install it :( - support.mozilla.org/en-US/kb/…Emmott
@PeterAjtai Mozilla keeps on trying hard to annoy me I see. Awaiting review: addons.mozilla.org/en-US/firefox/addon/cors-everywhere Should hopefully get auto signed.Enfilade
doesnt work for me. CorsE icon is green, but XmlHttpRequest returns just empty String for example.com or google.com. It works for a file on localhost - so the example script should be ok.Multifaceted
in about:config set xpinstall.signatures.required to false to install the addon. It worked for me.Sabelle
Use Chrome because it's so much easier to disable CORS for developing.Amorphous
addons.mozilla.org/de/firefox/addon/cors-everywhere This is the addon mentioned above. It works great.Reeva
My addon also work with the latest version of Firefox too. With better UI and support JS regex. Check it out here: addons.mozilla.org/en-US/firefox/addon/cross-domain-corsWisdom
@Enfilade This is a really useful tool. Any plans for making it work on the new FF version?Willed
@Willed I switched to the WebExtensions API around 6 months ago, it should work unless Mozilla already broke compatibility, which I wouldn't know since I've stopped updating Firefox and nobody opened an issue on the tracker. Perhaps you missed the marketplace link ? addons.mozilla.org/firefox/addon/cors-everywhereEnfilade
@Enfilade It disappeared from my Firefox when I got Quantum. I installed it through that. (Review link: addons.mozilla.org/en-GB/firefox/addon/cors-everywhere/reviews/…)Willed
What. I just reinstalled it... and it works. And now it's gone from the Legacy Extensions list. I blame cosmic rays.Willed
R
66
about:config -> security.fileuri.strict_origin_policy -> false
Rudie answered 28/8, 2013 at 18:22 Comment(10)
Thanks @Niklas, however, i think this only disables fileuri same origin policy checks - probably used for local web dev testing. It still stops me when I'm trying to access DOM nodes in an iframe with domain B from a JavaScript in domain A.Ovular
this doesn't do anythingDimorph
As vknyvz says, it is uselessMucoviscidosis
Confirmed it does work in my firefox (developer) version: 40. Thank you for the tip @Niklas.Fado
Just found about XOriginPolicy, sendRefererHeader, spoofSource which may be useful for testing purposes bypassing CORS and all (sources: ghacks.net, b.agilob.net).Fado
This is a setting specifically for debugging, and controls a local files access to other local files (set to true a local file can only access local files in the same folder or sub folders, set to false a local file can access all local files). SourceSeng
Easiest workaround for CSS rules referencing local files, such as @font-face { url(local/path); ... }Cabbagehead
It does do something, in my case it allows me to access local resources from a document served over file:// protocol. Computer scientists ought to put more weight into the word "anything" -- unless you have tested everything (which you haven't), try to be more conservative with your remarks. Same goes for use of word "useless".Joanjoana
As someone trying to solve the problem of blocked fetch requests in Firefox Developer Edition when debugging locally, this didn't work for me.Ines
It crashed my Firefox when after making the change I tried to reload the local file that was the problem.Largescale
O
14

I realized my older answer is downvoted because I didn't specify how to disable FF's same origin policy specifically. Here I will give a more detailed answer:

Warning: This requires a re-compilation of FF, and the newly compiled version of Firefox will not be able to enable SOP again.

Check out Mozilla's Firefox's source code, find nsScriptSecurityManager.cpp in the src directory. I will use the one listed here as example: http://mxr.mozilla.org/aviarybranch/source/caps/src/nsScriptSecurityManager.cpp

Go to the function implementation nsScriptSecurityManager::CheckSameOriginURI, which is line 568 as of date 03/02/2016.

Make that function always return NS_OK.

This will disable SOP for good.

The browser addon answer by @Giacomo should be useful for most people and I have accepted that answer, however, for my personal research needs (TL;won't explain here) it is not enough and I figure other researchers may need to do what I did here to fully kill SOP.

Ovular answered 2/3, 2016 at 23:29 Comment(1)
Line 499 as of today, Git mirror: github.com/mozilla/gecko-dev/blob/…Ionogen
W
10

I wrote an add-on to overcome this issue in Firefox (Chrome, Opera version will have soon). It works with the latest Firefox version, with beautiful UI and support JS regex: https://addons.mozilla.org/en-US/firefox/addon/cross-domain-cors

enter image description here

Wisdom answered 21/5, 2017 at 4:23 Comment(2)
Thanks you. Additionally, there's also CORS-Everywhere Extension which is similar.Szeged
It's not working. I tried enabling it and I still get an error saying "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource".Subtenant
C
5

The cors-everywhere addon works for me until Firefox 68, after 68 I need to adjust 'privacy.file_unique_origin' -> false (by open 'about:config') to solve 'CORS request not HTTP' for new CORS same-origin rule introduced.

NOTE: 12/2021 updated. Since firefox 95 the 'CORS request not HTTP' can't be disabled by adjusting 'privacy.file_unique_origin'. See above 'CORS request not HTTP' link, it already updated by official rencently. The only way for me is '....Developers who need to perform local testing should now set up a local server.'

Clisthenes answered 16/7, 2019 at 10:26 Comment(0)
S
3

As of September 2016 this addon is the best to disable CORS: https://github.com/fredericlb/Force-CORS/releases

In the options panel you can configure which header to inject and specific website to have it enabled automatically.

enter image description here

Sunlight answered 9/9, 2016 at 21:0 Comment(3)
From wiki.mozilla.org/Add-ons/Extension_Signing: Firefox 48: Release and Beta versions of Firefox for Desktop will not allow unsigned extensions to be installed, with no override. I could not find a signed version of this addon.Marmara
@Marmara Here's how to do it: ghacks.net/2016/08/14/…Sunlight
@Marmara Firefox Developer Edition has an option "xpinstall.signatures.required" boolean in the "about:config" flags. However, version 0.1.1 of this extension is not compatible with Firefox Developer Edition 58.0 (Quantum).Minnow
I
1

For me worked by setting content.cors.disable to false

Imminence answered 15/9, 2021 at 12:17 Comment(0)
A
0

In about:config add content.cors.disable (empty string).

Abusive answered 26/4, 2020 at 13:46 Comment(4)
Has this been tested? From what I'm reading, this pref was designed to make all CORS requests fail when set to true, but says nothing about false or other values. "In Firefox, the preference that disables CORS is content.cors.disable. Setting this to true disables CORS, so whenever that's the case, CORS requests will always fail with this error." developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/…Anticoagulant
As of Firefox 68.7 this setting is not even available.Thereby
Found this setting in FF 84 but it didn't help me overcome my issue of FF wanting valid CORS policy to foreign server.Ines
in FF85 content.cors.disable exists, but its boolean, remove/edit is not possibleDirtcheap

© 2022 - 2024 — McMap. All rights reserved.