fix(security): configure Express trust proxy and add Content-Security-Policy headers
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start with apps/api/src/main.ts and apps/web/next.config.ts, then check the deployment proxy setup and the web app’s external script, analytics, and embed origins. Configure proxy trust and API Helmet CSP, and add a report-only web CSP that covers the required origins. Done means client IP handling works for deployed and local setups, API responses have the stated restrictive CSP, and browser reports can be reviewed before web enforcement.
Written by the indexing model from the issue text.
Description
Problem Description
- Missing
trust proxyinapps/api/src/main.ts:
NestFactory.create(AppModule, { rawBody: true })does not configure Expresstrust proxy. Behind a reverse proxy or load balancer (Cloudflare, Nginx, etc.),req.ipresolves to the proxy's IP rather than the real client IP, causing users across workspaces to share a single rate-limit bucket or breaking IP-based throttling. - Missing Content-Security-Policy (CSP):
apps/api/src/main.tsexplicitly disables Helmet's CSP (contentSecurityPolicy: false).apps/web/next.config.ts(headers()for/:path*) setsX-Frame-Options,X-Content-Type-Options,Referrer-Policy, andPermissions-Policy, but sets noContent-Security-Policyheader.
Expected Behavior
apps/api/src/main.tsconfigures Expresstrust proxyvia an environment variable (e.g.,TRUST_PROXY, defaulting to1in production andfalselocally, or2when behind Cloudflare + Nginx) soreq.ipreflects the real client IP without breaking local/direct setups.apps/api/src/main.tsenables a restrictive Helmet CSP appropriate for API responses (defaultSrc: ["'none'"],frameAncestors: ["'none'"]).apps/web/next.config.tsrolls out aContent-Security-Policy-Report-Onlyheader first so existing scripts, pixels, and embeds are never accidentally blocked for users, and promotes it toContent-Security-Policyonce verified.
Where to Look
apps/api/src/main.tsapps/web/next.config.ts
Solution / Implementation Guide
- API
trust proxy& Helmet CSP (apps/api/src/main.ts):- Configure Express
trust proxyfromprocess.env.TRUST_PROXY(e.g.app.getHttpAdapter().getInstance().set('trust proxy', ...)), matching the deployment hop count (1behind a single proxy,2behind CDN + proxy,falsewhen no proxy is used). - Enable a strict
contentSecurityPolicyinhelmet(...)instead offalse.
- Configure Express
- Next.js CSP (
apps/web/next.config.ts):- Add a
Content-Security-Policy-Report-Onlyheader undersource: "/:path*"listing the app's required origins (API URL, analytics/pixel domains, YouTube/Spotify/Instagram embed & CDN hosts,frame-ancestors 'none'). - Monitor browser violation reports in staging/production before switching the header to enforcing
Content-Security-Policy.
- Add a
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day