fix(sandbox): default non-finite novnc token ttl · openclaw/openclaw@5f301e0
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -52,6 +52,28 @@ describe("noVNC auth helpers", () => {
|
52 | 52 | expect(consumeNoVncObserverToken(token, 1200)).toBeNull(); |
53 | 53 | }); |
54 | 54 | |
| 55 | +it("uses the default ttl when observer token ttlMs is non-finite", () => { |
| 56 | +resetNoVncObserverTokensForTests(); |
| 57 | +const liveToken = issueNoVncObserverToken({ |
| 58 | +noVncPort: 50123, |
| 59 | +password: "abcd1234", // pragma: allowlist secret |
| 60 | +nowMs: 1000, |
| 61 | +ttlMs: Number.NaN, |
| 62 | +}); |
| 63 | +const expiredToken = issueNoVncObserverToken({ |
| 64 | +noVncPort: 50123, |
| 65 | +password: "abcd1234", // pragma: allowlist secret |
| 66 | +nowMs: 1000, |
| 67 | +ttlMs: Number.NaN, |
| 68 | +}); |
| 69 | + |
| 70 | +expect(consumeNoVncObserverToken(liveToken, 60_999)).toEqual({ |
| 71 | +noVncPort: 50123, |
| 72 | +password: "abcd1234", // pragma: allowlist secret |
| 73 | +}); |
| 74 | +expect(consumeNoVncObserverToken(expiredToken, 61_001)).toBeNull(); |
| 75 | +}); |
| 76 | + |
55 | 77 | it("generates 8-char alphanumeric passwords", () => { |
56 | 78 | const password = generateNoVncPassword(); |
57 | 79 | expect(password).toMatch(/^[a-zA-Z0-9]{8}$/); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import crypto from "node:crypto"; |
| 2 | +import { parseFiniteNumber } from "../../shared/number-coercion.js"; |
2 | 3 | import { normalizeOptionalString } from "../../shared/string-coerce.js"; |
3 | 4 | |
4 | 5 | export const NOVNC_PASSWORD_ENV_KEY = "OPENCLAW_BROWSER_NOVNC_PASSWORD"; // pragma: allowlist secret |
@@ -64,10 +65,11 @@ export function issueNoVncObserverToken(params: {
|
64 | 65 | const now = params.nowMs ?? Date.now(); |
65 | 66 | pruneExpiredNoVncObserverTokens(now); |
66 | 67 | const token = crypto.randomBytes(24).toString("hex"); |
| 68 | +const ttlMs = Math.max(1, parseFiniteNumber(params.ttlMs) ?? NOVNC_TOKEN_TTL_MS); |
67 | 69 | NO_VNC_OBSERVER_TOKENS.set(token, { |
68 | 70 | noVncPort: params.noVncPort, |
69 | 71 | password: normalizeOptionalString(params.password), |
70 | | -expiresAt: now + Math.max(1, params.ttlMs ?? NOVNC_TOKEN_TTL_MS), |
| 72 | +expiresAt: now + ttlMs, |
71 | 73 | }); |
72 | 74 | return token; |
73 | 75 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。