Difference between ssl_context options in Python Flask Difference between ssl_context options in Python Flask flask flask

Difference between ssl_context options in Python Flask


With first two options, you provide a certificate of your own, that might (should) be either signed by a recognized authority or by your client if you manage them (this happens either if your application is deployed in a context where you can install your certificate on each computer or if your client is not a web browser but your application and you can ship the certificate with it).

This will show the user he is communicating with the real server, not with someone trying to eavesdrop the traffic.

The third option will create a self-signed certificate, offering no guarantee to the user on that matter.

In terms of user experience, using a self-signed certificate when the client is a Web browser will raise a worrying message about the certificate validity, and saying something like "serious web sites would not ask you to blindly accept an unknown certificate".

To sum-up, you have three options (your options 1 & 2 are the same in the end):

  • option 1 & 2 with a certificate signed by a recognized authority: the only good solution for a public Web application / Web site.
  • option 1 & 2 with a certificate of your own (or signed by an authority of your own), deployed on every client: a good solution when you can install the certificate on each client. A poor solution if you have to ask your clients to do so.
  • option 3: a good solution for testing in a lab. A terrible solution in any other context I can think of.


3. Security is the only one that matters, and the answer is "never use the Werkzeug/Flask dev server in production." The ssl_context option is there for convenience during testing, but a production application should use real application and web servers such as uWSGI along with Nginx, configuring Nginx appropriately to present a real TLS certificate.