Skip to content

Commit 3f77406

Browse files
committed
feat(permissions): expose current process SID
1 parent cfbe661 commit 3f77406

8 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
### Highlights
66

77
- Add policy-driven archive entry filtering and mode handling, bounded single-entry archive reads, root-bounded async walking, synchronous sidecar locks, async secret reads, create-only secret writes, and exclusive file publication.
8-
- Add public streaming `sha256File(path | FileHandle)` hashing with optional async native acceleration, plus policy-free Windows owner/DACL facts with owner SID and per-ACE masks and inheritance flags.
8+
- Add public streaming `sha256File(path | FileHandle)` hashing with optional async native acceleration, plus policy-free Windows owner/DACL facts with owner and current-process-user SIDs and per-ACE masks and inheritance flags.
99
- Add native fd-relative ZIP and TAR extraction/read support with gzip, zstd, and bzip2 streaming; TypeScript evaluates the shared entry policy before Rust creates any output, and zstd/bzip2 report a typed native-required error when no binding is available.
1010
- Bound PAX, GNU long-name/link, and sparse metadata with one `maxMetaEntryBytes` policy shared by node-tar and the native fixed-header metering reader, including typed failures for oversized or malformed metadata.
1111
- Add `Root.walk()` subtree pruning and partial directory-error reporting for bounded best-effort consumers, plus a shared `maxEntryPathComponents` archive limit that rejects implicit-directory depth attacks before either extraction path creates output.

‎docs/permissions.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ for (const ace of facts.aces) {
105105
}
106106
```
107107
108-
On Windows the supported result contains `ownerSid`, `daclPresent`, `isLocal`,
109-
`complete`, `unsupportedAceTypes`, and ordered basic allow/deny `aces`. Each ACE
110-
has `{ sid, mask, aceType, flags }`; `flags` retains the raw byte and decoded
108+
On Windows the supported result contains `ownerSid`, `currentUserSid`,
109+
`daclPresent`, `isLocal`, `complete`, `unsupportedAceTypes`, and ordered basic
110+
allow/deny `aces`. `currentUserSid` is the process token's `TokenUser` SID, so
111+
callers can compare it with the owner or their own allowlist without fs-safe
112+
applying trust policy. Each ACE has `{ sid, mask, aceType, flags }`; `flags`
113+
retains the raw byte and decoded
111114
`objectInherit`, `containerInherit`, `noPropagateInherit`, `inheritOnly`,
112115
`inherited`, `successfulAccess`, and `failedAccess` facts. SID strings are
113116
lowercase Windows SID notation. `daclPresent: false` represents a null DACL,

‎native/index.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface WindowsAceFlags {
8585

8686
export interface WindowsSecurityFacts {
8787
ownerSid: string
88+
currentUserSid: string
8889
ownerClass: string
8990
worldWritable: boolean
9091
groupWritable: boolean

‎native/src/windows_security.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct WindowsAccessControlEntry {
2828
#[napi(object)]
2929
pub struct WindowsSecurityFacts {
3030
pub owner_sid: String,
31+
pub current_user_sid: String,
3132
pub owner_class: String,
3233
pub world_writable: bool,
3334
pub group_writable: bool,
@@ -386,6 +387,7 @@ mod windows {
386387
};
387388
let mut facts = WindowsSecurityFacts {
388389
owner_sid: sid_string(owner)?,
390+
current_user_sid: sid_string(current.sid)?,
389391
owner_class: owner_class.to_owned(),
390392
world_writable: dacl.is_null(),
391393
group_writable: false,

‎scripts/release-graph-smoke.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ try {
8484
`import fs from 'node:fs';import os from 'node:os';import path from 'node:path';` +
8585
`import {configureFsSafeNative} from '@openclaw/fs-safe';` +
8686
`import {sha256File} from '@openclaw/fs-safe/durability';` +
87+
`import {readOwnerAndDacl} from '@openclaw/fs-safe/permissions';` +
8788
`const imported=await import('@openclaw/fs-safe-native');const n=imported.default??imported;` +
8889
`if(typeof n.openBeneath!=='function')throw new Error('openBeneath missing');` +
8990
`configureFsSafeNative({mode:'require'});const d=fs.mkdtempSync(path.join(os.tmpdir(),'fs-safe-hash-'));` +
9091
`try{const p=path.join(d,'input');fs.writeFileSync(p,'abc');const h=await sha256File(p);` +
9192
`if(h.digest!=='ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')` +
9293
`throw new Error('native hash mismatch');` +
93-
`console.log(JSON.stringify({nativeBinding:'loaded',openBeneath:typeof n.openBeneath,publicHash:h}));}` +
94+
`const a=readOwnerAndDacl(d);` +
95+
`if(process.platform==='win32'&&(a.status!=='supported'||!/^s-/i.test(a.currentUserSid)))` +
96+
`throw new Error('current process user SID missing');` +
97+
`console.log(JSON.stringify({nativeBinding:'loaded',openBeneath:typeof n.openBeneath,publicHash:h,publicDacl:a}));}` +
9498
`finally{fs.rmSync(d,{recursive:true,force:true});}`,
9599
);
96100
const offOutput = runNode(

‎src/owner-dacl.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type OwnerAndDaclResult =
2323
| {
2424
status: "supported";
2525
ownerSid: string;
26+
currentUserSid: string;
2627
daclPresent: boolean;
2728
isLocal: boolean;
2829
complete: boolean;
@@ -50,6 +51,7 @@ export function readOwnerAndDacl(targetPath: string): OwnerAndDaclResult {
5051
return {
5152
status: "supported",
5253
ownerSid: facts.ownerSid,
54+
currentUserSid: facts.currentUserSid,
5355
daclPresent: facts.daclPresent,
5456
isLocal: facts.isLocal,
5557
complete: facts.aceListComplete,

‎test/owner-dacl.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("readOwnerAndDacl", () => {
3737
({
3838
readOwnerAndDacl: () => ({
3939
ownerSid: "s-1-5-21-owner",
40+
currentUserSid: "s-1-5-21-current-user",
4041
ownerClass: "foreign",
4142
worldWritable: true,
4243
groupWritable: true,
@@ -72,6 +73,7 @@ describe("readOwnerAndDacl", () => {
7273
expect(result).toEqual({
7374
status: "supported",
7475
ownerSid: "s-1-5-21-owner",
76+
currentUserSid: "s-1-5-21-current-user",
7577
daclPresent: true,
7678
isLocal: true,
7779
complete: true,

‎test/private-directory.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ describe("createPrivateDirectory", () => {
6464
await createPrivateDirectory(target);
6565
const facts = native!.readOwnerAndDacl(target);
6666
expect(facts.ownerClass).toBe("current-user");
67+
expect(facts.currentUserSid).toMatch(/^s-/);
68+
expect(facts.ownerSid).toBe(facts.currentUserSid);
6769
expect(facts).toMatchObject({
6870
worldWritable: false,
6971
groupWritable: false,

0 commit comments

Comments
 (0)