security: harden backend API (SSRF, CORS, rate limiting, Helmet, Stripe HTTP redirect)#1
Draft
security: harden backend API (SSRF, CORS, rate limiting, Helmet, Stripe HTTP redirect)#1
Conversation
…t, restrict Stripe HTTP redirect, cap skip parameter Agent-Logs-Url: https://github.com/AnousAlma/needl/sessions/c96eaee9-4a0d-4b4f-8d11-a651b1a956fa Co-authored-by: AnousAlma <112284235+AnousAlma@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Copilot created this pull request from a session on behalf of
AnousAlma
April 7, 2026 05:13
View session
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Full security audit of the codebase. The following issues were found and fixed in the backend (
needl-driver-api):🔴 Critical: SSRF via unrestricted MongoDB URI
File:
backend/src/mongo.tsThe server accepted arbitrary MongoDB URIs from authenticated clients and opened connections to them, allowing abuse to probe internal network resources (private IP ranges, AWS metadata endpoint
169.254.169.254, etc.).Fix: Added
validateMongoUri(), called insidewithMongoClient()before every connection:mongodb://ormongodb+srv://scheme🔴 Critical: CORS allows all origins by default
File:
backend/src/index.tsWhen
CORS_ORIGINSwas not set, the server usedcors({ origin: true })which allows any origin to make cross-origin requests to the API.Fix: Changed fallback to
cors({ origin: false })(deny-all). A startup warning is logged whenCORS_ORIGINSis not configured. Updated.env.exampleto document this required variable.🟠 High: No rate limiting
File:
backend/src/index.tsNo rate limiting existed on any endpoint, enabling DoS and abuse of the MongoDB proxy.
Fix: Added
express-rate-limit— 60 requests per minute per IP on all/v1/routes, with standardRateLimit-*headers.🟠 High: Missing HTTP security headers
File:
backend/src/index.tsNo security headers (CSP, X-Frame-Options, HSTS, etc.) were set.
Fix: Added
helmetmiddleware.🟡 Medium:
http://allowed as Stripe checkout redirect URLFile:
backend/src/stripeDonate.tsWhen
DONATE_REDIRECT_ALLOWLISTwas unset, plainhttp://URLs were accepted as Stripe success/cancel redirect targets, which could be used to redirect users to insecure pages.Fix: Removed
http://from the default-allowed schemes. Onlyhttps://,exp://,exps://, and custom app schemes (e.g.needl://) are now permitted without an explicit allowlist.🟡 Medium: Unbounded
skipparameterFile:
backend/src/mongo.tsThe
skipoffset infindDocumentshad no upper bound, allowing a client to send arbitrarily large skip values and cause performance degradation.Fix: Capped
skipat100_000.Changes
backend/src/index.ts— addhelmet,express-rate-limit, fix CORS defaultbackend/src/mongo.ts— addvalidateMongoUri()(SSRF guard), capskipbackend/src/stripeDonate.ts— removehttp://from default redirect allowlistbackend/.env.example— documentCORS_ORIGINSbackend/package.json/package-lock.json— addhelmet@8.1.0,express-rate-limit@8.3.2Notes (not fixed — design-level or low risk)