Optional application-layer security beyond the login (attack screening, automatic bans, per-route policies)

オープン
#8,060 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
10/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
express, node.js, typescript
領域
backend, security

調査の方向性

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-For honored only from loopback by default or from --guard-trusted-proxy addresses (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 ssrf detection category is left out. Browsers send the page address as Referer and 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 (securityHeaders is 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/:port and /absproxy/:port, which expose ports of the development machine, and on /update, plus a strict budget with bans on /login on 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, zod and ipaddr.js (package-lock.json +100/-1, regenerated with npm 11). It's loaded with a dynamic import only when --guard is set. guardagent is 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 copies node_modules and the existing npm ci/npm prune --production flow 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: --help text, 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分
マージ済み PR(30日)
51

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

coder/code-server のほかの issue

coder/code-server の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。