Python Django Write Path Traversal
Description
This detector identifies Django applications vulnerable to path traversal attacks during file write operations. When user-controlled input is passed directly to file write functions without proper path validation, attackers can use sequences like "../" to write files outside the intended directory, potentially overwriting sensitive system files.
Detection Strategy
• Django framework must be imported in the code (checks for django library imports)
• Code must contain file write operations (functions like open(), file.write(), or similar file writing methods)
• User input must flow into the file path parameter of write operations without proper sanitization
• The data flow from user input to the write destination must be traceable through the code
Vulnerable code example
from pathlib import Path
from django.http import HttpResponse
import shutil
def write_file_vulnerable(request):
filename = request.GET["filename"]
...✅ Secure code example
from pathlib import Path
from django.http import HttpResponse
import shutil
import os
BASE_DIR = Path("uploads")
def write_file_secure(request):...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.