
Repositories, docs, and more, generated from structured Open-source Python applications arranged by topic, with links to This document is an always-growing list of 407 Production application is worth a thousand blog posts and Stack When building our own applications, open-source Python applicationsĪre a gold mine of practical patterns that we know work together. This on is mostly modules, packages, libraries, frameworks, and the At least in this example, you’d probably be safe with a whitelist and logic to reject input containing special characters.Case studies in successfully shipping Python softwareĪs developers, we spend our days with code. Remember, always escape your output but also validate your input! Most names don’t include less than and/or greater than symbols. We’ve taken a look at some of the features provided in Flask for output escaping, the potential issues, and the fixes available should you come across some vulnerable code.

Second, the fix, encapsulating output in an attribute context in single/double quotes will resolve this issue. First, the problem: our injected payload executed due to the name parameter appearing in the context of an HTML attribute. Person = and using the |e filter to manually escape output, we should be safe from injection, right? Consider the following snippet of code:įrom flask import Flask, request, render_template_string, render_templateĪpp = Flask ( _name_ ( '/hello-template-injection' ) Let’s take a look at using the template string functionality to explore some security concerns. Depending on the context of the application this could allow for arbitrary remote code execution (RCE). Execution of this input occurs within the context of the server. Briefly, this vulnerability allows an attacker to inject language/syntax into templates. If you’re unfamiliar check out the whitepaper( PDF) by James Kettle. The template engine provided within the Flask framework may allow developers to introduce Server-Side Template Injection vulnerabilities.

Flask allows for the creation of templates using strings of HTML in the Python source code or laid out in static files in a templates directory local to your project.

It’s easy to use and is configured out-of-the-box to autoescape content in. Let’s talk about injectionįor its presentation layer, Flask leverages the Jinga2 engine. Flask is a lightweight python framework that provides a simple yet powerful and extensible structure (it is Python after all). If you’ve never had the pleasure of working with Flask, you’re in for a treat. In this adventure we will discuss some of the security features available and potential issues within the Flask micro-framework with respect to Server-Side Template Injection, Cross-Site Scripting, and HTML attribute injection attacks, a subset of XSS.
