mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
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:
1 parent
295af1781e
commit
4124071371
13 files changed
+246
-57
No files matched your search
+21
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user