use uv, ruff, prek; update tests gh-workflow#1754
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
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month 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
| @@ -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
359c2cf to
472659f
Compare
472659f to
328267c
Compare
| uses: github/codeql-action/init@v4 | ||
| with: | ||
| languages: ${{ matrix.language }} | ||
| languages: ${{ matrix.language }} # TODO unknown reference? |
| while [ true ]; do | ||
| echo "Running cron job" | ||
| /usr/local/bin/python3 -m ephios run_periodic | ||
| uv run python -m ephios run_periodic |
There was a problem hiding this comment.
is uv available in the container?
| @@ -984,13 +984,13 @@ var Vue = (function (exports) { | |||
| } | |||
| const targetMap = /* @__PURE__ */ new WeakMap(); | |||
| const ITERATE_KEY = Symbol( | |||
| "Object iterate" | |||
| "Object iterate" | |||
There was a problem hiding this comment.
bit weird that we are linting dependencies
There was a problem hiding this comment.
oh I did that by accident once and wanted to undo those changes. Is this the only place I missed that you found?
| ("de", gettext_lazy("German")), | ||
| ("en", gettext_lazy("English")), | ||
| ] | ||
| LANGUAGES = [("de", gettext_lazy("German")), ("en", gettext_lazy("English"))] |
closes #1641
uv formatas well)srcfolder as suggested in the uv docs and pypi docs