Security: Add @login_required to all API endpoints and CSRF protection
- Added @login_required decorator to all 38 unprotected API endpoints - Initialized Flask-WTF CSRFProtect in app factory - Added CSRF token meta tag to base.html - Added JavaScript fetch interceptor to attach X-CSRFToken header to all non-GET requests - Closes critical security vulnerability where any unauthenticated user could perform administrative actions
This commit is contained in:
1 parent
573fb9858c
commit
9f56c3943e
3 files changed
+59
No files matched your search
@@ -10,6 +10,7 @@ from flask_socketio import SocketIO
|
||||
from flask_talisman import Talisman
|
||||
from flask_limiter import Limiter
|
||||
from flask_limiter.util import get_remote_address
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
|
||||
from app.config import load_settings
|
||||
from app.services.database import DatabaseService
|
||||
@@ -43,6 +44,9 @@ def create_app(settings_path=None):
|
||||
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
||||
app.config['SESSION_COOKIE_SECURE'] = True # Always enforce secure cookies
|
||||
|
||||
# Initialize CSRF protection
|
||||
csrf = CSRFProtect(app)
|
||||
|
||||
ssl_enabled = bool(
|
||||
settings['dashboard'].get('ssl_cert')
|
||||
and settings['dashboard'].get('ssl_key')
|
||||
|
||||
Reference in new issue
Block a user