Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test-apps/02-flask-blog-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,6 @@ def setup_rbac(rbac: RBAC):
║ ║
╚════════════════════════════════════════════════╝
""")
app.run(debug=True, host='0.0.0.0', port=5000)
# Use debug flag from app config (controlled via FLASK_DEBUG env var) rather than
# hardcoding debug=True, which would enable the interactive debugger in production.
app.run(debug=app.config.get('DEBUG', False), host='0.0.0.0', port=5000)
5 changes: 3 additions & 2 deletions test-apps/02-flask-blog-api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ def decorated_function(*args, **kwargs):
'message': 'Please login again'
}), 401

except jwt.InvalidTokenError as e:
except jwt.InvalidTokenError:
# Do not expose internal JWT error details to the client
return jsonify({
'error': 'Invalid token',
'message': str(e)
'message': 'Token is invalid'
}), 401

return decorated_function
Expand Down
7 changes: 6 additions & 1 deletion test-apps/02-flask-blog-api/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
RBAC Decorators for Flask Blog API.
Provides decorators for permission and role-based authorization.
"""
import logging
from functools import wraps
from flask import g, jsonify
from auth import get_current_user

logger = logging.getLogger(__name__)


def require_permission(action: str, resource_type: str = None, check_ownership: bool = False):
"""
Expand Down Expand Up @@ -110,9 +113,11 @@ def decorated_function(*args, **kwargs):
return f(*args, **kwargs)

except Exception as e:
# Log the full error internally; do not expose exception details to the client
logger.error('Authorization check failed: %s', str(e), exc_info=True)
return jsonify({
'error': 'Authorization error',
'message': f'Failed to check permissions: {str(e)}'
'message': 'Failed to check permissions'
}), 500

return decorated_function
Expand Down
Loading