Git Product home page Git Product logo

Comments (14)

Helveg avatar Helveg commented on July 18, 2024 2

The philosophy is sound, it leads to simple effortless setup of CORS. In the context of security this ease-of-use could lead to carelessness, and as the most popular package for CORS for Flask you shape the landscape quite a bit. As probably mentioned before in this thread, CORS is encountered more as an annoyance than as a security concern. That's why I'd argue the philosophy shouldn't centre 100% around ease-of-use, but also incorporate responsibility around the defaults you promote. The proper default behaviour, which will overlap with most if not all use-cases of people unfamiliar with CORS, that will blindly rely on the defaults, is that you want your app, not any app, to communicate with your server, which corresponds to the Same Origin policy.

Both CSRF and XSS attacks are enabled by lack of CORS. Without proper CORS users of your domain are vulnerable to pretty devastating "one-click attacks", where just by following a link they've received that leads to a perfectly valid domain, stealth attacks can be performed on other domains and even local services/containers running on localhost:

I came here because a developer of a scientific software decided to use Flask for a sandbox, which executes arbitrary code, and they in their browser got slapped with the CORS error, and used these default settings, turning a trusted piece of scientific software into an XSS trojan horse.

You'll also see that on any/all cloud providers, identity providers and OAuth2, the allowed CORS origins are important security settings, that they do not default to "*". Asking the user to consider the question "from where will my users initiate actions?" seems like a reasonable ask for a CORS package! 😄 If they want to answer "from anywhere", it'll only cost them 1 character to reply * 👍

from flask-cors.

derek-adair avatar derek-adair commented on July 18, 2024 1

This is something that would make a great pull request ;)

from flask-cors.

Helveg avatar Helveg commented on July 18, 2024 1

I came here to open just the same exact issue. Many, let's say 5 nines of all developers, see CORS as a frustration and just disable it, but it is an important measure to limit the severity of XSS attacks. Flask-CORS' current defaults contribute to this nonchalance by by default completely disabling CORS. The documentation should be restructured so that the index page explains how to actually safely allow access from a whitelist, and only later on, and with a big fat warning, introduce the '*' as an option!

It's bad enough to have a security vulnerability, it's worse that anyone can exploit it from the victim's machine merely by browsing to a domain the attacker controls!

from flask-cors.

corydolphin avatar corydolphin commented on July 18, 2024 1

Hey folks,

Loosely held opinions open to change.

First, everything above is probably accurate.

This package has a simple philosophy: when you want to enable CORS, you wish to enable it for all use cases on a domain. This means no mucking around with different allowed headers, methods, etc.

By default, submission of cookies across domains is disabled due to the security implications. Please see the documentation for how to enable credential'ed requests, and please make sure you add some sort of CSRF protection before doing so!

The main security attack vector I'm familiar with with CORS is via CSRF, which is why cookies are disabled by default. I'm open to changing this such that the default is to ask for an origin list, with special handling of "*".

Honestly, this library could use a major version bump to land a number of improvements to the API which weren't thought of in the beginning, in addition, it may be useful to introduce MyPy support and break python version support compatibility.

@derek-adair Is that something you would be interested in championing?

from flask-cors.

corydolphin avatar corydolphin commented on July 18, 2024 1

Hello,

First, I'd love to have more maintainers who can help to continue to support this project since I do not use Flask on a regular cadence at this point. Second, I'd love to see a PR which changed the behavior and bumped the major version, I'd happily approve it and help support the release

from flask-cors.

derek-adair avatar derek-adair commented on July 18, 2024

This is a very good point. I'd be willing to guess a LOT of people here are using this project to bypass CORS altogether. It's a much more secure default. An option to disable same origin restriction is probably the safer decision here.

from flask-cors.

Helveg avatar Helveg commented on July 18, 2024

To get this Same Origin behaviour, I should grab the host and protocol as the default value for origins, right? I can PR that and propose a draft for the doc index.

Since this could be seen both as a security vulnerability fix, and as a breaking change for all these people who didn't actually secure their app, do we introduce it as a patch version bump, or major version? 😂

from flask-cors.

derek-adair avatar derek-adair commented on July 18, 2024

this would be a major version bump a la breaking changes.

As for how this should be done I've not had a chance to think on that and would be something the maintainer would need to weigh in on.

from flask-cors.

derek-adair avatar derek-adair commented on July 18, 2024

@derek-adair Is that something you would be interested in championing?

...as the most popular package for CORS for Flask you shape the landscape quite a bit..

This gives me anxiety. I'll consider it but probably not. I dont think I have the right mindset for such an important project. I may however know someone who would have a LOT to add to this project that is a huge security nerd.

from flask-cors.

derek-adair avatar derek-adair commented on July 18, 2024

I came here because a developer of a scientific software decided to use Flask for a sandbox, which executes arbitrary code, and they in their browser got slapped with the CORS error, and used these default settings, turning their local sandbox into an XSS trojan horse.

Yaaaa. This is exactly the kind of thing some more tight defaults will prevent. Giving a novice dev the ability to bypass DECADES of progress in browsers locking down/preventing/warning devs and users about CORS is not ideal.

from flask-cors.

n1ngu avatar n1ngu commented on July 18, 2024

Fully agree that default should not be to whitelist '*' and the package deserves a major bump. The issue importance and severity has already been clearly stated.

Yet, AFAIU, same-origin policy can be enforced by... not using flask-cors nor anything at all?

from flask-cors.

Helveg avatar Helveg commented on July 18, 2024

So what needs to be done to pull the trigger on this @corydolphin ? I have time to PR it.

from flask-cors.

n1ngu avatar n1ngu commented on July 18, 2024

AFAIU it boils down to simply replacing the "*" value for and empty list in flask_cors.core.DEFAULT_OPTIONS["origins"].

Then I think this deserves a unit test to assert the default configuration from the simplest examples (either via the flask extension or the function decorator) do enforce a same-origin policy by default.

Also, documentation should be reviewed because some examples won't make sense. And maybe updated to emphasize everybody should whitelist specific domains and avoid "*".

IMHO raising a warning if someone configures a wildcard origin would not be out of scope. I guess the right place for such check would be the flask_cors.core.serialize_options function. But this is arguable.

Later, package major version should be bumped when releasing this.

I am unaware of further considerations.

from flask-cors.

Helveg avatar Helveg commented on July 18, 2024

I took a look at the open issues and pull requests, and I'm willing to triage wherever I can!

from flask-cors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.