omowright 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -22
- package/TOOLS.md +6 -6
- package/dist/agent-tabs.d.ts +56 -0
- package/dist/aria-hidden.d.ts +1 -0
- package/dist/aside/cli-binary.d.ts +7 -0
- package/dist/aside/cli-contract.d.ts +9 -0
- package/dist/aside/errors.d.ts +8 -0
- package/dist/aside/line-transport.d.ts +11 -0
- package/dist/aside/mcp-transport.d.ts +11 -0
- package/dist/aside/onboard.d.ts +76 -0
- package/dist/aside/session-types.d.ts +68 -0
- package/dist/aside/session.d.ts +20 -0
- package/{bin/omowright-cloak.mjs → dist/bin/omowright-cloak.js} +28 -31
- package/dist/bridge-schemas.d.ts +326 -0
- package/dist/bridge-transport.d.ts +144 -0
- package/dist/browser-context.d.ts +4024 -0
- package/dist/browser-process.d.ts +10 -0
- package/dist/bsk/browser-signals.d.ts +23 -0
- package/dist/bsk/browsers.d.ts +46 -0
- package/dist/bsk/connect.d.ts +23 -0
- package/dist/bsk/daemon-info.d.ts +16 -0
- package/dist/bsk/external-extension.d.ts +74 -0
- package/dist/bsk/identify-browser.d.ts +48 -0
- package/dist/bsk/install-cli.d.ts +37 -0
- package/dist/bsk/ipc-client.d.ts +45 -0
- package/dist/bsk/onboard.d.ts +96 -0
- package/dist/bsk/reply-fields.d.ts +3 -0
- package/dist/bsk/screenshot.d.ts +24 -0
- package/dist/bsk/session.d.ts +142 -0
- package/dist/bsk/snapshot.d.ts +16 -0
- package/dist/bsk/targets.d.ts +20 -0
- package/dist/captcha-wait.d.ts +17 -0
- package/dist/captcha.d.ts +46 -0
- package/dist/cdp-errors.d.ts +38 -0
- package/dist/cdp-methods.d.ts +10 -0
- package/dist/cdp-protocol.d.ts +459 -0
- package/dist/chrome-profile.d.ts +77 -0
- package/dist/chrome.d.ts +130 -0
- package/dist/cloak-profile.d.ts +43 -0
- package/dist/connection.d.ts +4024 -0
- package/dist/console-events.d.ts +22 -0
- package/dist/cookies.d.ts +42 -0
- package/dist/core.d.ts +10810 -0
- package/dist/cua.d.ts +56 -0
- package/dist/dialog-policy.d.ts +43 -0
- package/dist/ego/bindings.d.ts +68 -0
- package/dist/ego/cdp-client.d.ts +28 -0
- package/dist/ego/client.d.ts +8 -0
- package/dist/ego/errors.d.ts +7 -0
- package/dist/emulate.d.ts +62 -0
- package/dist/engines.d.ts +59 -0
- package/dist/events.d.ts +93 -0
- package/dist/frames-snapshot.d.ts +58 -0
- package/dist/har.d.ts +88 -0
- package/dist/human-handoff.d.ts +30 -0
- package/{src/index.js → dist/index.d.ts} +11 -55
- package/dist/index.js +39262 -0
- package/dist/injected.d.ts +1 -0
- package/dist/instance-lock.d.ts +5 -0
- package/dist/instances.d.ts +45 -0
- package/dist/internal-capability.d.ts +1 -0
- package/dist/launch-endpoint.d.ts +34 -0
- package/dist/layers.d.ts +31 -0
- package/dist/llm.d.ts +1349 -0
- package/dist/lock-backend-win32-xbcm60vz.js +57 -0
- package/dist/lock-backend-win32.d.ts +3 -0
- package/dist/lock-backend.d.ts +6 -0
- package/dist/native-host-win32.d.ts +38 -0
- package/dist/network-events.d.ts +66 -0
- package/dist/network-snoop.d.ts +56 -0
- package/dist/nul-frames.d.ts +4 -0
- package/dist/open-shadow-query.d.ts +1 -0
- package/dist/owner-only.d.ts +15 -0
- package/dist/page-bundle.js +1587 -0
- package/dist/page-events.d.ts +25 -0
- package/dist/page-routes.d.ts +30 -0
- package/dist/page-setup.d.ts +55 -0
- package/dist/pipe.d.ts +71 -0
- package/dist/process-start-time.d.ts +2 -0
- package/dist/read-property.d.ts +2 -0
- package/dist/routes.d.ts +60 -0
- package/dist/running-browser.d.ts +39 -0
- package/dist/scroll-collect.d.ts +36 -0
- package/dist/serial-emitter.d.ts +5 -0
- package/dist/shared-connections.d.ts +11 -0
- package/dist/snapshot-diff.d.ts +57 -0
- package/dist/text-matching.d.ts +21 -0
- package/dist/trace.d.ts +59 -0
- package/dist/url-match.d.ts +7 -0
- package/dist/viewport.d.ts +26 -0
- package/dist/ws.d.ts +62 -0
- package/package.json +47 -26
- package/presets/agent-events/SKILL.md +1 -1
- package/presets/captcha/SKILL.md +1 -3
- package/presets/chrome/SKILL.md +2 -2
- package/presets/cloak-bridge/SKILL.md +11 -11
- package/presets/network/SKILL.md +15 -13
- package/presets/visual-browse/SKILL.md +14 -10
- package/skills/omowright/SKILL.md +77 -47
- package/skills/omowright/references/aside.md +50 -0
- package/skills/omowright/references/browserskill.md +29 -32
- package/skills/omowright/references/ego.md +24 -0
- package/skills/omowright/references/eval-kernel.md +44 -23
- package/skills/omowright/references/frames-layers-human.md +16 -7
- package/skills/omowright/references/quickstart.md +3 -3
- package/skills/omowright/references/stealth.md +7 -7
- package/src/agent-tabs.js +0 -179
- package/src/aria-hidden.js +0 -47
- package/src/bridge-schemas.js +0 -44
- package/src/bridge-transport.js +0 -83
- package/src/browser-context.js +0 -105
- package/src/browser-process.js +0 -127
- package/src/bsk/browser-signals.js +0 -90
- package/src/bsk/browsers.js +0 -114
- package/src/bsk/connect.js +0 -75
- package/src/bsk/daemon-info.js +0 -100
- package/src/bsk/external-extension.js +0 -110
- package/src/bsk/identify-browser.js +0 -88
- package/src/bsk/install-cli.js +0 -81
- package/src/bsk/ipc-client.js +0 -236
- package/src/bsk/onboard.js +0 -140
- package/src/bsk/screenshot.js +0 -49
- package/src/bsk/session.js +0 -131
- package/src/bsk/snapshot.js +0 -56
- package/src/bsk/targets.js +0 -25
- package/src/captcha-wait.js +0 -79
- package/src/captcha.js +0 -142
- package/src/cdp-errors.js +0 -23
- package/src/cdp-methods.js +0 -69
- package/src/chrome-profile.js +0 -176
- package/src/chrome.js +0 -194
- package/src/cloak-profile.js +0 -266
- package/src/connection.js +0 -234
- package/src/console-events.js +0 -12
- package/src/cookies.js +0 -39
- package/src/core.js +0 -1702
- package/src/cua.js +0 -74
- package/src/dialog-policy.js +0 -80
- package/src/emulate.js +0 -127
- package/src/events.js +0 -111
- package/src/frames-snapshot.js +0 -138
- package/src/har.js +0 -103
- package/src/human-handoff.js +0 -124
- package/src/injected.js +0 -3
- package/src/instance-lock.js +0 -74
- package/src/instances.js +0 -490
- package/src/internal-capability.js +0 -1
- package/src/launch-endpoint.js +0 -185
- package/src/layers.js +0 -138
- package/src/llm.js +0 -201
- package/src/lock-backend-win32.js +0 -54
- package/src/lock-backend.js +0 -81
- package/src/native-host-win32.js +0 -201
- package/src/network-events.js +0 -223
- package/src/network-snoop.js +0 -229
- package/src/nul-frames.js +0 -28
- package/src/open-shadow-query.js +0 -101
- package/src/owner-only.js +0 -196
- package/src/page-bundle.js +0 -1478
- package/src/page-events.js +0 -45
- package/src/page-routes.js +0 -94
- package/src/page-setup.js +0 -239
- package/src/pipe.js +0 -418
- package/src/process-start-time.js +0 -64
- package/src/routes.js +0 -256
- package/src/running-browser.js +0 -85
- package/src/scroll-collect.js +0 -73
- package/src/serial-emitter.js +0 -17
- package/src/shared-connections.js +0 -285
- package/src/snapshot-diff.js +0 -75
- package/src/text-matching.js +0 -101
- package/src/trace.js +0 -183
- package/src/url-match.js +0 -148
- package/src/viewport.js +0 -12
package/src/open-shadow-query.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// Self-contained because locator queries serialize this into the frame's page or isolated world.
|
|
2
|
-
// Order matches the CSS locator traversal: the scope's own matches, then each open shadow root below
|
|
3
|
-
// it, depth first in document order, nested roots included. Closed roots stay excluded.
|
|
4
|
-
// A selector with combinators also matches across open shadow boundaries (a host is the parent of its
|
|
5
|
-
// shadow root's top-level children), but matching never climbs above the scope, and an element scope
|
|
6
|
-
// anchors the selector to itself: `:scope` and leading compounds resolve inside it, not against its ancestors.
|
|
7
|
-
export function queryOpenShadowAll(root, selector) {
|
|
8
|
-
const groups = [];
|
|
9
|
-
let parts = [], token = "", depth = 0, quote = "", escaped = false, combinator = " ";
|
|
10
|
-
const flush = () => {
|
|
11
|
-
if (!token.trim()) return;
|
|
12
|
-
parts.push({ selector: token.trim(), combinator });
|
|
13
|
-
token = "";
|
|
14
|
-
combinator = " ";
|
|
15
|
-
};
|
|
16
|
-
for (const char of selector) {
|
|
17
|
-
if (escaped) { token += char; escaped = false; continue; }
|
|
18
|
-
if (char === "\\") { token += char; escaped = true; continue; }
|
|
19
|
-
if (quote) { token += char; if (char === quote) quote = ""; continue; }
|
|
20
|
-
if (char === '"' || char === "'") { quote = char; token += char; continue; }
|
|
21
|
-
if (char === "[" || char === "(") depth++;
|
|
22
|
-
if (char === "]" || char === ")") depth--;
|
|
23
|
-
if (!depth && (char === "," || char === ">" || char === "+" || char === "~" || /\s/.test(char))) {
|
|
24
|
-
flush();
|
|
25
|
-
if (char === ",") { groups.push(parts); parts = []; combinator = " "; }
|
|
26
|
-
else if (!/\s/.test(char)) combinator = char;
|
|
27
|
-
} else token += char;
|
|
28
|
-
}
|
|
29
|
-
flush();
|
|
30
|
-
groups.push(parts);
|
|
31
|
-
// One compound per group matches the same nodes in every tree scope, so each scope stays a native query.
|
|
32
|
-
const simple = groups.every(parts => parts.length === 1 && !/^:scope\b/.test(parts[0].selector));
|
|
33
|
-
let rootSelector = selector;
|
|
34
|
-
if (!simple && root instanceof Element) {
|
|
35
|
-
const scopedSelectors = [];
|
|
36
|
-
for (const parts of groups) {
|
|
37
|
-
const first = parts[0].selector;
|
|
38
|
-
const rest = parts.slice(1).map(part => `${part.combinator} ${part.selector}`).join(" ");
|
|
39
|
-
const scoped = /^:scope\b/.test(first);
|
|
40
|
-
scopedSelectors.push(`${scoped ? "" : ":scope "}${first} ${rest}`);
|
|
41
|
-
if (!scoped && parts.length > 1 && root.matches(first)) scopedSelectors.push(`:scope ${rest}`);
|
|
42
|
-
}
|
|
43
|
-
rootSelector = scopedSelectors.join(", ");
|
|
44
|
-
}
|
|
45
|
-
const rootElements = root.querySelectorAll("*");
|
|
46
|
-
const rootMatches = rootSelector === "*" ? rootElements : root.querySelectorAll(rootSelector);
|
|
47
|
-
// A stack of open roots, popped depth first; the scope's own shadow root comes first.
|
|
48
|
-
const pending = [];
|
|
49
|
-
for (let index = rootElements.length - 1; index >= 0; index--) {
|
|
50
|
-
if (rootElements[index].shadowRoot) pending.push(rootElements[index].shadowRoot);
|
|
51
|
-
}
|
|
52
|
-
if (root instanceof Element && root.shadowRoot) pending.push(root.shadowRoot);
|
|
53
|
-
if (pending.length === 0) return Array.from(rootMatches);
|
|
54
|
-
const results = [];
|
|
55
|
-
// Index loops, never spread: a scope can hold more nodes than the engine's argument limit.
|
|
56
|
-
for (let index = 0; index < rootMatches.length; index++) results.push(rootMatches[index]);
|
|
57
|
-
const parent = node => node.parentElement ?? node.getRootNode().host ?? null;
|
|
58
|
-
const scope = root instanceof Element ? root : root.documentElement;
|
|
59
|
-
const matches = (node, parts, index) => {
|
|
60
|
-
if (node === root && index > 0) return false;
|
|
61
|
-
const part = parts[index];
|
|
62
|
-
const scoped = /^:scope\b/.test(part.selector);
|
|
63
|
-
const compound = scoped ? part.selector.replace(/^:scope\b/, "*") : part.selector;
|
|
64
|
-
if (scoped && node !== scope) return false;
|
|
65
|
-
if (!node.matches(compound)) return false;
|
|
66
|
-
if (index === 0) return true;
|
|
67
|
-
if (part.combinator === ">") {
|
|
68
|
-
const ancestor = parent(node);
|
|
69
|
-
return !!ancestor && matches(ancestor, parts, index - 1);
|
|
70
|
-
}
|
|
71
|
-
if (part.combinator === "+") return !!node.previousElementSibling && matches(node.previousElementSibling, parts, index - 1);
|
|
72
|
-
if (part.combinator === "~") {
|
|
73
|
-
for (let sibling = node.previousElementSibling; sibling; sibling = sibling.previousElementSibling) {
|
|
74
|
-
if (matches(sibling, parts, index - 1)) return true;
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
for (let ancestor = parent(node); ancestor; ancestor = parent(ancestor)) {
|
|
79
|
-
if (matches(ancestor, parts, index - 1)) return true;
|
|
80
|
-
if (ancestor === root) break;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
};
|
|
84
|
-
while (pending.length) {
|
|
85
|
-
const shadow = pending.pop();
|
|
86
|
-
const elements = shadow.querySelectorAll("*");
|
|
87
|
-
for (let index = elements.length - 1; index >= 0; index--) {
|
|
88
|
-
if (elements[index].shadowRoot) pending.push(elements[index].shadowRoot);
|
|
89
|
-
}
|
|
90
|
-
if (simple) {
|
|
91
|
-
const found = selector === "*" ? elements : shadow.querySelectorAll(selector);
|
|
92
|
-
for (let index = 0; index < found.length; index++) results.push(found[index]);
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
for (let index = 0; index < elements.length; index++) {
|
|
96
|
-
const node = elements[index];
|
|
97
|
-
if (groups.some(parts => matches(node, parts, parts.length - 1))) results.push(node);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return results;
|
|
101
|
-
}
|
package/src/owner-only.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
// Owner-only access for the registry, lock and CloakBrowser profile state.
|
|
2
|
-
// POSIX expresses it with mode bits. On Windows chmod only toggles the
|
|
3
|
-
// read-only attribute, so the same property is a protected DACL that grants the
|
|
4
|
-
// current user alone: inherited entries (the parent's grants to other users or
|
|
5
|
-
// groups) are dropped, and files created inside a directory inherit its grant.
|
|
6
|
-
// A directory keeps its explicit entries for Windows' root equivalents (SYSTEM,
|
|
7
|
-
// Administrators, TrustedInstaller) and for OWNER RIGHTS and CREATOR OWNER; an
|
|
8
|
-
// explicit grant to anyone else is removed.
|
|
9
|
-
// The Windows tools are spawned by absolute path: a bare name is resolved from
|
|
10
|
-
// the process cwd before PATH, and a cwd another user can write would let them
|
|
11
|
-
// substitute the tool. Any failure throws, so a caller never goes on with the
|
|
12
|
-
// inherited ACL in place. A volume without ACLs (FAT32, exFAT, some network
|
|
13
|
-
// shares) cannot hold the grant, so icacls fails there and so does the caller.
|
|
14
|
-
import { execFile } from "node:child_process";
|
|
15
|
-
import { chmod, mkdtemp, readFile, rm, stat } from "node:fs/promises";
|
|
16
|
-
import { tmpdir } from "node:os";
|
|
17
|
-
import path from "node:path";
|
|
18
|
-
import { promisify } from "node:util";
|
|
19
|
-
|
|
20
|
-
const execFileAsync = promisify(execFile);
|
|
21
|
-
const WINDOWS_COMMAND_TIMEOUT_MS = 15_000;
|
|
22
|
-
// Directories this process restricted or found restricted, by volume and file
|
|
23
|
-
// id rather than by name: a directory that later takes a restricted one's name
|
|
24
|
-
// never got the grant, and on a case-sensitive NTFS directory two names that
|
|
25
|
-
// differ only in case are two directories.
|
|
26
|
-
const ownerOnlyDirectories = new Set();
|
|
27
|
-
// SDDL trustees that may hold allow entries on an owner-only directory besides
|
|
28
|
-
// the user: SYSTEM, Administrators and TrustedInstaller (the trusted set of
|
|
29
|
-
// src/native-host-win32.js), OWNER RIGHTS (the owner, the user) and CREATOR
|
|
30
|
-
// OWNER (whoever creates a child, on that child). SDDL writes well-known SIDs
|
|
31
|
-
// as aliases; their numeric forms are listed too.
|
|
32
|
-
const TRUSTED_TRUSTEES = new Set([
|
|
33
|
-
"SY", "S-1-5-18",
|
|
34
|
-
"BA", "S-1-5-32-544",
|
|
35
|
-
"S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",
|
|
36
|
-
"OW", "S-1-3-4",
|
|
37
|
-
"CO", "S-1-3-0",
|
|
38
|
-
]);
|
|
39
|
-
const DENY_ACE_TYPES = new Set(["D", "OD", "XD"]);
|
|
40
|
-
let currentUserSid;
|
|
41
|
-
|
|
42
|
-
export function windowsSystemTool(name, env = process.env) {
|
|
43
|
-
return path.win32.join(env.SystemRoot || env.windir || "C:\\Windows", "System32", name);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function readCurrentUserSid(run) {
|
|
47
|
-
const { stdout } = await run(windowsSystemTool("whoami.exe"), ["/user", "/fo", "csv", "/nh"], {
|
|
48
|
-
timeout: WINDOWS_COMMAND_TIMEOUT_MS,
|
|
49
|
-
windowsHide: true,
|
|
50
|
-
});
|
|
51
|
-
const sid = /"(S-1-[\d-]+)"\s*$/.exec(String(stdout).trim())?.[1];
|
|
52
|
-
if (!sid) throw new Error(`cannot read the current user's SID from whoami: ${String(stdout).trim()}`);
|
|
53
|
-
return sid;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function cachedCurrentUserSid() {
|
|
57
|
-
currentUserSid ??= readCurrentUserSid(execFileAsync).catch((error) => {
|
|
58
|
-
currentUserSid = undefined;
|
|
59
|
-
throw error;
|
|
60
|
-
});
|
|
61
|
-
return currentUserSid;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// The directory's DACL as SDDL. `icacls /save` without /T reads this one
|
|
65
|
-
// object only and writes it, as UTF-16, to a file.
|
|
66
|
-
async function readDirectoryDacl(dir, run) {
|
|
67
|
-
const scratch = await mkdtemp(path.join(tmpdir(), "omowright-acl-"));
|
|
68
|
-
try {
|
|
69
|
-
const saved = path.join(scratch, "acl");
|
|
70
|
-
await run(windowsSystemTool("icacls.exe"), [dir, "/save", saved, "/Q"], {
|
|
71
|
-
timeout: WINDOWS_COMMAND_TIMEOUT_MS,
|
|
72
|
-
windowsHide: true,
|
|
73
|
-
});
|
|
74
|
-
const bytes = await readFile(saved);
|
|
75
|
-
const text = bytes.length > 1 && bytes[1] === 0 ? bytes.toString("utf16le") : bytes.toString("utf8");
|
|
76
|
-
return /D:[^\r\n]*/.exec(text)?.[0] ?? "";
|
|
77
|
-
} finally {
|
|
78
|
-
await rm(scratch, { recursive: true, force: true });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// The flags and ACE fields of an SDDL DACL (`D:` flags, then parenthesized
|
|
83
|
-
// ACEs, up to the SACL `S:` that may follow), or null when it does not parse,
|
|
84
|
-
// as for `D:NO_ACCESS_CONTROL`. A conditional ACE nests parentheses and may
|
|
85
|
-
// quote strings, so ACEs are split at depth zero, skipping quoted text.
|
|
86
|
-
function parseDacl(dacl) {
|
|
87
|
-
const head = /^D:([A-Z]*)/.exec(dacl);
|
|
88
|
-
if (!head) return null;
|
|
89
|
-
const aces = [];
|
|
90
|
-
let depth = 0;
|
|
91
|
-
let start = 0;
|
|
92
|
-
let i = head[0].length;
|
|
93
|
-
for (; i < dacl.length; i++) {
|
|
94
|
-
const c = dacl[i];
|
|
95
|
-
if (c === '"' && depth > 0) {
|
|
96
|
-
i = dacl.indexOf('"', i + 1);
|
|
97
|
-
if (i === -1) return null;
|
|
98
|
-
} else if (c === "(") {
|
|
99
|
-
if (depth++ === 0) start = i + 1;
|
|
100
|
-
} else if (c === ")") {
|
|
101
|
-
if (depth === 0) return null;
|
|
102
|
-
if (--depth === 0) aces.push(dacl.slice(start, i).split(";"));
|
|
103
|
-
} else if (depth === 0) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (depth !== 0 || (i < dacl.length && !dacl.startsWith("S:", i))) return null;
|
|
108
|
-
return { flags: head[1], aces };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Reads a directory DACL against the grant below. `ownerOnly`: already what
|
|
112
|
-
// the grant leaves, protected, with the user's one entry being the inheritable
|
|
113
|
-
// full-control allow and no allow entry for a trustee outside the trusted set.
|
|
114
|
-
// `foreign`: the trustees outside it with explicit allow entries, which the
|
|
115
|
-
// grant removes (it drops inherited entries itself). Deny entries grant nothing
|
|
116
|
-
// and stay. `parsed` is false for a DACL that could not be read, whose entries
|
|
117
|
-
// are unknown. SDDL names the built-in Administrator and Guest accounts LA and LG.
|
|
118
|
-
function inspectDirectoryDacl(text, sid) {
|
|
119
|
-
const dacl = parseDacl(text);
|
|
120
|
-
if (!dacl) return { parsed: false, ownerOnly: false, foreign: [] };
|
|
121
|
-
const isUser = (trustee) =>
|
|
122
|
-
trustee === sid || (trustee === "LA" && sid.endsWith("-500")) || (trustee === "LG" && sid.endsWith("-501"));
|
|
123
|
-
const own = dacl.aces.filter((fields) => isUser(fields[5]));
|
|
124
|
-
const others = dacl.aces.filter(([type, , , , , trustee]) => !isUser(trustee) && !TRUSTED_TRUSTEES.has(trustee) && !DENY_ACE_TYPES.has(type));
|
|
125
|
-
return {
|
|
126
|
-
parsed: true,
|
|
127
|
-
ownerOnly: dacl.flags.includes("P") && others.length === 0 &&
|
|
128
|
-
own.length === 1 && own[0][0] === "A" && own[0][1] === "OICI" && own[0][2] === "FA",
|
|
129
|
-
foreign: [...new Set(others.filter(([, flags]) => !flags.includes("ID")).map(([, , , , , trustee]) => trustee))],
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// The memo key: volume, file id and creation time. The 64-bit id Node reports
|
|
134
|
-
// can name a later directory too (ReFS ids are 128-bit, and a file system may
|
|
135
|
-
// reuse a deleted directory's id); the creation time tells them apart. A file
|
|
136
|
-
// system that reports no file id gives none, and its directories are not
|
|
137
|
-
// remembered.
|
|
138
|
-
async function directoryIdentity(dir) {
|
|
139
|
-
const { dev, ino, birthtimeNs } = await stat(dir, { bigint: true });
|
|
140
|
-
return ino === 0n ? null : `${dev}:${ino}:${birthtimeNs}`;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// The memo only spares later tool runs, so a directory whose identity cannot
|
|
144
|
-
// be read is not remembered and files created in it get their own grant.
|
|
145
|
-
async function rememberOwnerOnlyDirectory(dir) {
|
|
146
|
-
const identity = await directoryIdentity(dir).catch(() => null);
|
|
147
|
-
if (identity) ownerOnlyDirectories.add(identity);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// `platform` and `run` let the security contract above (absolute tool paths,
|
|
151
|
-
// fail closed) be tested off Windows; production callers pass neither.
|
|
152
|
-
export async function restrictToOwner(target, kind, { platform = process.platform, run } = {}) {
|
|
153
|
-
if (platform !== "win32") {
|
|
154
|
-
await chmod(target, kind === "directory" ? 0o700 : 0o600);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const command = run ?? execFileAsync;
|
|
158
|
-
const sid = run ? await readCurrentUserSid(run) : await cachedCurrentUserSid();
|
|
159
|
-
// Re-granting an inheritable entry makes Windows rewrite the inherited
|
|
160
|
-
// entries of everything below the directory, thousands of files in a used
|
|
161
|
-
// browser profile, so a directory that already holds the grant is left as is.
|
|
162
|
-
const dacl = kind === "directory" ? inspectDirectoryDacl(await readDirectoryDacl(target, command), sid) : null;
|
|
163
|
-
if (dacl?.ownerOnly) {
|
|
164
|
-
await rememberOwnerOnlyDirectory(target);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const grant = kind === "directory" ? `*${sid}:(OI)(CI)F` : `*${sid}:F`;
|
|
168
|
-
await command(windowsSystemTool("icacls.exe"), [target, "/inheritance:r", "/grant:r", grant, "/Q"], {
|
|
169
|
-
timeout: WINDOWS_COMMAND_TIMEOUT_MS,
|
|
170
|
-
windowsHide: true,
|
|
171
|
-
});
|
|
172
|
-
if (!dacl) return;
|
|
173
|
-
// The grant keeps explicit entries; another trustee's is removed by SID (an
|
|
174
|
-
// SDDL alias such as WD is a SID string icacls accepts after `*`).
|
|
175
|
-
if (dacl.foreign.length > 0) {
|
|
176
|
-
await command(windowsSystemTool("icacls.exe"), [target, "/remove:g", ...dacl.foreign.map((trustee) => `*${trustee}`), "/Q"], {
|
|
177
|
-
timeout: WINDOWS_COMMAND_TIMEOUT_MS,
|
|
178
|
-
windowsHide: true,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
// Entries of a DACL that could not be read may still grant someone else.
|
|
182
|
-
if (dacl.parsed) await rememberOwnerOnlyDirectory(target);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// For a file the caller has just created. On Windows a file created inside a
|
|
186
|
-
// directory restrictToOwner handled in this process inherits that directory's
|
|
187
|
-
// owner-only grant at creation, so no tool runs for it.
|
|
188
|
-
export async function restrictNewFileToOwner(target, options = {}) {
|
|
189
|
-
const platform = options.platform ?? process.platform;
|
|
190
|
-
if (platform === "win32") {
|
|
191
|
-
// A parent that cannot be identified is not trusted: the file gets its own grant.
|
|
192
|
-
const parent = await directoryIdentity(path.dirname(path.resolve(target))).catch(() => null);
|
|
193
|
-
if (parent && ownerOnlyDirectories.has(parent)) return;
|
|
194
|
-
}
|
|
195
|
-
await restrictToOwner(target, "file", options);
|
|
196
|
-
}
|