daftari 3.12.0 → 3.12.1

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.
@@ -0,0 +1,61 @@
1
+ // realpath-confine — symlink-aware path confinement shared by the storage
2
+ // backend (#6/F5) and the hook loader (F2). Lexical resolve()/relative()
3
+ // confinement cannot see through symlinks: a component under a root may link
4
+ // outside it, and a following read/write/import would escape. These helpers
5
+ // resolve real paths and re-check confinement, failing closed when a path
6
+ // cannot be proven.
7
+ //
8
+ // This is IO (realpathSync), so it lives apart from the lexical, IO-free
9
+ // helpers in utils/paths.ts. The semantics mirror resolveVaultPath in
10
+ // storage/local.ts: a symlink that stays inside the root is allowed; one that
11
+ // escapes it is rejected.
12
+ import { realpathSync } from "node:fs";
13
+ import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
14
+ import { err, ok } from "../frontmatter/types.js";
15
+ // The real (symlink-resolved) path of `p`, walking up over not-yet-existing
16
+ // tail components so a target whose leaf does not exist yet (e.g. a fresh put)
17
+ // still resolves through its real ancestors. Returns null on any non-ENOENT
18
+ // error (EACCES/ELOOP/ENOTDIR) — we cannot prove where the path resolves, so
19
+ // the caller must reject rather than trust an unverified lexical path.
20
+ export function realpathConfined(p) {
21
+ let current = p;
22
+ const tail = [];
23
+ for (;;) {
24
+ try {
25
+ const real = realpathSync(current);
26
+ return tail.length > 0 ? resolve(real, ...tail) : real;
27
+ }
28
+ catch (e) {
29
+ if (e.code !== "ENOENT")
30
+ return null;
31
+ const parent = dirname(current);
32
+ if (parent === current)
33
+ return null; // reached the fs root; nothing resolved
34
+ tail.unshift(basename(current));
35
+ current = parent;
36
+ }
37
+ }
38
+ }
39
+ // Confine `target` under `root` by realpath'ing BOTH and re-checking that the
40
+ // real target stays within the real root. `root` is realpath'd too so a root
41
+ // that legitimately sits under a symlinked prefix (e.g. macOS /var → /private/var)
42
+ // does not spuriously reject its own children. Returns the (lexical) target on
43
+ // success — the caller performs IO on it, having proven it resolves inside.
44
+ //
45
+ // TOCTOU: the check precedes the IO, so a component swapped to a symlink
46
+ // between this call and the IO could still escape. Node offers no
47
+ // directory-relative no-follow open here; this closes the durable-symlink
48
+ // vector, not a racing attacker with write access to the traversed path.
49
+ export function confineRealpath(root, target, label = "path") {
50
+ const realRoot = realpathConfined(root);
51
+ const realTarget = realpathConfined(target);
52
+ if (realRoot === null || realTarget === null) {
53
+ return err(new Error(`${label} escapes root: ${target}`));
54
+ }
55
+ const rel = relative(realRoot, realTarget);
56
+ if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
57
+ return err(new Error(`${label} escapes root: ${target}`));
58
+ }
59
+ return ok(target);
60
+ }
61
+ //# sourceMappingURL=realpath-confine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realpath-confine.js","sourceRoot":"","sources":["../../src/utils/realpath-confine.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AACzE,6EAA6E;AAC7E,4EAA4E;AAC5E,0EAA0E;AAC1E,oBAAoB;AACpB,EAAE;AACF,yEAAyE;AACzE,sEAAsE;AACtE,8EAA8E;AAC9E,0BAA0B;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,yBAAyB,CAAC;AAE/D,4EAA4E;AAC5E,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,CAAS;IACxC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,SAAS,CAAC;QACR,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO,IAAI,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KAAK,kBAAkB,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;AACpB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "daftari",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "description": "An open-source, multi-user knowledge vault exposed to AI agents via an MCP server.",
5
5
  "mcpName": "io.github.mavaali/daftari",
6
6
  "license": "MIT",