Skip to content

Commit 4a24b6d

Browse files
committed
fix: bound restart handoff ttl
1 parent acb0acd commit 4a24b6d

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/infra/restart-handoff.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,36 @@ describe("gateway restart handoff", () => {
190190
expect(fs.existsSync(handoffPath(env))).toBe(false);
191191
});
192192

193+
it("rejects persisted handoffs with a ttl longer than the supported window", () => {
194+
const env = createHandoffEnv();
195+
196+
fs.writeFileSync(
197+
handoffPath(env),
198+
`${JSON.stringify({
199+
kind: GATEWAY_SUPERVISOR_RESTART_HANDOFF_KIND,
200+
version: 1,
201+
intentId: "too-long",
202+
pid: 111,
203+
createdAt: 1_000,
204+
expiresAt: 61_001,
205+
source: "plugin-change",
206+
restartKind: "full-process",
207+
supervisorMode: "external",
208+
})}\n`,
209+
{ encoding: "utf8", mode: 0o600 },
210+
);
211+
212+
expect(readGatewayRestartHandoffSync(env, 1_001)).toBeNull();
213+
expect(
214+
consumeGatewayRestartHandoffForExitedProcessSync({
215+
env,
216+
exitedPid: 111,
217+
now: 1_001,
218+
}),
219+
).toBeNull();
220+
expect(fs.existsSync(handoffPath(env))).toBe(false);
221+
});
222+
193223
it("does not follow an existing handoff-path symlink when writing", () => {
194224
const env = createHandoffEnv();
195225
const targetPath = path.join(env.OPENCLAW_STATE_DIR ?? "", "attacker-target.txt");

src/infra/restart-handoff.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function parseGatewayRestartHandoff(raw: string): GatewayRestartHandoff | null {
157157
typeof parsed.expiresAt !== "number" ||
158158
!Number.isFinite(parsed.expiresAt) ||
159159
parsed.expiresAt <= parsed.createdAt ||
160+
parsed.expiresAt - parsed.createdAt > GATEWAY_RESTART_HANDOFF_TTL_MS ||
160161
!isSource(parsed.source) ||
161162
!isRestartKind(parsed.restartKind) ||
162163
!isSupervisorMode(parsed.supervisorMode)

0 commit comments

Comments
 (0)