Skip to content

Commit cbfa7d4

Browse files
fix(audit): audit filters select wrong intervals when dates are invalid (#103433)
* fix(audit): reject invalid ISO timestamps in filters * test(audit): cover strict date filter semantics Co-authored-by: qingminlong <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 5ed8121 commit cbfa7d4

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Docs: https://docs.openclaw.ai
3636
- **Model pin hot reload and fallback:** keep explicit `/model` selections authoritative across Telegram config reloads and model fallback, capture one live config snapshot per assembled turn, and leave fallback candidates turn-local instead of persisting them over the user's pin. (#103324, #103417) Thanks @obviyus.
3737
- **Swift protocol initializers:** default every schema-optional generated initializer parameter to `nil` so additive protocol fields no longer break SDK construction call sites.
3838
- **OpenCode Go MiMo catalog:** stop exposing the deprecated `mimo-v2-omni` and `mimo-v2-pro` aliases that reject agent requests, and keep release validation on the active MiMo V2.5 routes. (#103311, #103329) Thanks @krissding.
39+
- **Audit time filters:** reject impossible calendar dates for `openclaw audit --after` and `--before` instead of rolling them into unintended intervals, while preserving timezone-less timestamp semantics. (#103433) Thanks @qingminglong.
3940
- **OpenAI-compatible streamed tool calls:** execute complete native tool calls from streams that end with SSE `data: [DONE]` but omit `finish_reason`, while keeping transport EOF and visible-text cases fail-closed. (#98124, #97994) Thanks @SunnyShu0925.
4041
- **xAI provider aliases:** preserve Grok 4.3 and Grok 4.5 thinking profiles, fast-model routing, and encrypted reasoning replay when models use the shipped `x-ai` provider alias instead of clamping valid thinking requests to `minimal`. (#103315)
4142
- **Doctor state isolation:** prevent automated update and Gateway watch repair from importing and archiving default-home exec or plugin-binding approvals when `OPENCLAW_STATE_DIR` points elsewhere, keep implicit CLI preflight notice-only, and reserve cross-state imports for direct operator doctor runs. (#103247, #103317)

‎src/commands/audit.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "vitest";
1+
import { describe, expect, it, vi } from "vitest";
22
import { testApi } from "./audit.js";
33

44
describe("audit command parsing", () => {
@@ -7,9 +7,37 @@ describe("audit command parsing", () => {
77
Date.parse("2026-07-01T00:00:00Z"),
88
);
99
expect(testApi.parseAuditTimestamp("1234", "--after")).toBe(1234);
10+
expect(testApi.parseAuditTimestamp("2024-02-29T00:00:00Z", "--after")).toBe(
11+
Date.parse("2024-02-29T00:00:00Z"),
12+
);
1013
expect(() => testApi.parseAuditTimestamp("not-a-date", "--after")).toThrow("--after");
1114
});
1215

16+
it.each(["--after", "--before"])("rejects impossible calendar dates for %s", (flag) => {
17+
expect(() => testApi.parseAuditTimestamp("2026-02-30T00:00:00Z", flag)).toThrow(flag);
18+
});
19+
20+
it("keeps the original local-time result for timezone-less timestamps", () => {
21+
const input = "2026-07-01T00:00:00";
22+
const localMs = 1_782_878_400_000;
23+
const utcMs = 1_782_864_000_000;
24+
const parse = vi.spyOn(Date, "parse").mockImplementation((value) => {
25+
if (value === input) {
26+
return localMs;
27+
}
28+
if (value === `${input}Z`) {
29+
return utcMs;
30+
}
31+
return Number.NaN;
32+
});
33+
34+
try {
35+
expect(testApi.parseAuditTimestamp(input, "--after")).toBe(localMs);
36+
} finally {
37+
parse.mockRestore();
38+
}
39+
});
40+
1341
it("keeps exports bounded", () => {
1442
expect(testApi.parseAuditLimit(undefined)).toBe(100);
1543
expect(testApi.parseAuditLimit("500")).toBe(500);

‎src/commands/audit.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
AuditListResult,
88
} from "../../packages/gateway-protocol/src/index.js";
99
import { sanitizeTerminalText } from "../../packages/terminal-core/src/safe-text.js";
10+
import { parseAbsoluteTimeMs } from "../cron/parse.js";
1011
import { callGateway } from "../gateway/call.js";
1112
import { parseStrictPositiveInteger } from "../infra/parse-finite-number.js";
1213
import { type RuntimeEnv, writeRuntimeJson } from "../runtime.js";
@@ -39,7 +40,7 @@ function parseAuditTimestamp(value: string | undefined, flag: string): number |
3940
}
4041
}
4142
const parsed = Date.parse(trimmed);
42-
if (!Number.isNaN(parsed)) {
43+
if (!Number.isNaN(parsed) && parseAbsoluteTimeMs(trimmed) !== null) {
4344
return parsed;
4445
}
4546
throw new Error(`${flag} must be an ISO timestamp or Unix milliseconds.`);

0 commit comments

Comments
 (0)