Skip to content

Commit 209fbd1

Browse files
authored
fix(permissions): raise Windows command timeout (#99)
The 10-second bound added in #89 was too tight for the command fallback and fired on contended Windows runners, producing an intermittent permission-unverified failure on unrelated pull requests. That code means "we could not verify", which a consumer may reasonably treat as a security signal, so emitting it because a runner was busy is a false alarm with real consequences. Successful runs of the affected secure-read test measure 1.930s to 5.400s, and one Node 24 leg passed at 9.349s with roughly 651ms of margin. The contended failures on #94 and #95 landed at 10.130s and 10.173s, which is the old bound firing rather than a hang. Thirty seconds is over five times the slowest observed success and about three times the overloaded cutoff, while still terminating a genuinely wedged command rather than letting it hang indefinitely. The deadline stays per process, since each child is the independently wedgable unit and an overall budget would let several slow-but-successful commands compete for one allowance and reproduce the same false result. Fail-closed behavior is unchanged: a real failure or timeout still yields source "unknown", and secure reads still reject it as permission-unverified.
1 parent 3c64caa commit 209fbd1

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- Apply atomic-replacement parent-directory modes through verified no-follow descriptors on POSIX, so a directory-entry swap cannot redirect `chmod` through a symlink to an unrelated directory. Windows keeps its explicit `mkdir(mode)`-only behavior because Node does not enforce POSIX directory modes there.
1212
- Retry a contended file-lock acquisition when Windows denies access to a lock file whose directory entry is still being torn down, including when the native binding performs the exclusive create. Both the exclusive create and the holder's snapshot read reported that transient `EPERM` as a hard failure, so concurrent `acquireFileLock()` calls failed intermittently on Windows even though the very next attempt would have succeeded. Retries stay bounded, so a genuine permission denial still surfaces as `EPERM` rather than a lock timeout; thanks @Yigtwxx for the fix.
1313
- Apply `replaceFileAtomic()` and `replaceFileAtomicSync()` modes through pinned temp-file descriptors before rename, and through pinned copy-fallback descriptors, so a post-rename symlink swap cannot redirect `chmod` to an unrelated file while exact modes remain independent of umask; thanks @yetval for reporting this (#86).
14-
- Bound fallback Windows owner and ACL command execution to 10 seconds per process and report owner-query failures as unverified instead of returning a partial permission classification; thanks @Yigtwxx for the diagnosis.
14+
- Bound fallback Windows owner and ACL command execution to 30 seconds per process, tolerating loaded runners while still terminating wedged commands, and report owner-query failures as unverified instead of returning a partial permission classification; thanks @Yigtwxx for the diagnosis.
1515
- Verify published npm bytes directly when registry integrity metadata conflicts, and cryptographically verify the registry signature plus Sigstore provenance against the package digest and the trusted fs-safe release workflow (#81).
1616
- Report the documented `remove()` failure codes instead of collapsing every failure to `path-alias`. A missing target now throws `not-found`, a non-empty directory throws `not-empty`, and any other filesystem failure throws `not-removable`, while directory identity drift keeps reporting `path-mismatch`; thanks @Yigtwxx for the fix.
1717

‎docs/permissions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The fallback Windows inspector calls `icacls.exe <path>` using its supported
6868
path-only inspection syntax and classifies principals as trusted, world, or
6969
group. Trusted defaults include the current user, SYSTEM, and Administrators.
7070
Built-in PowerShell, `icacls.exe`, and `whoami.exe` invocations have a fixed
71-
10-second per-process deadline. A command failure or timeout returns an
71+
30-second per-process deadline. A command failure or timeout returns an
7272
unverified result (`source: "unknown"`) so callers fail closed. Advanced callers
7373
that inject a custom `exec` implementation own that executor's deadline.
7474
The parser is on the advanced surface so tests and CLIs can process captured

‎src/permission-exec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { promisify } from "node:util";
33

44
const execFileAsync = promisify(execFile);
55

6-
export const DEFAULT_PERMISSION_EXEC_TIMEOUT_MS = 10_000;
6+
export const DEFAULT_PERMISSION_EXEC_TIMEOUT_MS = 30_000;
77

88
export async function executePermissionCommand(
99
command: string,

‎test/permissions-exec.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@ describe("Windows permission command execution", () => {
2525
).rejects.toThrow(`Windows permission inspection timed out after ${timeoutMs}ms`);
2626

2727
expect(performance.now() - startedAt).toBeLessThan(3_000);
28-
expect(DEFAULT_PERMISSION_EXEC_TIMEOUT_MS).toBe(10_000);
28+
expect(DEFAULT_PERMISSION_EXEC_TIMEOUT_MS).toBe(30_000);
29+
});
30+
31+
it("allows a slow command to finish within its deadline", async () => {
32+
const delayMs = 250;
33+
const startedAt = performance.now();
34+
35+
const result = await executePermissionCommand(
36+
process.execPath,
37+
["-e", `setTimeout(() => process.stdout.write("done"), ${delayMs})`],
38+
5_000,
39+
);
40+
41+
expect(result.stdout).toBe("done");
42+
expect(performance.now() - startedAt).toBeGreaterThanOrEqual(delayMs);
2943
});
3044

3145
it("fails closed without starting an ACL query when owner inspection fails", async () => {

0 commit comments

Comments
 (0)