Flask-Talisman

1.1.0 · active · verified Fri Apr 10

Flask-Talisman is a small Flask extension that sets HTTP security headers to help protect against common web application security issues like Cross-Site Scripting (XSS) and clickjacking. It provides a simple way to configure Content Security Policy (CSP), HTTP Strict Transport Security (HSTS), X-Frame-Options, and more. The library is actively maintained, with version 1.1.0 released in August 2023, and releases typically occur as needed for bug fixes or new feature/policy additions. [1, 3, 5]

Warnings

Install

Imports

Quickstart

This quickstart initializes a Flask application and applies default strict security headers using Flask-Talisman. The default configuration includes HTTPS enforcement (unless `debug=True`), HSTS, strict Content Security Policy, and more. [1, 2, 3]

from flask import Flask
from flask_talisman import Talisman

app = Flask(__name__)
# Initialize Talisman with default strict security headers
talisman = Talisman(app)

@app.route('/')
def hello():
    return 'Hello, Secure World!'

if __name__ == '__main__':
    # In production, ensure debug=False and serve over HTTPS
    # For local development, you might need to adjust Talisman's force_https or debug settings
    app.run(debug=True)

view raw JSON →