views:

119

answers:

1

I am posting this question on Super User as well. In my opinion this question overlaps the two...


I am creating a simple JavaScript wrapper for CouchDB's REST-ful interface, but I am stuck on same-origin policy issues.

So far I've been developing my code to work locally - and only as a proof of concept - on Mozilla FireFox. My server is running on localhost, port 5984.

To disable cross-origin policy in Mozilla FireFox you can use the PrivilegeManager, but it only gets me half-way in the sense that I can't do PUT requests against my server...

/*
 * Including this in my JavaScript file only seems to disable cross-origin
 * policy checks for POST and GET requests in Mozilla FireFox.
 * PUT requests fail.
 */

netscape.security.PrivilegeManager.enablePrivilege(
    "UniversalBrowserRead UniversalBrowserWrite"
);



Is there any way that I can configure my server to hide it's location so I won't have to implement browser-specific work-arounds to avoid same-origin policy issues? If not: what browser work-arounds exist to disable same-origin policy completely?

+3  A: 

Unfortunately, any browser workarounds to disable same-origin policies are likely to be treated as serious security bugs and fixed as soon as possible.

See if you can come up with a way to work within the same-origin policy without trying to bypass it.

Can you serve your example scripts on the target server? Could you build a reflection script that would load the target script on your server after a local script on the users computer uploaded whatever they modified?

There should be a good solution that doesn't involve bypassing the same-origin policy. Trying to hack your way around it is a good way to ensure that your code doesn't work properly in future browsers.

Paul McMillan
So serving my JavaScript files from the CouchDB server would solve my cross-origin issues?
roosteronacid
That would be one option. Since CouchDB isn't usually set up for direct user interaction, it's not a standard setup. Depending on how your servers are configured, you might alias a URL to your database server.
Paul McMillan
So if I we're to serve my scripts from my CouchDB server instance, would I experience SOP-issues when using those scripts in a file run from the file system?
roosteronacid
... That is to say: If reference my JavaScript wrapper from the CouchDB instance (`http://localhost:5984/_utils/wapper.js`) in a file located on the filesystem. Would I get any SOP errors when calling functions from wrapper.js that executes GET/POST/PUT etc. requests to the CouchDB server?
roosteronacid
Unfortunately, local file system SOP gets weird. Some browsers are more strict, some are less. If you're accessing a file using `http://localhost/` syntax, you're stuck with the web-model. If you're accessing the file with a `file://` style syntax, you will get different permissions.
Paul McMillan