-
Notifications
You must be signed in to change notification settings - Fork 12
use uv, ruff, prek; update tests gh-workflow #1754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
4b1b283 to
54d8054
Compare
| return JsonResponse({ | ||
| "state": consequence.state, | ||
| "fail_reason": fail_reason, | ||
| }) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 7 days ago
In general, to fix this class of issue you should avoid sending raw exception messages or stack traces directly to clients. Instead, log the detailed information on the server (where developers can inspect it) and return either a generic error message or a sanitized, predefined user-facing message. This prevents accidental disclosure of internal state or implementation details.
For this specific view in src/ephios/core/views/consequences.py, the minimal-impact fix is:
- Stop using
str(e)directly asfail_reason. - Replace it with a generic, non-sensitive message (e.g.
"confirm_failed"or a short human-readable text) that does not depend on the exception content. - Optionally, log the exception using Django’s logging facilities so that developers still have full details; this requires importing
loggingand using a module-level logger.
Concretely:
- Add an import for the standard
loggingmodule at the top ofconsequences.py, and define a logger such aslogger = logging.getLogger(__name__). - In the
except ConsequenceError as e:block, replacefail_reason = str(e)with:- a call to
logger.exception(...)(orlogger.warning/infoif preferred) to record the exception, and - assignment of
fail_reasonto a safe, generic string that can be returned to the client.
This preserves the existing JSON structure (stateandfail_reason) while eliminating exposure of exception text.
- a call to
-
Copy modified line R8 -
Copy modified lines R10-R12 -
Copy modified lines R25-R26
| @@ -5,7 +5,11 @@ | ||
|
|
||
| from ephios.core.consequences import ConsequenceError, editable_consequences | ||
|
|
||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ConsequenceUpdateView(LoginRequiredMixin, SingleObjectMixin, View): | ||
| def get_queryset(self): | ||
| return editable_consequences(self.request.user) | ||
| @@ -19,7 +22,8 @@ | ||
| try: | ||
| consequence.confirm(request.user) | ||
| except ConsequenceError as e: | ||
| fail_reason = str(e) | ||
| logger.exception("Error while confirming consequence %s for user %s", consequence, request.user) | ||
| fail_reason = "confirm_failed" | ||
| return JsonResponse({ | ||
| "state": consequence.state, | ||
| "fail_reason": fail_reason, |
c0efe1b to
1d2d606
Compare
uv system fix locale building fix locale building fix locale building fix locale building fix signals import
refix pylint
e6317fc to
ae0f0a6
Compare
closes #1641
uv formatas well)srcfolder as suggested in the uv docs and pypi docs