mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 03:02:56 +00:00
fix(cli): reject non-decimal desktop application limits (#9061)
inspect-desktop-application took --max_entries and --max_probe_bytes through Number(), so 0x1 examined one entry and 1e1 ten. Admit decimal text only and keep the shared fields' bounds and defaults.
This commit is contained in:
2 files changed
+59
-8
No files matched your search
@@ -12,6 +12,7 @@ import { absoluteCallerPath } from "../filesystem/callerPath.js";
|
||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import { withCommandCancellation } from "./commandCancellation.js";
|
||||
import { cliDecimalField } from "./options.js";
|
||||
|
||||
/** One-shot complete Evidence can be saved and queried with inspect-analysis-view. */
|
||||
export const registerDesktopApplicationCommands = (
|
||||
@@ -25,15 +26,17 @@ export const registerDesktopApplicationCommands = (
|
||||
path: localPathStringSchema.describe("Local installation directory"),
|
||||
}),
|
||||
options: z.object({
|
||||
max_entries:
|
||||
inspectDesktopApplicationInputSchema.shape.max_entries.describe(
|
||||
"Maximum directory entries to examine; exhaustion leaves partial coverage",
|
||||
),
|
||||
// Decimal tokens only: numeric coercion would read "0x1" as 1 and
|
||||
// "1e1" as 10. The shared fields keep their bounds and defaults.
|
||||
max_entries: cliDecimalField(
|
||||
inspectDesktopApplicationInputSchema.shape.max_entries,
|
||||
).describe(
|
||||
"Maximum directory entries to examine; exhaustion leaves partial coverage",
|
||||
),
|
||||
...analysisEvidenceDeliveryOptions,
|
||||
max_probe_bytes:
|
||||
inspectDesktopApplicationInputSchema.shape.max_probe_bytes.describe(
|
||||
"Maximum total bytes read from selected file ranges",
|
||||
),
|
||||
max_probe_bytes: cliDecimalField(
|
||||
inspectDesktopApplicationInputSchema.shape.max_probe_bytes,
|
||||
).describe("Maximum total bytes read from selected file ranges"),
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
withCommandCancellation((signal) =>
|
||||
|
||||
@@ -193,3 +193,51 @@ cliTest.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Numeric coercion admits each spelling within the field's bounds:
|
||||
// "0x1" as 1 entry, "1e1" as 10 entries and "0x1000" as 4096 bytes.
|
||||
cliTest.for([
|
||||
["max_entries", "0x1"],
|
||||
["max_entries", "1e1"],
|
||||
["max_probe_bytes", "0x1000"],
|
||||
] as const)(
|
||||
"rejects %s %s as a non-decimal desktop limit",
|
||||
async ([field, value], { cli }) => {
|
||||
const root = await createTestTempDirectory("rea-desktop-limit-");
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect-desktop-application",
|
||||
root,
|
||||
`--${field}=${value}`,
|
||||
"--json",
|
||||
],
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.json).toMatchObject({
|
||||
code: "VALIDATION_ERROR",
|
||||
fieldErrors: [expect.objectContaining({ path: field })],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest("keeps a decimal desktop entry limit", async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-desktop-limit-");
|
||||
await writeFile(join(root, "a.txt"), "a");
|
||||
await writeFile(join(root, "b.txt"), "b");
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect-desktop-application",
|
||||
root,
|
||||
"--max_entries=01",
|
||||
"--json",
|
||||
],
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
expect(parseEvidence(result.json).normalized_result).toMatchObject({
|
||||
coverage: {
|
||||
status: "partial",
|
||||
entries_examined: 1,
|
||||
limits: { max_entries: 1 },
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user