Skip to content

7/8 Security: fix the clinical-PDF exposure, SECRET_KEY from env, config hardening - #641

Open
mcfrank wants to merge 1 commit into
phase5-jscatfrom
phase6-security-config
Open

7/8 Security: fix the clinical-PDF exposure, SECRET_KEY from env, config hardening#641
mcfrank wants to merge 1 commit into
phase5-jscatfrom
phase6-security-config

Conversation

@mcfrank

@mcfrank mcfrank commented Jul 9, 2026

Copy link
Copy Markdown
Member

Continues the stack (targets the jsCat PR's branch; merge after #622). Closes #626, #627 — and effectively #630.

Please prioritize the review of this one. The audit found a real exposure: the researcher clinical-report PDF view (which renders child data) was reachable by guessable study pk with no authentication at all. Everyone assumed the custom LoginRequiredMiddleware covered it, but that middleware was a no-op — its LOGIN_EXEMPT_URLS ended with r"^", which matches every path. Worth checking whether any such PDF URL was ever shared outside the lab.

  • Clinical PDF view: now LoginRequiredMixin + ownership-scoped (get_queryset filters researcher=request.user). New tests assert anonymous → redirect, non-owner → 404.
  • Also gated: ProfileView and the two /interface/ajax/ endpoints (this also converts their previous anonymous 500s — Anonymous AJAX endpoints 500 on missing params #630 — into clean redirects).
  • Dead code removed: the no-op LoginRequiredMiddleware and LOGIN_EXEMPT_URLS, with a note in settings explaining that access control lives on the views (researcher views use LoginRequiredMixin; participant views are anonymous by hash-URL design).
  • Config: SECRET_KEY read from the environment first (generated-file fallback kept; production should set the env var — each fresh instance minting its own key invalidates sessions). GA ID → GOOGLE_ANALYTICS_ID (empty disables the snippet). Amazon gift-card URLs → settings.AMAZON_GIFT_CARD_URLS.

Tests: 7 tests that had encoded the insecure behavior (hitting protected endpoints anonymously) now authenticate; targeted download/ajax/PDF suites green (38 tests).

🤖 Generated with Claude Code

…oken login gating

The custom LoginRequiredMiddleware was a no-op: LOGIN_EXEMPT_URLS ended
with r"^", which matches every path, so nothing was ever gated by it.
Access control actually lives on the views — but the audit found three
that lacked it, including a real exposure: the researcher clinical-report
PDF view (child data) was reachable by guessable study pk with NO
authentication. It now requires login and is ownership-scoped
(get_queryset filters researcher=request.user); other researchers get
404, anonymous requests redirect to login. ProfileView and the two
/interface/ajax/ endpoints also gain LoginRequiredMixin (which turns
their previous anonymous 500s into clean redirects). The dead middleware
and LOGIN_EXEMPT_URLS are removed, with a note left in settings.

Config hardening: SECRET_KEY is read from the environment first (the
generated-file fallback stays so existing deploys keep working, but each
fresh instance minting its own key invalidates sessions — production
should set the env var). The Google Analytics ID moves to
GOOGLE_ANALYTICS_ID (empty disables the snippet entirely) and the Amazon
gift-card URLs move to settings.AMAZON_GIFT_CARD_URLS.

Tests: ajax/PDF view tests now authenticate; new tests assert the PDF
view redirects anonymous users and 404s non-owners. Fixes #626, #627.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant