@tritard/waterbrother 0.16.1 → 0.16.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/security.js +22 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tritard/waterbrother",
3
- "version": "0.16.1",
3
+ "version": "0.16.3",
4
4
  "description": "Waterbrother: bring-your-own-model coding CLI with local tools, sessions, operator modes, and approval controls",
5
5
  "type": "module",
6
6
  "bin": {
package/src/security.js CHANGED
@@ -52,17 +52,33 @@ function checkFilePath(filePath, cwd) {
52
52
  const normalized = filePath.replace(/\\/g, "/");
53
53
  const cwdNorm = cwd.replace(/\\/g, "/");
54
54
 
55
+ // Resolve the actual target path
56
+ const resolved = path.resolve(cwd, filePath).replace(/\\/g, "/");
57
+ const resolvedLower = resolved.toLowerCase();
58
+ const cwdLower = cwdNorm.toLowerCase();
59
+
55
60
  // Scope escalation: writing outside project directory
56
- if (!normalized.startsWith(cwdNorm) && !normalized.startsWith("./") && !normalized.startsWith("../")) {
57
- // Absolute path outside cwd
58
- if (path.isAbsolute(filePath)) {
59
- reasons.push({ rule: "scope-escalation", message: `Writing outside project directory: ${filePath}` });
61
+ // Check for directory traversal (../../etc/passwd) and absolute paths outside cwd
62
+ if (!resolvedLower.startsWith(cwdLower + "/") && resolvedLower !== cwdLower) {
63
+ reasons.push({ rule: "scope-escalation", message: `Writing outside project directory: ${filePath}` });
64
+ }
65
+
66
+ // Dangerous system paths — never allow regardless of cwd
67
+ const dangerousPaths = ["/etc", "/usr", "/bin", "/sbin", "/var", "/root", "/sys", "/proc", "C:/Windows", "C:/Program Files"];
68
+ for (const dp of dangerousPaths) {
69
+ if (resolvedLower.startsWith(dp.toLowerCase())) {
70
+ reasons.push({ rule: "system-path-write", message: `Writing to system directory: ${resolved}` });
71
+ break;
60
72
  }
61
73
  }
62
74
 
63
- // Home directory protection
75
+ // Home directory protection — only block writes to home dir root itself
76
+ // Allow writes to subdirectories (Desktop/my-project, Documents/app, etc.)
64
77
  if (HOME_DIR && cwdNorm === HOME_DIR) {
65
- reasons.push({ rule: "home-dir-write", message: "Writing files in home directory — use a project directory instead" });
78
+ const depth = resolved.split("/").length - HOME_DIR.split("/").length;
79
+ if (depth <= 1) {
80
+ reasons.push({ rule: "home-dir-write", message: "Writing files in home directory — use a project directory instead" });
81
+ }
66
82
  }
67
83
 
68
84
  // Self-modification