Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

Allow for a null origin (file URL) in the whitelist #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jrsupplee
Copy link

This patch allows for a straight-forward way of adding a file based URL (null origin) to the whitelist

@ericholscher
Copy link

Is null specified somewhere as a standard way of representing file:// URL's?

@jrsupplee
Copy link
Author

If you do a cross origin request from a file URL you can see that the header value Origin is set equal to "null". Seems to me I have seen it in the specs too.

@jrsupplee
Copy link
Author

Can't find it in any specs. Maybe I missed it. There is a lot of stackoverflow stuff that talks about null origin for file URLs. Chrome and Firefox both set the header Origin value to null when the page is loaded from a file URL.

@jrsupplee
Copy link
Author

jrsupplee commented Jul 27, 2016

I have been thinking about this and the way the origin whitelist is implemented is not optimal. It is not actually a list of origins, but rather a list of origins stripped of their protocols. Maybe origin_not_found_in_white_lists should be changed to allow protocols by comparing the whitelists against the actual origin header value as well as the protocol stripped URL.

def origin_not_found_in_white_lists(self, origin, url):
    return (
        url.netloc not in settings.CORS_ORIGIN_WHITELIST and
        origin not in settings.CORS_ORIGIN_WHITELIST and
        not self.regex_domain_match(origin)
    )

This would allow whitelist entries that include protocols. So you could accept https://some.domain.com and reject http://some.domain.com. It also allows for the null origin without my proposed hack.

@adamchainz
Copy link

N.B. in upstream PR adamchainz#101 I decided not to add this since I couldn't find good information that setting Origin to 'null' for file:// urls is actually standard, and also it can be added with a custom signal handler anyway.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants