Code-scanning cleanup¶
Branch chore/code-scanning. Source: the open alerts on
https://github.com/EPFL-ENAC/co2-calculator/security/code-scanning.
Security fixes (errors)¶
- py/log-injection (
app/repositories/location_repo.py): the raw user searchquerywas interpolated into log lines. Newlines are now stripped (safe_query) before logging so a crafted query can't forge log entries. - py/stack-trace-exposure (
app/main.py/ready): the readiness response returneddetailscontainingstr(e)for DB / Accred failures to unauthenticated callers. Details now stay in the warning log only. - Regression tests:
tests/unit/test_security_alert_fixes.py.
Behavior fix¶
get_unit_providercase _silently fell back to the database provider on an unknown provider type. Now raisesValueError, mirroringget_role_provider(no-silent-fallbacks invariant).
Mechanical fixes¶
- Duplicate constant block deleted in
core/constants.py; duplicatedata_entry_type_idcomputation deleted inapi/v1/carbon_report_module.py. - Unreachable re-check deleted in
modules/purchase/schemas.py. - Implicit string concatenation in seed SQL lists made explicit with
+. exit()→sys.exit()inscripts/{audit,migrate}_test_users.py; inlinetracebackimport hoisted.- Unused
loggerremoved fromtasks/reference_ingest_tasks.py. - Commented-out code removed (
carbon_report_module_repo.py); the parked metier-denied test intest_permission_scope_e2e.pyis now a real test under@pytest.mark.skipinstead of a comment block. - Test hygiene: empty
exceptblocks got explanatory comments, unused locals/imports removed,import+from-importduplication resolved,lambda: _user()→_user. frontend/scripts/gen-api-types.mjs: live OpenAPI payload is round-tripped throughJSON.parsebefore staging, so non-JSON responses fall back to the snapshot.
Triaged as false positive / won't fix (not code changes)¶
Not all of these were dismissed on GitHub: 35 alerts were on 2026-07-20, but others were still open in November. See #3185, which fixes some in code and lists the rest for dismissal.
py/ineffectual-statementon...bodies:typing.Protocolstubs.py/unused-importon side-effect imports (model registration indb.py/alembic/env.py, handler registration in seed modules).py/mixed-returnsonmatchstatements whosecase _raises.py/cyclic-importacrossapp/tasks/*and the two carbon-report services: deliberate, documented lazy-import cycles (Plan 310-C); restructuring the pipeline is out of scope while the lead is away.py/unexpected-raise-in-special-method: the_ForbiddenSessionsentinel raisesAssertionErrorby design.py/unused-global-variableon_BOOTSTRAPPED: it is read as the idempotency guard.