Skip to content

Commit e8f2908

Browse files
committed
fix: validate configure gateway ports strictly
1 parent b2fdbc5 commit e8f2908

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/cli/shared/parse-port.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ describe("parsePort (#83899, #83900)", () => {
3737
expect(parsePort(Number.POSITIVE_INFINITY)).toBeNull();
3838
expect(parsePort("abc")).toBeNull();
3939
expect(parsePort("8080ms")).toBeNull();
40+
expect(parsePort("0x10")).toBeNull();
41+
expect(parsePort("1e3")).toBeNull();
4042
});
4143
});

src/commands/configure.gateway.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { formatPortRangeHint } from "../cli/error-format.js";
2+
import { parsePort } from "../cli/shared/parse-port.js";
23
import { resolveGatewayPort } from "../config/config.js";
34
import type { OpenClawConfig } from "../config/types.openclaw.js";
45
import { isValidEnvSecretRefId, type SecretInput } from "../config/types.secrets.js";
@@ -8,7 +9,6 @@ import {
89
TAILSCALE_EXPOSURE_OPTIONS,
910
TAILSCALE_MISSING_BIN_NOTE_LINES,
1011
} from "../gateway/gateway-config-prompts.shared.js";
11-
import { parseStrictPositiveInteger } from "../infra/parse-finite-number.js";
1212
import { findTailscaleBinary } from "../infra/tailscale.js";
1313
import type { RuntimeEnv } from "../runtime.js";
1414
import { resolveDefaultSecretProviderAlias } from "../secrets/ref-contract.js";
@@ -29,8 +29,7 @@ type GatewayAuthChoice = "token" | "password" | "trusted-proxy";
2929
type GatewayTokenInputMode = "plaintext" | "ref";
3030

3131
function validateGatewayPortInput(value: unknown): string | undefined {
32-
const port = Number(typeof value === "string" ? value.trim() : value);
33-
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
32+
if (parsePort(value) === null) {
3433
return formatPortRangeHint();
3534
}
3635
return undefined;
@@ -52,7 +51,7 @@ export async function promptGatewayConfig(
5251
}),
5352
runtime,
5453
);
55-
const port = parseStrictPositiveInteger(portRaw) ?? resolveGatewayPort(cfg);
54+
const port = parsePort(portRaw) ?? resolveGatewayPort(cfg);
5655

5756
let bind = guardCancel(
5857
await select({

src/commands/configure.wizard.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { describeCodexNativeWebSearch } from "../agents/codex-native-web-search.
55
import { formatCliCommand } from "../cli/command-format.js";
66
import { formatPortRangeHint } from "../cli/error-format.js";
77
import { commitConfigWithPendingPluginInstalls } from "../cli/plugins-install-record-commit.js";
8+
import { parsePort } from "../cli/shared/parse-port.js";
89
import { readConfigFileSnapshot, resolveGatewayPort } from "../config/config.js";
910
import { logConfigUpdated } from "../config/logging.js";
1011
import { ConfigMutationConflictError } from "../config/mutate.js";
1112
import type { OpenClawConfig } from "../config/types.openclaw.js";
1213
import { ensureControlUiAssetsBuilt } from "../infra/control-ui-assets.js";
13-
import { parseStrictPositiveInteger } from "../infra/parse-finite-number.js";
1414
import { resolvePluginContributionOwners } from "../plugins/plugin-registry.js";
1515
import type { RuntimeEnv } from "../runtime.js";
1616
import { defaultRuntime } from "../runtime.js";
@@ -65,8 +65,7 @@ const setupPluginConfigModuleLoader = createLazyImportLoader<SetupPluginConfigMo
6565
);
6666

6767
function validateGatewayPortInput(value: unknown): string | undefined {
68-
const port = Number(typeof value === "string" ? value.trim() : value);
69-
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
68+
if (parsePort(value) === null) {
7069
return formatPortRangeHint();
7170
}
7271
return undefined;
@@ -641,7 +640,7 @@ export async function runConfigureWizard(
641640
}),
642641
runtime,
643642
);
644-
gatewayPort = parseStrictPositiveInteger(portInput) ?? gatewayPort;
643+
gatewayPort = parsePort(portInput) ?? gatewayPort;
645644
};
646645

647646
if (selectedSections) {

0 commit comments

Comments
 (0)