fix(security): configure Express trust proxy and add Content-Security-Policy headers
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- TypeScript
- Star
- 2
- Fork
- 1
- Merge trung bình
- 6 phút
- Pull request đã merge (30 ngày)
- 27
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sumamakhan761/tryinstance
-
backend good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sumamakhan761/tryinstance#65 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
sumamakhan761/tryinstance#64 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
sumamakhan761/tryinstance#63 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sumamakhan761/tryinstance#62 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sumamakhan761/tryinstance#60 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của sumamakhan761/tryinstance
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
makecindy/cindy#15342 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
kwitsch/claude-code-plugin-tooling#219 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
no-repo-link tool-submission
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100