@xkwdstore/agent 2.1.3 → 2.1.4
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 +4 -4
- package/package.json +1 -1
- package/scripts/install-machine-agent.ps1 +1 -1
- package/src/cli.js +1 -1
- package/src/profilePath.js +86 -14
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Terminal-only, cryptographically authenticated CLI for XKWDStore browser automat
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
> **@xkwdstore/agent 2.1.
|
|
7
|
+
> **@xkwdstore/agent 2.1.4 is the last version published on npm.**
|
|
8
8
|
>
|
|
9
|
-
> The current source version is **2.1.
|
|
9
|
+
> The current source version is **2.1.4** (machine-wide hardening). It is
|
|
10
10
|
> NOT claimed to be published unless the release workflow has published it — see
|
|
11
11
|
> `reports/` for the authoritative publication state.
|
|
12
12
|
|
|
@@ -29,7 +29,7 @@ curl -L -o "%TEMP%\xkwdstore-install.ps1" https://raw.githubusercontent.com/Essa
|
|
|
29
29
|
The generated launcher runs the pinned command:
|
|
30
30
|
|
|
31
31
|
```powershell
|
|
32
|
-
npx --yes @xkwdstore/agent@2.1.
|
|
32
|
+
npx --yes @xkwdstore/agent@2.1.4 start
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
Automated installer tests use `-NoLaunch` or a mocked `npx` command so the
|
|
@@ -203,7 +203,7 @@ The agent does NOT update itself. To use a newer version, change the version
|
|
|
203
203
|
number in the command. The pinned command for this release is:
|
|
204
204
|
|
|
205
205
|
```powershell
|
|
206
|
-
npx --yes @xkwdstore/agent@2.1.
|
|
206
|
+
npx --yes @xkwdstore/agent@2.1.4 start
|
|
207
207
|
```
|
|
208
208
|
|
|
209
209
|
> 2.1.0 is the current local agent version (machine-wide hardening).
|
package/package.json
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
# -NoLaunch (test) validate + write files, never start a process
|
|
36
36
|
|
|
37
37
|
param(
|
|
38
|
-
[string]$AgentVersion = '2.1.
|
|
38
|
+
[string]$AgentVersion = '2.1.4',
|
|
39
39
|
[string]$Server = 'https://x.kwdstore.com',
|
|
40
40
|
[string]$ServiceAccount = 'LocalSystem',
|
|
41
41
|
[string]$AgentRoot,
|
package/src/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ const crypto = require('crypto');
|
|
|
24
24
|
const os = require('os');
|
|
25
25
|
const path = require('path');
|
|
26
26
|
|
|
27
|
-
const CLI_VERSION = '2.1.
|
|
27
|
+
const CLI_VERSION = '2.1.4';
|
|
28
28
|
const PROTOCOL_VERSION = 2;
|
|
29
29
|
|
|
30
30
|
// ── Command parsing ──────────────────────────────────────────────────────────
|
package/src/profilePath.js
CHANGED
|
@@ -207,9 +207,9 @@ function _fsyncPath(p, kind) {
|
|
|
207
207
|
*
|
|
208
208
|
* On POSIX, chmod the path to `mode` (best-effort in dev, fail-closed in prod).
|
|
209
209
|
*/
|
|
210
|
-
function _applyPerms(target, mode) {
|
|
210
|
+
function _applyPerms(target, mode, opts = {}) {
|
|
211
211
|
if (IS_WIN) {
|
|
212
|
-
_applyWindowsAcl(target);
|
|
212
|
+
_applyWindowsAcl(target, opts);
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
215
|
try {
|
|
@@ -225,19 +225,72 @@ function _applyPerms(target, mode) {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Windows SID of the user logged in on the ACTIVE CONSOLE session — the user
|
|
230
|
+
* whose session the browser worker (and therefore Chromium) runs in.
|
|
231
|
+
*
|
|
232
|
+
* Chromium is launched by the per-session worker, which the Session-0 broker
|
|
233
|
+
* starts with CreateProcessAsUser(WTSQueryUserToken(activeSession)). Chromium
|
|
234
|
+
* therefore writes its profile — and its ProcessSingleton lock — as THAT user,
|
|
235
|
+
* not as the broker (SYSTEM) that creates the directory. A profile DACL that
|
|
236
|
+
* grants only the broker's own SID + Administrators + SYSTEM leaves Chromium
|
|
237
|
+
* unable to create the lock, and every launch fails with
|
|
238
|
+
* "Failed to create a ProcessSingleton for your profile directory".
|
|
239
|
+
*
|
|
240
|
+
* Returns null when there is no active console session (headless CI / no logged
|
|
241
|
+
* in user) or the SID cannot be resolved; callers then add no extra ACE.
|
|
242
|
+
*/
|
|
243
|
+
function _activeConsoleUserSid() {
|
|
244
|
+
if (!IS_WIN) return null;
|
|
245
|
+
const script = [
|
|
246
|
+
"$ErrorActionPreference='Stop'",
|
|
247
|
+
"$u = (Get-CimInstance Win32_ComputerSystem).UserName",
|
|
248
|
+
"if (-not $u) { '' } else {",
|
|
249
|
+
" (New-Object System.Security.Principal.NTAccount($u)).Translate([System.Security.Principal.SecurityIdentifier]).Value",
|
|
250
|
+
"}",
|
|
251
|
+
].join('; ');
|
|
252
|
+
try {
|
|
253
|
+
const r = spawnSync('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], {
|
|
254
|
+
windowsHide: true, encoding: 'utf8', timeout: 10000,
|
|
255
|
+
});
|
|
256
|
+
const sid = (r.stdout || '').trim();
|
|
257
|
+
return /^S-\d-[\d-]+$/.test(sid) ? sid : null;
|
|
258
|
+
} catch { return null; }
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function _applyWindowsAcl(target, opts = {}) {
|
|
229
262
|
const { enforce } = _windowsAclPolicy();
|
|
230
263
|
if (!enforce) return;
|
|
231
264
|
|
|
265
|
+
// Extra SIDs that must ALSO be granted — notably the interactive session user
|
|
266
|
+
// who runs Chromium. Only well-formed SIDs are accepted.
|
|
267
|
+
const extraSids = (Array.isArray(opts.extraSids) ? opts.extraSids : [])
|
|
268
|
+
.filter((s) => typeof s === 'string' && /^S-\d-[\d-]+$/.test(s));
|
|
269
|
+
|
|
232
270
|
// Resolve the current user's SID structurally (not by localized username).
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
271
|
+
// `opts.ownerSid` is a TEST-ONLY injection so a regression test can prove what
|
|
272
|
+
// happens when the ACL is applied by a DIFFERENT principal (the Session-0
|
|
273
|
+
// broker running as SYSTEM) than the user who later runs Chromium.
|
|
274
|
+
let ownerSid = typeof opts.ownerSid === 'string' && /^S-\d-[\d-]+$/.test(opts.ownerSid)
|
|
275
|
+
? opts.ownerSid
|
|
276
|
+
: null;
|
|
277
|
+
if (!ownerSid) {
|
|
278
|
+
const ownerSidResult = spawnSync('powershell', [
|
|
279
|
+
'-NoProfile', '-NonInteractive', '-Command',
|
|
280
|
+
'[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value',
|
|
281
|
+
], { windowsHide: true, encoding: 'utf8' });
|
|
282
|
+
if (ownerSidResult.status !== 0 || !ownerSidResult.stdout.trim()) {
|
|
283
|
+
throw new ProfileIdentityError('cannot resolve current user SID for ACL verification', 'PROFILE_ACL_NO_USER');
|
|
284
|
+
}
|
|
285
|
+
ownerSid = ownerSidResult.stdout.trim();
|
|
239
286
|
}
|
|
240
|
-
|
|
287
|
+
|
|
288
|
+
// PowerShell array literals: the extra (interactive-session) SIDs, and the
|
|
289
|
+
// full ALLOWLIST used by the verification step below.
|
|
290
|
+
const extraSidArray = extraSids.map((s) => `'${s}'`).join(', ');
|
|
291
|
+
const allowedSidArray = [ownerSid, 'S-1-5-32-544', 'S-1-5-18', ...extraSids]
|
|
292
|
+
.map((s) => `'${s}'`)
|
|
293
|
+
.join(', ');
|
|
241
294
|
|
|
242
295
|
let isDir = false;
|
|
243
296
|
try { isDir = fs.statSync(target).isDirectory(); } catch { /* treat as file */ }
|
|
@@ -289,6 +342,18 @@ function _applyWindowsAcl(target) {
|
|
|
289
342
|
[System.Security.AccessControl.AccessControlType]::Allow)
|
|
290
343
|
$acl.AddAccessRule($systemRule)
|
|
291
344
|
|
|
345
|
+
# Interactive session user(s): Chromium runs AS THIS USER (the worker is
|
|
346
|
+
# started with CreateProcessAsUser(WTSQueryUserToken(activeSession))), so the
|
|
347
|
+
# profile MUST be writable by them or Chrome cannot create its singleton lock.
|
|
348
|
+
foreach ($extraSid in @(${extraSidArray})) {
|
|
349
|
+
if (-not $extraSid) { continue }
|
|
350
|
+
$extraRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
|
351
|
+
(New-Object System.Security.Principal.SecurityIdentifier($extraSid)),
|
|
352
|
+
$colRights, $inhFlags, $propFlags,
|
|
353
|
+
[System.Security.AccessControl.AccessControlType]::Allow)
|
|
354
|
+
$acl.AddAccessRule($extraRule)
|
|
355
|
+
}
|
|
356
|
+
|
|
292
357
|
# Apply the fresh DACL (instance method — works in PS 5.1+ without extra assemblies)
|
|
293
358
|
(Get-Item -LiteralPath $path).SetAccessControl($acl)
|
|
294
359
|
`;
|
|
@@ -320,9 +385,7 @@ function _applyWindowsAcl(target) {
|
|
|
320
385
|
$acl = $item.GetAccessControl()
|
|
321
386
|
$allRules = $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])
|
|
322
387
|
$allowed = @(
|
|
323
|
-
|
|
324
|
-
'S-1-5-32-544',
|
|
325
|
-
'S-1-5-18'
|
|
388
|
+
${allowedSidArray}
|
|
326
389
|
)
|
|
327
390
|
$leaked = @()
|
|
328
391
|
$ownerHasAccess = $false
|
|
@@ -684,7 +747,12 @@ function writeIdentityMarker(dir, tuple, options = {}) {
|
|
|
684
747
|
};
|
|
685
748
|
// 0o700: only the owning user may traverse/read the profile dir.
|
|
686
749
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
687
|
-
|
|
750
|
+
// The browser profile is written by Chromium running AS THE INTERACTIVE
|
|
751
|
+
// SESSION USER (the worker is launched with CreateProcessAsUser on that
|
|
752
|
+
// session's token), so that user must be granted access in addition to the
|
|
753
|
+
// broker's own identity, Administrators and SYSTEM. Without it Chromium
|
|
754
|
+
// cannot create its ProcessSingleton lock and every launch fails.
|
|
755
|
+
_applyPerms(dir, 0o700, { extraSids: [_activeConsoleUserSid()] });
|
|
688
756
|
const tmp = path.join(dir, '.' + IDENTITY_FILE + '.tmp.' + crypto.randomBytes(6).toString('hex'));
|
|
689
757
|
let renamed = false;
|
|
690
758
|
try {
|
|
@@ -1114,4 +1182,8 @@ module.exports = {
|
|
|
1114
1182
|
quarantineDir,
|
|
1115
1183
|
// Phase 10: exported for ACL-policy config unit tests.
|
|
1116
1184
|
windowsAclPolicy: _windowsAclPolicy,
|
|
1185
|
+
// Exported for the interactive-session ACL regression tests: the profile DACL
|
|
1186
|
+
// must grant the user who runs Chromium, not only the process that created it.
|
|
1187
|
+
_applyWindowsAcl,
|
|
1188
|
+
_activeConsoleUserSid,
|
|
1117
1189
|
};
|