This repository was archived by the owner on Aug 22, 2026. It is now read-only.
Security review: clear all dependency vulnerabilities, harden chat API input - #3
Open
echotech wants to merge 1 commit into
Open
Security review: clear all dependency vulnerabilities, harden chat API input#3echotech wants to merge 1 commit into
echotech wants to merge 1 commit into
Conversation
npm audit reported 4 high-severity advisories (nanoid, next, picomatch, postcss) covering 20+ CVEs, which is what has been generating the daily Dependabot alert emails. This clears all of them: npm audit now reports 0 vulnerabilities. Dependencies: - next 14.2 -> 16.3.2. The Next.js advisories (SSRF in rewrites and Server Actions, cache poisoning, App Router XSS via CSP nonces, several DoS vectors, unauthenticated disclosure of Server Function endpoints) are only fully resolved in 15.5.21+, so a major upgrade was required. - react / react-dom 18.3 -> 19.2.8, required by Next 16. - @types/react and @types/react-dom bumped to match React 19. - postcss resolves to 8.5.23, nanoid to 3.3.18, picomatch to 2.3.2/4.0.5. - tsconfig.json: moduleResolution and jsx updated by the Next 16 migration. No application source changes were needed for the upgrade; the build, static generation, and the streaming chat route all work unchanged. API hardening (found during the review): - POST /api/chat called JSON.parse on caller-controlled input with no guard, so any malformed body produced an unhandled 500. It now returns 400. - The disease field was forwarded to the model with no length limit, letting an anonymous caller run up token cost on our API key. Now capped at 500 characters. Note: /api/chat remains unauthenticated and unrated-limited, which is the largest remaining exposure. That needs a rate limiter and is left out of this change deliberately. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EfzXHE5YUHyMmdWfm39xz6
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Clears every known dependency advisory in the repo, which is what has been generating the daily Dependabot alert emails.
npm auditonmainreports 4 high-severity vulnerable packages (next,postcss,nanoid,picomatch) spanning ~35 package/path/advisory pairs; GitHub currently counts 50 open alerts (21 high, 25 moderate, 4 low) across those same four packages. After this change, a cleannpm ci+npm audit --audit-level=lowreports 0 vulnerabilities.Dependency changes
nextreact/react-dom@types/react/@types/react-dompostcss</style>, arbitrary.mapfile read viasourceMappingURL).nanoidpicomatchThe Next.js advisories cleared include SSRF in rewrites and Server Actions, cache poisoning in RSC responses, App Router XSS with CSP nonces, unauthenticated disclosure of internal Server Function endpoints, and several DoS vectors.
tsconfig.jsonchanges (moduleResolution→bundler,jsx→react-jsx, added.next/dev/types) were applied automatically by the Next 16 migration, not by hand.No application source changes were required for the upgrade.
API hardening
Two issues found while reviewing
app/api/chat/route.ts:JSON.parse(body.disease)ran on caller-controlled input with no guard, so any malformed body threw and produced an unhandled 500. Now returns 400.diseasewas interpolated into the model prompt with no length limit, letting an anonymous caller inflate token spend on the OpenAI key. Now capped at 500 characters.Behaviour for valid requests is unchanged, including the existing
ROLE_NOT_SETfallback for an unset physician type.Verification
npm cifrom the committed lockfile →npm audit --audit-level=low: 0 vulnerabilitiesnpm run buildpasses (compile, TypeScript, static generation) from a clean checkout/api/chatstreams correctlynull→ 400 · 600-char input → 400 · 500-char input → 200next start), since 18 → 19 is the riskiest part of this change: page hydrates with zero React or hydration warnings, accordion state toggles, dropdown and controlled textarea work, and form submit issuesPOST /api/chat → 200. The only console error is a 404 for/_vercel/insights/script.js, which is the Vercel Analytics script that only exists on a Vercel deployment — pre-existing and unrelated..envfile has ever been committedNot addressed — needs your decision
/api/chatis unauthenticated and has no rate limiting. This is the largest remaining exposure: anyone can call it in a loop and bill GPT-4 usage to your OpenAI key. The length cap above narrows the per-request cost but does nothing about request volume. Fixing it properly means adding a rate limiter (e.g.@upstash/ratelimitbacked by Upstash Redis, which is what the upstream template used) plus the accompanying infrastructure, so I left it out rather than adding a dependency and an external service on my own.Two lower-priority items also left alone:
next.config.jsstill redirects/githuband/deploytoNutlope/twitterbioand an unrelated Vercel template — leftover from the starter this was forked from. Not a vulnerability (destinations are fixed, not attacker-controlled), but they point users of your domain at an unrelated project.app/layout.tsxhas a malformedmetadataBase:new URL('https://https://med-notes-...'). A correctness bug in OG/Twitter card URLs, not a security issue.One note on the upgrade itself: Next 16 deprecates the Edge runtime that
/api/chatuses (export const runtime = 'edge'). It still works and the build only warns, but it will need migrating tonodejseventually.