Optional application-layer security beyond the login (attack screening, automatic bans, per-route policies)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 10/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- express, node.js, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 79.9k
- 派生
- 6.9k
- 平均合并
- 20 小时 21 分钟
- 30 天内合并 PR
- 51
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
coder/code-server 的其他 Issue
-
Error not true未关闭
难度 3/5 1-2 天 新手友好度 45/100
coder/code-server#8148 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 51/100
coder/code-server#8145 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 15/100
coder/code-server#8142 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: --proxy-domain does not proxy when the host includes a port可能已有人在做 @adityajai119 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
coder/code-server#8128 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: /healthz with a query string triggers a heartbeat可能已有人在做 @adityajai119 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
coder/code-server#8126 · 1 条评论 ·
维护者通常 1 天内回复
查看 coder/code-server 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
vercel-labs/ui#1066 ·
维护者通常 1 天内回复
-
fix(factory-cockpit): display active agent/actor name instead of verbose step name in run card badge未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
ranxianglei/billion-context#7597 ·
维护者通常 1 天内回复
-
documentation target:powerpoint
难度 1/5 1 小时以内 新手友好度 76/100
tomast1337/PdfLapas#602 ·
维护者通常 1 天内回复
-
kubernetes-ingestor: fetchCRDMapping() runs even when crossplane.enabled is false, logging a 403 ERROR every run可能已有人在做 @kc9ddi 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
TeraSky-OSS/backstage-plugins#228 ·