Optional application-layer security beyond the login (attack screening, automatic bans, per-route policies)
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ó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 10/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- express, node.js, typescript
Hướng nghiên cứu
This is a design proposal, not a task: the issue asks maintainers to decide whether to add an opt-in --guard middleware and a new runtime dependency, @guardcore/express. Read src/node/routes/login.ts for the existing login limiter the proposal leaves unchanged, and the issue's notes on the HTTP router and websocket upgrade hook. Done means a maintainer decision on scope, the dependency and the trusted-proxy design, not a patch.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Disclosure: I maintain the Guard Core libraries used in this proposal.
What is your suggestion?
An opt-in --guard flag that screens every HTTP request and websocket upgrade before it reaches code-server's routes, using the @guardcore/express middleware (MIT, express ^4 || ^5 peer, and code-server already runs Express 5). Without the flag nothing is imported and no middleware is added.
When it's on you get:
- attack-pattern detection on the path, query string and headers (scanner traffic, path traversal, injection probes) with automatic IP bans for clients that keep sending them
- an IP and CIDR allowlist (
--guard-allow-ip, repeatable) - a trusted client IP: the address of the direct connection, with
X-Forwarded-Forhonored only from loopback by default or from--guard-trusted-proxyaddresses (repeatable), so other peers can't spoof it - per-IP rate limiting for all routes (
--guard-rate-limit, requests per minute, default 1200)
How it behaves:
- Request bodies are never scanned, so uploads, the login form and VS Code traffic aren't inspected. Path, query and headers only.
- The
ssrfdetection category is left out. Browsers send the page address asRefererand guard-core 4.4.0 flags localhost and LAN addresses in it, which would break the UI for anyone opening it on localhost or a LAN IP. I'd turn it back on when the engine fix ships. - The guard sits first on the HTTP router, so rejected requests never reach the heartbeat, static files or the login limiter. Websocket upgrades can't go through router middleware (their response isn't a real HTTP response), so the same checks run through an upgrade hook. That's what lets the allowlist, bans and rate limit cover the editor websocket and proxied ports. Allowed upgrades pass through untouched.
- State is in memory per process (no Redis), like the existing login limiter. The regular request path and the upgrade path keep separate counters.
- Security headers are left alone (
securityHeadersis disabled) because VS Code sets its own CSP. - The login limiter is unchanged and still applies on top.
What else the engine offers
I kept the branch to a small, safe subset. The rest is already in @guardcore/express and I can wire whatever you find useful:
- Per-route policies: an IP allowlist only on
/proxy/:portand/absproxy/:port, which expose ports of the development machine, and on/update, plus a strict budget with bans on/loginon top of the existing limiter. - Honeypot traps: a hidden field in the login form that no person can see. A client that fills it is a bot working through the instance, so the request is rejected.
- Behavior rules, for example banning clients that keep hitting 404s (scanners) or repeat suspicious request patterns.
- Country allow and block lists, blocking cloud-provider IP ranges, user-agent filtering.
- Emergency mode, which locks the instance down to an allowlist during an incident, and a passive (log-only) mode to try everything before enforcing it.
Why do you want this feature?
code-server is meant to be exposed to the internet, but today only /login is rate limited, with a process-wide token bucket (2 per minute plus 12 per hour) in src/node/routes/login.ts that isn't per IP. Every other route is unthrottled, there's no IP allowlist, and nothing bans scanners that probe the server. Anyone who can reach the port can hammer the static, proxy and VS Code routes.
It has come up before:
- #1320 "Ratelimit code-server password auth" (closed) asked for the login rate limit that exists today.
- #2647 "Login rate limiter should not count against successful logins" (closed) refined it.
- #7104 "Security Feature Request and Issues" (open) asks for customizable rate limit settings and fail2ban style integration for people who want tighter control.
This doesn't change the login limiter. It adds the missing layer for everything else, and changes nothing for anyone who doesn't opt in.
Are there any workarounds to get this functionality today?
Yes: a reverse proxy (nginx limit_req and allow/deny, Caddy, Traefik) or a network firewall for rate limits and allowlists, and fail2ban reading code-server's logs for login failures. They protect the edge and stay useful, but it's a different layer. They need infrastructure the user may not control (--trusted-origins exists for people who can't configure their proxy), fail2ban only sees the failed logins code-server logs, and none of them inspects requests for attack patterns inside the application. A built-in opt-in option complements them, behind a proxy or without one.
Are you interested in submitting a PR for this?
Yes. A tested branch is ready: https://github.com/rennf93/code-server/tree/feat/guardcore-express-security (I'll open the PR once this is discussed).
- Dependency impact: one new runtime dependency,
@guardcore/express, which brings@guardcore/core,guardagent,zodandipaddr.js(package-lock.json+100/-1, regenerated with npm 11). It's loaded with a dynamic import only when--guardis set.guardagentis the optional telemetry client of these libraries: installed, but never imported unless an agent is explicitly configured, which this change doesn't do, so nothing is sent anywhere. The release build copiesnode_modulesand the existingnpm ci/npm prune --productionflow covers it, no packaging changes. - Tests (
test/unit/node/guard.test.ts, existing integration harness): disabled adds nothing and never loads the package, 429 on a burst, 403 allowlist (HTTP and websocket), spoofed X-Forwarded-For ignored from an untrusted peer and honored from loopback, attack in the query blocked, bodies not scanned, login page and login limiter unchanged, static and VS Code style paths served, websocket upgrade unaffected. - Docs:
--helptext, a FAQ entry and a changelog entry.
Who I am: I'm rennf93. I wrote fastapi-guard, public since August 2024 (first PyPI release, 0.1.0, on 2024-08-26), now at 825 GitHub stars, 65 releases and about 62,000 PyPI downloads last month (pypistats.org). The engines and adapters for other languages and frameworks came later and run the same detection rules, checked in CI against shared conformance fixtures.
- Ngôn ngữ chính
- TypeScript
- Star
- 79.9k
- Fork
- 6.9k
- Merge trung bình
- 20 giờ 21 phút
- Pull request đã merge (30 ngày)
- 51
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- 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 coder/code-server
-
Error not trueĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
coder/code-server#8148 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 51/100
coder/code-server#8145 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
coder/code-server#8142 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: --proxy-domain does not proxy when the host includes a portCó thể đã có người làm @adityajai119 đã nhận 10 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
coder/code-server#8128 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: /healthz with a query string triggers a heartbeatCó thể đã có người làm @adityajai119 đã nhận 10 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
coder/code-server#8126 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của coder/code-server
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vercel-labs/ui#1066 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(factory-cockpit): display active agent/actor name instead of verbose step name in run card badgeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ranxianglei/billion-context#7597 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation target:powerpoint
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 76/100
tomast1337/PdfLapas#602 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
kubernetes-ingestor: fetchCRDMapping() runs even when crossplane.enabled is false, logging a 403 ERROR every runCó thể đã có người làm @kc9ddi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
TeraSky-OSS/backstage-plugins#228 ·