fix(platform): accept absolute paths for any host and stop blaming the ceiling for a missing grant (#552)

Addresses #548 and #545.

#548: processScenarioSchema required a leading "/" for executable,
working_directory and filesystem_roots, so no process scenario could be
expressed on Windows at all. The report suggested node:path's isAbsolute, but
that answers for the host running the check: on Linux `C:\tools` is not
absolute, so a scenario captured on Windows would fail validation when it is
replayed, compared, or asserted in a test on another host. A boundary schema
must not vary with its evaluator, so the check accepts the POSIX form, a
Windows drive path and a UNC share everywhere. The rejection message now names
the constraint instead of leaving the caller to infer it from "invalid request".
The HTTP `path` field inside `checkpoints` is an URL path and is deliberately
left alone.

I checked whether this merely moved the failure downstream: containment is
enforced by isPathWithinRoot, which already uses host-aware path.relative, so
validation really was the only blocker.

#545: when a scope is inside the administrator ceiling but no grant was ever
issued, the denial still pointed at widening the ceiling -- advice that cannot
help, since the ceiling already permits the operation. The `missing` payload is
computed against candidate *grants*, so it describes what a grant must cover,
not a ceiling gap. `PermissionRemediation` gains a `grant` variant saying
exactly that, and PermissionAuthority selects it when the denial is not a
ceiling violation. An explicitly requested remediation is still honoured, and a
genuine ceiling violation still says "configure".
This commit is contained in:
morluto
2026-10-05 18:50:10 +08:00
committed by GitHub
parent 5b383b2ddd
commit e793e124a2
10 changed files with 219 additions and 13 deletions
+11 -3
View File
@@ -282,9 +282,17 @@ export class PermissionAuthority {
const outsideAdministratorCeiling =
denied.reason === "outside_administrator_ceiling";
const requestedRemediation = options.remediation ?? "configure";
const remediation =
outsideAdministratorCeiling && requestedRemediation !== "restart"
? this.outsideCeilingRemediation
// Only a genuine ceiling violation can be fixed by widening configuration.
// When the scope is inside the ceiling but no grant was ever issued, the
// `missing` payload describes what a *grant* must cover, so pointing the
// caller at the ceiling sends them to edit configuration that already
// permits the operation. An explicitly requested remediation is honoured.
const remediation = outsideAdministratorCeiling
? requestedRemediation === "restart"
? requestedRemediation
: this.outsideCeilingRemediation
: requestedRemediation === "configure"
? "grant"
: requestedRemediation;
return err(
new PermissionRequiredError({
@@ -0,0 +1,99 @@
import { describe, expect, it } from "vitest";
import { PermissionAuthority } from "./PermissionAuthority.js";
import type { PermissionRequiredError } from "../domain/errors.js";
import {
createPermissionPolicy,
type PermissionRequest,
type PermissionScope,
} from "../domain/permissionPolicy.js";
// Ceiling paths must exist: the policy canonicalizes them with realpath.
const ceilingScope: PermissionScope = {
capability: "browser_automate",
roots: [],
executables: [process.execPath],
origins: ["http://127.0.0.1:3000"],
environment_names: [],
network: "external",
mount: false,
};
/** A request the administrator ceiling already fully covers. */
const coveredRequest = (
overrides: Partial<PermissionScope> = {},
): PermissionRequest => ({
...ceilingScope,
network: "loopback",
operation_identity: "browser-scenario-1",
...overrides,
});
/** Narrow to the permission-denial error, failing the test on any other error. */
const denied = async (
authority: PermissionAuthority,
request: PermissionRequest,
remediation?: "elicit",
): Promise<PermissionRequiredError> => {
const result = await authority.authorize(
request,
"write",
remediation === undefined ? {} : { remediation },
);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected a denial");
if (result.error._tag !== "PermissionRequiredError")
throw new Error(`expected a permission denial, got ${result.error._tag}`);
return result.error;
};
describe("permission denial remediation", () => {
it("asks for a grant, not a wider ceiling, when the ceiling covers the scope", async () => {
const authority = new PermissionAuthority(
createPermissionPolicy([ceilingScope], []),
);
// The ceiling contains this scope, so widening it cannot help.
expect(await denied(authority, coveredRequest())).toMatchObject({
remediation: "grant",
});
});
it("denies an empty request as needing a grant, not a ceiling violation", async () => {
const authority = new PermissionAuthority(
createPermissionPolicy([ceilingScope], []),
);
expect(
await denied(authority, {
capability: "browser_automate",
roots: [],
executables: [],
origins: [],
environment_names: [],
network: "none",
mount: false,
operation_identity: "browser-scenario-1",
}),
).toMatchObject({ remediation: "grant" });
});
it("still points at configuration for a genuine ceiling violation", async () => {
const authority = new PermissionAuthority(
createPermissionPolicy([ceilingScope], []),
);
expect(
await denied(
authority,
coveredRequest({ origins: ["https://not-configured.example"] }),
),
).toMatchObject({ remediation: "configure" });
});
it("keeps an explicitly requested elicit remediation untouched", async () => {
const authority = new PermissionAuthority(
createPermissionPolicy([ceilingScope], []),
);
expect(await denied(authority, coveredRequest(), "elicit")).toMatchObject({
remediation: "elicit",
});
});
});