fix(seat): hosted route fences P3s: realOr runs once per fixed path, a test hook adds a stand-in fixed path so a linked one is tested, the refuse list adds LUA_INIT, CURL_HOME and SSLKEYLOGFILE, and the plugins README names every refused suffix and hook (#1873, lane triage-p3s)
This commit is contained in:
1 parent
80ce06851d
commit
4b5d027361
3 files changed
+44
-9
No files matched your search
@@ -265,8 +265,10 @@ export returns:
|
||||
`harnessEnv` name only when it is listed here and is not one the host
|
||||
always refuses: `MOSAIC_*`, `NODE_*`, `LD_*`, `DYLD_*`, `PYTHON*`, `BASH_*`,
|
||||
`GIT_*`, `MALLOC_*`, `NPM_CONFIG_*`, `XDG_*`, any name ending in `_DIR`,
|
||||
`_CONF` or `_CONFIG`, PATH, HOME, TMPDIR, ENV, the founder's and the
|
||||
provider's names, and named shell, proxy, libc, OpenSSL and Java hooks. `installRoots` lists the directories
|
||||
`_CONF`, `_CONFIG`, `_ASKPASS`, `_CA_BUNDLE` or `_BASE_URL`, PATH, HOME,
|
||||
TMPDIR, ENV, the founder's and the provider's names, and named shell,
|
||||
proxy, libc, OpenSSL, Java, askpass, CA bundle and base URL hooks, with
|
||||
Lua's start code, curl's config home and a TLS key log. `installRoots` lists the directories
|
||||
where the adapter and the mounts live. A hosted adapter or mount source
|
||||
must resolve inside one of them, and never in or around the data root,
|
||||
the config directory, HOME, `/srv/mosaic` or a path with a `secret`
|
||||
|
||||
@@ -232,25 +232,32 @@ const secretPath = (p) => p.split("/").some((seg) => /secret/i.test(seg));
|
||||
const realOr = (p) => { try { return realpathSync(p); } catch { return p; } };
|
||||
const plainObject = (o) => o !== null && typeof o === "object" && !Array.isArray(o) && [Object.prototype, null].includes(Object.getPrototypeOf(o));
|
||||
|
||||
export function checkHostedRoute({ adapter, harnessMounts, installRoots, protectedPaths, codeRoot = null, codeHolder = null, runDir, node = process.execPath }) {
|
||||
// `alsoFixed` is a test hook: it adds stand-in fixed paths and never removes a shipped one.
|
||||
export function checkHostedRoute({ adapter, harnessMounts, installRoots, protectedPaths, codeRoot = null, codeHolder = null, runDir, node = process.execPath, alsoFixed = [] }) {
|
||||
if (!cleanPath(runDir)) refuseRoute("protected", "the run directory is not a clean absolute path");
|
||||
if (!Array.isArray(protectedPaths)) refuseRoute("protected", "no protected paths were given");
|
||||
if (!Array.isArray(alsoFixed)) refuseRoute("protected", "the added fixed paths are not a list");
|
||||
// Lists are copied once, so a Proxy cannot answer one length to a check and another to the map.
|
||||
protectedPaths = Array.from(protectedPaths);
|
||||
// Each guarded entry: its spellings, and whether a source in the code root is clear of it. The
|
||||
// fixed paths and the run dir never hold the code. Their spellings are looked up once, here, and
|
||||
// serve both the code-root check and their guards, so the two always see the same real path.
|
||||
const fixed = [...ALWAYS_PROTECTED, ...Array.from(alsoFixed), runDir].map((p) => {
|
||||
if (!cleanPath(p)) refuseRoute("protected", "a protected path is not a clean absolute path");
|
||||
return { spellings: [p, realOr(p)], holdsCode: false };
|
||||
});
|
||||
let code = null;
|
||||
if (codeRoot !== null) {
|
||||
if (!cleanPath(codeRoot)) refuseRoute("protected", "the code root is not a clean absolute path");
|
||||
if (!protectedPaths.includes(codeHolder)) refuseRoute("protected", "the code root's holder is not a protected path");
|
||||
code = [codeRoot, realOr(codeRoot)];
|
||||
const fixed = [runDir, ...ALWAYS_PROTECTED].flatMap((g) => [g, realOr(g)]);
|
||||
if (code.some((c) => fixed.some((g) => overlaps(c, g)))) refuseRoute("protected", "the code root is in or around a path that is never set aside");
|
||||
if (code.some((c) => fixed.some((g) => g.spellings.some((s) => overlaps(c, s))))) refuseRoute("protected", "the code root is in or around a path that is never set aside");
|
||||
}
|
||||
// Each guarded entry: its spellings, and whether a source in the code root is clear of it.
|
||||
const guarded = [];
|
||||
for (const [p, mayHoldCode] of [...ALWAYS_PROTECTED.map((g) => [g, false]), ...protectedPaths.map((g) => [g, g === codeHolder]), [runDir, false]]) {
|
||||
const guarded = [...fixed];
|
||||
for (const p of protectedPaths) {
|
||||
if (!cleanPath(p)) refuseRoute("protected", "a protected path is not a clean absolute path");
|
||||
const spellings = [p, realOr(p)];
|
||||
const holdsCode = mayHoldCode && code !== null && spellings.some((g) => code.some((c) => c !== g && within(c, g)));
|
||||
const holdsCode = p === codeHolder && code !== null && spellings.some((g) => code.some((c) => c !== g && within(c, g)));
|
||||
guarded.push({ spellings, holdsCode });
|
||||
}
|
||||
if (!Array.isArray(installRoots)) refuseRoute("roots", "the harness module declares no usable install roots");
|
||||
|
||||
@@ -177,6 +177,32 @@ test("a protected path that holds the code root (HOME over a copy or a worktree)
|
||||
assert.throws(() => checkHostedRoute({ adapter: join(realRun, "code", "inst", "a.sh"), harnessMounts: [], installRoots: [join(realRun, "code", "inst")], protectedPaths: [p.dataRoot, home], codeRoot: join(realRun, "code"), codeHolder: home, runDir: join(p.root, "runlink") }), (e) => e.fence === "protected", "code root in the run dir's real path");
|
||||
});
|
||||
|
||||
test("a fixed path named through a link: a code root in its real path is refused before any guard, and a source there is refused by its guard", async (t) => {
|
||||
const p = await layout(t);
|
||||
// None of the shipped fixed paths is a link on a test host, so the test hook adds a stand-in.
|
||||
const home = join(p.root, "home");
|
||||
const real = join(home, "fixedreal");
|
||||
const inst = join(real, "code", "inst");
|
||||
mkdirSync(inst, { recursive: true });
|
||||
writeFileSync(join(inst, "a.sh"), "x");
|
||||
const link = join(p.root, "fixedlink");
|
||||
symlinkSync(real, link);
|
||||
const base = { adapter: join(inst, "a.sh"), harnessMounts: [], installRoots: [inst], protectedPaths: [p.dataRoot, home], codeHolder: home, runDir: p.runDir, alsoFixed: [link] };
|
||||
const refused = (opts, fence, message, label) => assert.throws(() => checkHostedRoute({ ...base, ...opts }), (e) => e.code === "hosted-binds-refused" && e.fence === fence && message.test(e.message), label);
|
||||
// The code root lies in the stand-in's real path, not under the name the list gives.
|
||||
refused({ codeRoot: join(real, "code") }, "protected", /never set aside/, "code root in a fixed path's real path");
|
||||
// With the code root elsewhere, the source in the stand-in's real path is refused by its guard,
|
||||
// which holds the same real spelling, not by HOME: HOME sets the code root aside.
|
||||
mkdirSync(join(home, "code"));
|
||||
refused({ codeRoot: join(home, "code") }, "adapter", /protected path/, "source in a fixed path's real path");
|
||||
// The same source passes without the stand-in: only the stand-in refused it.
|
||||
assert.equal(checkHostedRoute({ ...base, alsoFixed: [], codeRoot: join(real, "code") }).adapter.src, join(inst, "a.sh"));
|
||||
// The hook adds fixed paths and never removes one, and takes only a list of clean absolute paths.
|
||||
refused({ alsoFixed: [], codeRoot: "/srv/mosaic/x" }, "protected", /never set aside/, "shipped fixed path with an empty hook");
|
||||
refused({ alsoFixed: ["relative"], codeRoot: join(real, "code") }, "protected", /clean absolute/, "relative stand-in");
|
||||
refused({ alsoFixed: "/x", codeRoot: join(real, "code") }, "protected", /clean absolute|list/, "a hook that is not a list");
|
||||
});
|
||||
|
||||
test("a list that answers one length to the check and another later is read once", async (t) => {
|
||||
const p = await layout(t);
|
||||
const items = [];
|
||||
|
||||
Reference in new issue
Block a user