Skip to content

Commit fd744af

Browse files
committed
Don't give non-admin users a full stacktrace on 500
As `traceback.format_exc()` might contain internal file paths, library versions, function names, and variable values.
1 parent fca5805 commit fd744af

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

cps/error_handler.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from flask_limiter import RateLimitExceeded
2323
from flask_babel import gettext as _
2424
from werkzeug.exceptions import default_exceptions
25+
26+
from .cw_login import current_user
2527
try:
2628
from werkzeug.exceptions import FailedDependency
2729
except ImportError:
@@ -62,14 +64,21 @@ def internal_error(error):
6264
error_stack="",
6365
instance=config.config_calibre_web_title
6466
), 500
67+
log.error("500 Internal Server Error: %s", traceback.format_exc())
68+
error_stack = ""
69+
try:
70+
if current_user.is_authenticated and current_user.role_admin():
71+
error_stack = traceback.format_exc().split("\n")
72+
except Exception:
73+
pass
6574
return render_template('http_error.html',
6675
error_code="500 Internal Server Error",
6776
error_name='The server encountered an internal error and was unable to complete your '
6877
'request. There is an error in the application.',
6978
issue=True,
7079
goto_admin=False,
7180
unconfigured=False,
72-
error_stack=traceback.format_exc().split("\n"),
81+
error_stack=error_stack,
7382
instance=config.config_calibre_web_title
7483
), 500
7584

0 commit comments

Comments
 (0)