Performance: Allowed file types validation
MEDIUM IMPACT
This affects page load speed and user interaction responsiveness by preventing unnecessary file uploads and server processing.
from flask import request ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS file = request.files['file'] if file and allowed_file(file.filename): file.save('/uploads/' + file.filename) else: return 'Invalid file type', 400
from flask import request file = request.files['file'] # No validation on file type file.save('/uploads/' + file.filename)
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No file type validation | N/A | N/A | N/A | [X] Bad |
| Early file type validation on server | N/A | N/A | N/A | [OK] Good |