Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable same origin policy in Chrome

Is there any way to disable the Same-origin policy on Google's Chrome browser?

like image 330
Landon Kuhn Avatar asked Jun 23 '10 15:06

Landon Kuhn


People also ask

How do I enable CORS policy in chrome?

Allow CORS: Access-Control-Allow-Origin. Easily add (Access-Control-Allow-Origin: *) rule to the response header. Allow CORS: Access-Control-Allow-Origin lets you easily perform cross-domain Ajax requests in web applications. Simply activate the add-on and perform the request.

How do I fix CORS problem in chrome?

i. Turn OFF the CORS plugin, reload the app, at this time you should still get the errors which are correct. ii. Turn it back ON, reload the app, if the APIs are successful, stop here, no need to proceed to iii.


2 Answers

Close chrome (or chromium) and restart with the --disable-web-security argument. I just tested this and verified that I can access the contents of an iframe with src="http://google.com" embedded in a page served from "localhost" (tested under chromium 5 / ubuntu). For me the exact command was:

Note : Kill all chrome instances before running command

chromium-browser --disable-web-security --user-data-dir="[some directory here]" 

The browser will warn you that "you are using an unsupported command line" when it first opens, which you can ignore.

From the chromium source:

// Don't enforce the same-origin policy. (Used by people testing their sites.) const wchar_t kDisableWebSecurity[] = L"disable-web-security"; 

Before Chrome 48, you could just use:

chromium-browser --disable-web-security 
like image 148
Dagg Nabbit Avatar answered Oct 01 '22 16:10

Dagg Nabbit


Yep. For OSX, open Terminal and run:

$ open -a Google\ Chrome --args --disable-web-security --user-data-dir 

--user-data-dir required on Chrome 49+ on OSX

For Linux run:

$ google-chrome --disable-web-security 

Also if you're trying to access local files for dev purposes like AJAX or JSON, you can use this flag too.

--allow-file-access-from-files 

For Windows go into the command prompt and go into the folder where Chrome.exe is and type

chrome.exe --disable-web-security 

That should disable the same origin policy and allow you to access local files.

Update: For Chrome 22+ you will be presented with an error message that says:

You are using an unsupported command-line flag: --disable-web-security. Stability and security will suffer.

However you can just ignore that message while developing.

like image 40
ectype Avatar answered Oct 01 '22 15:10

ectype