Python Flask Delete Path Traversal
Description
This detector identifies path traversal vulnerabilities in Flask applications where user-controlled input flows to file deletion operations. Path traversal attacks allow attackers to delete files outside the intended directory by using sequences like "../" to navigate the filesystem, potentially compromising application security or causing denial of service.
Detection Strategy
• Check if the Flask library is imported in the Python code
• Identify file deletion operations (such as calls to os.remove, os.unlink, pathlib.Path.unlink, or similar file deletion functions)
• Track data flow from Flask request parameters, form data, or route variables to the file deletion operations
• Report a vulnerability when user input can influence the file path being deleted without proper validation or sanitization
Vulnerable code example
from flask import Flask, request
import os
from pathlib import Path
app = Flask(__name__)
@app.route("/delete")
def delete_file():...✅ Secure code example
from flask import Flask, request, abort
import os
from pathlib import Path
from werkzeug.utils import secure_filename
app = Flask(__name__)
UPLOAD_DIR = "/uploads"...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.