Loading...
Loading...
Directory traversal vulnerability allowing unauthorized file access through path manipulation.
1import os23def read_user_file(filename):4 # Read files from user uploads directory5 base_dir = '/var/www/uploads'6 file_path = os.path.join(base_dir, filename)78 with open(file_path, 'r') as f:9 return f.read()
The vulnerable code directly concatenates user input to the base directory without validation. Attackers can use ../ sequences to escape the intended directory. The secure version resolves paths and validates they remain within the base directory.
Use directory traversal to escape uploads folder
../../etc/passwdReads /etc/passwd instead of files in uploads