Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixes/tailscale-port-and-windows-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed Tailscale tunnel setup to reject ports outside the valid 1-65535 range and safely install Windows MSI packages from paths containing apostrophes.
2 changes: 1 addition & 1 deletion src/app/api/tunnels/tailscale/routeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
export const tailscaleEnableSchema = z.object({
sudoPassword: z.string().optional(),
hostname: z.string().optional(),
port: z.number().int().positive().optional(),
port: z.number().int().min(1).max(65535).optional(),
});

export const tailscaleLoginSchema = z.object({
Expand Down
12 changes: 6 additions & 6 deletions src/lib/tailscaleTunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,11 @@ async function installTailscaleLinux(password: string, onProgress?: (message: st
});
}

export function buildWindowsTailscaleInstallCommand(msiPath: string): string {
const escapedMsiPath = msiPath.replace(/'/g, "''");
return `Start-Process msiexec -ArgumentList '/i','${escapedMsiPath}','TS_NOLAUNCH=true','/quiet','/norestart' -Verb RunAs -Wait`;
}

async function installTailscaleWindows(onProgress?: (message: string) => void) {
const msiUrl = "https://pkgs.tailscale.com/stable/tailscale-setup-latest-amd64.msi";
const msiPath = path.join(os.tmpdir(), "tailscale-setup.msi");
Expand All @@ -1125,12 +1130,7 @@ async function installTailscaleWindows(onProgress?: (message: string) => void) {
await new Promise<void>((resolve, reject) => {
const child = spawn(
"powershell",
[
"-NoProfile",
"-NonInteractive",
"-Command",
`Start-Process msiexec -ArgumentList '/i','${msiPath}','TS_NOLAUNCH=true','/quiet','/norestart' -Verb RunAs -Wait`,
],
["-NoProfile", "-NonInteractive", "-Command", buildWindowsTailscaleInstallCommand(msiPath)],
{
windowsHide: true,
stdio: ["ignore", "pipe", "pipe"],
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/tailscale-validation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import assert from "node:assert/strict";
import test from "node:test";

import { tailscaleEnableSchema } from "../../src/app/api/tunnels/tailscale/routeUtils.ts";
import { buildWindowsTailscaleInstallCommand } from "../../src/lib/tailscaleTunnel.ts";

test("tailscale enable accepts only valid TCP ports", () => {
assert.equal(tailscaleEnableSchema.safeParse({ port: 1 }).success, true);
assert.equal(tailscaleEnableSchema.safeParse({ port: 65535 }).success, true);
assert.equal(tailscaleEnableSchema.safeParse({ port: 0 }).success, false);
assert.equal(tailscaleEnableSchema.safeParse({ port: 65536 }).success, false);
});

test("Windows installer command escapes apostrophes in MSI paths", () => {
assert.equal(
buildWindowsTailscaleInstallCommand("C:\\Users\\O'Brien\\tailscale-setup.msi"),
"Start-Process msiexec -ArgumentList '/i','C:\\Users\\O''Brien\\tailscale-setup.msi','TS_NOLAUNCH=true','/quiet','/norestart' -Verb RunAs -Wait"
);
});
Loading