Skip to content

[WIP] Harden authentication and protect sensitive tokens#60

Closed
BigSimmo with Copilot wants to merge 3 commits into
mainfrom
copilot/harden-authentication-and-protect-tokens
Closed

[WIP] Harden authentication and protect sensitive tokens#60
BigSimmo with Copilot wants to merge 3 commits into
mainfrom
copilot/harden-authentication-and-protect-tokens

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>Harden authentication and protect sensitive tokens</issue_title>
<issue_description>### Problem

  • requireAuthenticatedUser falls back to a local “no-auth” mode if no bearer token is supplied, using cached owner‑ID lookups or deriving the owner from the last imported document. This bypass allows unauthorised access if an attacker crafts requests without tokens.
  • The front-end persists Supabase refresh tokens and the user’s email in browser localStorage, leaving them vulnerable to cross‑site scripting (XSS) or multi-user environment leaks.
  • The ingestion pipeline automatically uploads and captions images and stores captions and classification metadata in the database. If the image‑classification model misclassifies an image (e.g. a patient identifier), the caption may include sensitive text that is stored unredacted.
  • Several scripts still log Supabase errors with full details, and those logs may be sent to third-party monitoring. This can expose sensitive data (document names, user IDs).

Recommendations

  • Remove the no-auth fallback in production and always validate bearer tokens against Supabase auth. Ensure that all routes require proper authentication.
  • Store session tokens in secure cookies (e.g. HttpOnly and SameSite=Lax) or use in-memory session storage instead of localStorage to reduce the risk of token theft.
  • Introduce a manual review or filtering step before persisting generated captions. De-identify or redact potential identifiers in the captions.
  • Use the existing safeErrorLogDetails helper consistently across the codebase to redact sensitive paths, URLs and secrets before logging. Avoid logging full Supabase error details to external services.
    </issue_description>
  • Closes Harden authentication and protect sensitive tokens #53

<agent_instructions>Please implement logical and efficient fixes to these issues. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@BigSimmo
BigSimmo marked this pull request as ready for review June 23, 2026 05:55
@BigSimmo BigSimmo closed this Jun 26, 2026
@BigSimmo
BigSimmo deleted the copilot/harden-authentication-and-protect-tokens branch June 26, 2026 12:18
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
…iss class)

The monitoring-schedule answer gate was narrower than the fact filter and the
eval judge: inflected schedules (reviewed annually, monitored for 3 hours),
bare digit durations, and the level-range/metabolic-panel vocabulary passed
fact filtering but died at the gate or at kind classification, so answers for
those cases shipped without the asked-for schedule (run-#60 targeting misses).
One shared monitoringScheduleEvidencePattern now feeds both the gate and the
filter (lockstep by construction); the kind arm gains inflection tolerance
only (panel/range vocab would steal sentences from the dose arm — pinned by
the restored adjacent-context refusal test); and both the result-level and
sentence-level coverage checks gain a figure escape mirroring the existing
concrete-dose escape, tightly scoped to sentences/chunks that carry the
asked-for interval or unit range themselves. Four red-proof tests (each
verified failing pre-change) plus a negative guard pin the widen.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
BigSimmo pushed a commit that referenced this pull request Jul 21, 2026
…up layer

The neuroleptic-side-effect-escalation eval case failed the citation gate on
every canary (#57-#60): the query misclassifies as medication_dose_risk, its
honest lexical pool fails the dose fast-path floor (measured 0.184/0.0125 vs
0.66/0.055), the S3 document-lookup title layer that would surface the
title-named SOP was excluded by the class allowlist, and the vector leg then
injects the wrong sibling doc. shouldAttemptDocumentLookupFastPath now also
engages the layer for medication_dose_risk when the classifier's existing
deterministic signals say the query is escalation-shaped (intent
escalation_risk — only assigned when drug_dosing wording did NOT match, so
pure dose/route/frequency questions structurally cannot fire) AND a curated
title alias phrase is present for the alias tier to rescue with
(documentTitleTerms > 0). Rescue semantics by construction: the S3 block sits
after both fast-path returns, so a medication_dose_risk query only reaches it
once the floor already rejected the pool. Executed blast-radius sweep:
exactly one eval case fires across the 44-case answer canary, the 36-case
golden retrieval fixture, and the 30-case answer-quality harness — every
non-firing case executes byte-identical code. No imputation formula,
released-comparator key, selection clamp, or threshold is touched.

Red-proof: the predicate test and the end-to-end rescue ordering test both
fail with the gate reverted (verified); negative guards pin pure-dose,
no-title, and non-escalation shapes plus the four allowlisted classes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
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.

Harden authentication and protect sensitive tokens

2 participants