Skip to content

fix: input hardening (CRIT-2, HIGH-2, HIGH-3, HIGH-5)#22

Merged
SPerekrestova merged 5 commits intomainfrom
fix/input-hardening
Mar 25, 2026
Merged

fix: input hardening (CRIT-2, HIGH-2, HIGH-3, HIGH-5)#22
SPerekrestova merged 5 commits intomainfrom
fix/input-hardening

Conversation

@SPerekrestova
Copy link
Copy Markdown
Owner

Summary

  • Reject empty/whitespace-only drug names and names >200 chars in /interactions (HIGH-2)
  • Add 5000-char limit to /analyze text input to prevent server crash (CRIT-2)
  • Strip HTML tags from raw_text response to prevent reflected XSS (HIGH-3)
  • Filter single-char and punctuation-only NER entities like - and ... (HIGH-5 partial)
  • Reject whitespace-only drug names via strip_whitespace (from code review)

Test plan

  • 155 tests pass (6 new validation + entity filtering tests)
  • Deploy to staging and verify 422 responses for empty/oversized inputs
  • Verify <script> tags stripped from /analyze response
  • Verify NER entity - no longer appears in drug results

🤖 Generated with Claude Code

SPerekrestova and others added 5 commits March 24, 2026 21:41
Add min_length=1 and max_length=200 per-item validation to the drugs
list in InteractionsRequest. Previously empty strings were accepted
and produced garbage interaction results from OpenFDA.

Fixes QA report HIGH-2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevents server crash (HTTP 500) when NER model receives very large
input. 5000 chars covers any realistic pill label or packaging text.

Fixes QA report CRIT-2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevents reflected XSS if raw_text is rendered in a browser without
escaping. Tags are removed but text content is preserved.

Fixes QA report HIGH-3.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
NER model sometimes extracts hyphens, dots, or other garbage from
packaging text (e.g. NDC codes). These are now rejected before
RxNorm lookup. Catches the '-' drug bug from QA report.

Fixes QA report HIGH-5 (partial — full fix via NER fine-tuning).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use StringConstraints(strip_whitespace=True) so "  " is stripped to ""
and then rejected by min_length=1. Caught by code review.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@SPerekrestova SPerekrestova merged commit 6942eb5 into main Mar 25, 2026
3 checks passed
@SPerekrestova SPerekrestova deleted the fix/input-hardening branch March 25, 2026 10:44
SPerekrestova added a commit that referenced this pull request Mar 25, 2026
Combines dosage/fallback changes with input hardening (PR #22) and
infrastructure (PR #23) changes. All 160 tests pass.

Co-Authored-By: Claude Opus 4.6 <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