Skip to main content

Sanitization functions for Flask backend input to prevent XSS, RCE, SQLi and many others

Project description

Flask-Sanitize-Escape 🛡️

PyPI Version Github Build License: MIT Python Version Flask Version

A Flask middleware extension for automatic input sanitization, guarding against common web vulnerabilities like XSS, SQL injection, and other code injection attacks.

Key Features

  • Effortless Integration: Works in the middleware
  • Automatic Protection: Sanitizes incoming request data without requiring manual intervention in your route handlers.
  • Comprehensive Coverage: Scrubs query parameters, form data, and JSON payloads.
  • Targeted Defense: Neutralizes malicious code through HTML entity encoding and regex-based filtering.
  • Customizable: Easily adapt the sanitization logic to your specific application's needs.
  • Custom Escaping: Seamless custom escaping for specific characters as you need.

Installation

pip install flask-sanitize-escape

Usage

1. Activate Middleware:

from flask import Flask
from flask_sanitize_escape import SanitizeEscapeExtension  

app = Flask(__name__)

# Initialize the extension with options
sanitize_extension = SanitizeEscapeExtension(
    app, sanitize_quotes=True, custom_characters=["$", "#", "%"]
)

sanitize_extension.init_app(app) # Register the middleware

NOTE

It is suggested to use sanitize_quotes=True


2. Relax! Your application's input data is now automatically sanitized before it reaches your route handlers.

Example

@app.route('/submit', methods=['POST'])
def submit_data():
    data = g.sanitized_json  # accessing JSON from request.get_json()
    data = g.sanitized_args  # accessing arguments from request.args
    data = g.sanitized_form  # accessing values from request.form

    # Safely process the sanitized data...

Customization

Stay tune for upcoming version

Contributing

We welcome contributions! Feel free to open issues for bugs or feature requests, or submit pull requests with improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_sanitize_escape-0.0.3.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

flask_sanitize_escape-0.0.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file flask_sanitize_escape-0.0.3.tar.gz.

File metadata

  • Download URL: flask_sanitize_escape-0.0.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for flask_sanitize_escape-0.0.3.tar.gz
Algorithm Hash digest
SHA256 98f7dbc824886dbba6d305a4c2ef03c87edc930943694bbe8625bef7abf34a88
MD5 d940a4ae7fbd2c5c9c1ecb4b80ce406f
BLAKE2b-256 df16700423d781b432e2770d4f2c058374dcf7cdcbbc39ee037548726d80efa3

See more details on using hashes here.

File details

Details for the file flask_sanitize_escape-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sanitize_escape-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7b73a3b797b3c9d542de97668fcf29ecae627d29b8e48b61f277db59d28ee8a5
MD5 fe9b391a98a80a559c9fc80eb42c6278
BLAKE2b-256 09de2e6f1c14527cd7e149f197f45c76da119b2143fd84f36fa435c57322b3e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page