mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
fix: harden local targets and monitor network continuously
This commit is contained in:
1 parent
12f440ab8b
commit
2b43952c01
5 files changed
+74
-39
No files matched your search
@@ -109,10 +109,12 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
||||
if (policy.accessMode === "open" && typeof body.target === "string" && body.target.trim()) {
|
||||
target = parseTeamSpeakTarget(body.target);
|
||||
const isDefault = teamSpeakTargetKey(target) === teamSpeakTargetKey(policy.defaultTarget);
|
||||
if (!isDefault) {
|
||||
target = await resolveSafeOpenTarget(target);
|
||||
serverPassword = typeof body.serverPassword === "string" ? body.serverPassword.slice(0, 512) : "";
|
||||
}
|
||||
// Open mode must protect the gateway even when a user submits the
|
||||
// same address configured as the administrator's default target.
|
||||
// The default target only controls which server is prefilled; it is
|
||||
// not a trust boundary and must not bypass SSRF protection.
|
||||
target = await resolveSafeOpenTarget(target);
|
||||
if (!isDefault) serverPassword = typeof body.serverPassword === "string" ? body.serverPassword.slice(0, 512) : "";
|
||||
}
|
||||
} catch {
|
||||
response.status(400).json({ ok: false, code: "TARGET_NOT_ALLOWED" });
|
||||
|
||||
@@ -57,6 +57,8 @@ export class EndpointProtocolCache {
|
||||
|
||||
export const endpointProtocolCache = new EndpointProtocolCache();
|
||||
|
||||
const TEAM_SPEAK_CONNECT_TIMEOUT_MS = 15_000;
|
||||
|
||||
export interface TeamSpeakAdapterOptions {
|
||||
target: TeamSpeakTarget;
|
||||
nickname: string;
|
||||
@@ -109,8 +111,9 @@ export class TeamSpeakAdapter {
|
||||
this.logger.info({ target: formatTeamSpeakTarget(this.target), cachedProtocol }, "Connecting through TeamSpeak adapter");
|
||||
try {
|
||||
await this.client.connect();
|
||||
await this.client.waitConnected();
|
||||
await this.client.waitConnected(AbortSignal.timeout(TEAM_SPEAK_CONNECT_TIMEOUT_MS));
|
||||
} catch (error: unknown) {
|
||||
await this.client.disconnect().catch(() => undefined);
|
||||
throw normalizeTeamSpeakError(error);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user