Harden the gateway against abuse (review S1-S3, S5-S7, S9)

- /ws: optional ALLOWED_ORIGINS allowlist, connection limits per IP and
  in total, 34 MiB maxPayload (uploads capped at 24 MiB client-side)
- connect: reject malformed host/nickname before spawning a connector;
  args passed as --flag=value, secrets via env instead of argv
- connector: 25 MiB download cap, 512 KiB for auto-fetched icons, friendly
  error for blocked private targets (tsclientlib: ALLOW_PRIVATE_TARGETS)
- feedback: contact e-mail never goes into the public GitHub issue;
  mentions/links in the issue body are neutralized; form says so
- rate limits: TRUST_PROXY-aware client IP, expiring limiter maps
- security headers (nosniff, frame options, CSP on served HTML)
- web: icon downloads requested once per path instead of on every update

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-09-27 18:52:35 +00:00
1 parent 295af1781e
commit 4124071371
13 files changed
+246 -57

No files matched your search

+21 -1
View File
@@ -3573,6 +3573,8 @@ function iconDataUrl(base64: string): string {
// colored-letter badge instead; only real custom uploads (id >= threshold)
// are fetched as actual images.
const CUSTOM_ICON_ID_THRESHOLD = 1000;
// Keep in sync with WS_MAX_PAYLOAD in gateway/src/index.ts (base64 adds ~4/3).
const MAX_UPLOAD_BYTES = 24 * 1024 * 1024;
/** Deterministic color for a group's letter badge - same icon id always
* produces the same hue, so a group looks consistent across the tree
@@ -7988,6 +7990,11 @@ function AppInner() {
// cid 0 always lands in serverIconImages, regardless of who asked) - fetch
// any group icon referenced by a currently visible client that isn't
// cached yet.
const requestedIconPathsRef = useRef(new Set<string>());
useEffect(() => {
if (!connected) requestedIconPathsRef.current.clear();
}, [connected]);
useEffect(() => {
if (!serverGroups) return;
const iconById = new Map(serverGroups.map((g) => [g.id, g.iconId]));
@@ -7998,7 +8005,10 @@ function AppInner() {
);
for (const iconId of wantedIconIds) {
const path = `/icon_${iconId}`;
if (!(path in serverIconImages)) {
// Once per path and connection: without this, every client-list update
// re-requested icons still in flight (or ones that failed for good).
if (!(path in serverIconImages) && !requestedIconPathsRef.current.has(path)) {
requestedIconPathsRef.current.add(path);
socketRef.current?.send(JSON.stringify({ type: "downloadFile", channelId: 0, path }));
}
}
@@ -9103,8 +9113,17 @@ function AppInner() {
);
};
// Uploads travel base64-encoded in a single WebSocket message; anything
// above the gateway's maxPayload would make it drop the whole connection.
const rejectOversizedUpload = (file: File): boolean => {
if (file.size <= MAX_UPLOAD_BYTES) return false;
appendLog({ text: t("fileBrowser.tooLarge", { mb: String(MAX_UPLOAD_BYTES >> 20) }), kind: "error" });
return true;
};
const handleFileBrowserUpload = (file: File) => {
if (!fileBrowserTarget) return;
if (rejectOversizedUpload(file)) return;
const channelId = fileBrowserTarget.channelId;
const targetPath = ftJoinPath(fileBrowserPath, file.name);
const reader = new FileReader();
@@ -9131,6 +9150,7 @@ function AppInner() {
};
const handleServerIconUpload = (iconId: number, file: File) => {
if (rejectOversizedUpload(file)) return;
const reader = new FileReader();
reader.onload = () => {
const result = reader.result as string;
+2 -1
View File
@@ -52,7 +52,7 @@
"feedback.dialog.reportHint": "Meldungen bleiben privat und werden nie als GitHub-Issue veröffentlicht. Gib bei Bedarf den betroffenen Server mit an.",
"feedback.dialog.message": "Nachricht",
"feedback.dialog.messagePlaceholder": "Was ist passiert, oder was schlägst du vor?",
"feedback.dialog.email": "E-Mail (optional, für Rückfragen)",
"feedback.dialog.email": "E-Mail (optional, für Rückfragen – bleibt privat, wird nie veröffentlicht)",
"feedback.dialog.publishAsIssue": "Als öffentliches GitHub-Issue veröffentlichen",
"feedback.dialog.publishAsIssueHint": "Ohne Haken bleibt dein Feedback privat und geht nur an den Betreiber.",
"feedback.dialog.publishAsIssueHintBug": "Fehlermeldungen werden immer als öffentliches GitHub-Issue veröffentlicht.",
@@ -575,6 +575,7 @@
"channelContext.files": "Dateien...",
"fileBrowser.title": "Dateitransfers",
"fileBrowser.up": "Nach oben",
"fileBrowser.tooLarge": "Datei zu groß – höchstens {mb} MiB pro Upload.",
"fileBrowser.refresh": "Aktualisieren",
"fileBrowser.newFolder": "Neuer Ordner",
"fileBrowser.upload": "Hochladen",
+2 -1
View File
@@ -52,7 +52,7 @@
"feedback.dialog.reportHint": "Reports stay private and are never published as a GitHub issue. Feel free to name the affected server.",
"feedback.dialog.message": "Message",
"feedback.dialog.messagePlaceholder": "What happened, or what are you suggesting?",
"feedback.dialog.email": "Email (optional, for follow-up)",
"feedback.dialog.email": "Email (optional, for follow-up – stays private, never published)",
"feedback.dialog.publishAsIssue": "Publish as a public GitHub issue",
"feedback.dialog.publishAsIssueHint": "Leave unchecked to keep your feedback private, visible only to the maintainer.",
"feedback.dialog.publishAsIssueHintBug": "Bug reports are always published as a public GitHub issue.",
@@ -575,6 +575,7 @@
"channelContext.files": "Files...",
"fileBrowser.title": "File Transfers",
"fileBrowser.up": "Up",
"fileBrowser.tooLarge": "File too large – uploads are limited to {mb} MiB.",
"fileBrowser.refresh": "Refresh",
"fileBrowser.newFolder": "New Folder",
"fileBrowser.upload": "Upload",
+2 -1
View File
@@ -52,7 +52,7 @@
"feedback.dialog.reportHint": "گزارش‌ها همیشه خصوصی می‌مانند و هرگز به‌صورت Issue عمومی در گیت‌هاب منتشر نمی‌شوند. در صورت نیاز می‌توانی نام سرور مربوطه را ذکر کنی.",
"feedback.dialog.message": "پیام",
"feedback.dialog.messagePlaceholder": "چه اتفاقی افتاد، یا چه پیشنهادی داری؟",
"feedback.dialog.email": "ایمیل (اختیاری، برای پیگیری)",
"feedback.dialog.email": "ایمیل (اختیاری، برای پیگیری – خصوصی می‌ماند و هرگز منتشر نمی‌شود)",
"feedback.dialog.publishAsIssue": "به‌صورت Issue عمومی در گیت‌هاب منتشر شود",
"feedback.dialog.publishAsIssueHint": "اگر تیک نزنی، بازخوردت خصوصی می‌ماند و فقط برای مدیر پروژه قابل مشاهده است.",
"feedback.dialog.publishAsIssueHintBug": "گزارش اشکال‌ها همیشه به‌صورت Issue عمومی در گیت‌هاب منتشر می‌شوند.",
@@ -574,6 +574,7 @@
"channelContext.files": "فایل‌ها...",
"fileBrowser.title": "انتقال فایل",
"fileBrowser.up": "بالا",
"fileBrowser.tooLarge": "فایل خیلی بزرگ است – حداکثر {mb} مگابایت برای هر آپلود.",
"fileBrowser.refresh": "بارگذاری مجدد",
"fileBrowser.newFolder": "پوشه جدید",
"fileBrowser.upload": "بارگذاری",
+2 -1
View File
@@ -431,6 +431,7 @@
"channelContext.files": "文件...",
"fileBrowser.title": "文件传输",
"fileBrowser.up": "上一级",
"fileBrowser.tooLarge": "文件过大——每次上传最多 {mb} MiB。",
"fileBrowser.refresh": "刷新",
"fileBrowser.newFolder": "新建文件夹",
"fileBrowser.upload": "上传",
@@ -522,7 +523,7 @@
"feedback.dialog.reportHint": "举报内容保持私密,不会作为 GitHub Issue 公开。如有需要可注明相关服务器。",
"feedback.dialog.message": "消息",
"feedback.dialog.messagePlaceholder": "发生了什么,或者你有什么建议?",
"feedback.dialog.email": "邮箱(可选,用于回复)",
"feedback.dialog.email": "邮箱(可选,用于回复——仅私下保存,绝不公开)",
"feedback.dialog.publishAsIssue": "作为公开的 GitHub Issue 发布",
"feedback.dialog.publishAsIssueHint": "不勾选则反馈保持私密,仅维护者可见。",
"feedback.dialog.publishAsIssueHintBug": "错误报告将始终作为公开的 GitHub Issue 发布。",