Skip to content
Source
Sign inSign up
pingdotgg/t3code

Harden server bind defaults and WebSocket origin checks #388

Closedbasilk15(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/388/headopened View on GitHub

Showing 6 changed files with 39 additions and 13 deletions (loading 3).

x
0 of 6 viewed, 6 left
11 additions and 0 deletionsapps/server/src/config.tsModified
View file
@@ -12,6 +12,8 @@
​
export type RuntimeMode = "web" | "desktop";
​
+const LOOPBACK_HOSTS = new Set(["127.0.0.1", "::1", "[::1]", "localhost"]);
+​
/**
* ServerConfigShape - Process/runtime configuration required by the server.
*/
@@ -59,6 +61,15 @@
);
​
+export const isWildcardHost = (host: string | undefined): boolean =>
+ host === "0.0.0.0" || host === "::" || host === "[::]";
+​
+export const isLoopbackHost = (host: string | undefined): boolean =>
+ host !== undefined && LOOPBACK_HOSTS.has(host.trim().toLowerCase());
+​
+export const formatHostForUrl = (host: string): string =>
+ host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
+​
export const resolveStaticDir = Effect.fn(function* () {
const { join, resolve } = yield* Path.Path;
const { exists } = yield* FileSystem.FileSystem;
13 additions and 1 deletionapps/server/src/main.test.tsModified
View file