nextclaw-core 0.4.3 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +25 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -982,16 +982,17 @@ var ExecTool = class extends Tool {
982
982
  "\\brm\\s+-[rf]{1,2}\\b",
983
983
  "\\bdel\\s+/[fq]\\b",
984
984
  "\\brmdir\\s+/s\\b",
985
- "\\b(format|mkfs|diskpart)\\b",
986
985
  "\\bdd\\s+if=",
987
986
  ">\\s*/dev/sd",
988
987
  "\\b(shutdown|reboot|poweroff)\\b",
989
988
  ":\\(\\)\\s*\\{.*\\};\\s*:"
990
989
  ]).map((pattern) => new RegExp(pattern, "i"));
991
990
  this.allowPatterns = (options.allowPatterns ?? []).map((pattern) => new RegExp(pattern, "i"));
991
+ this.dangerousCommands = ["format", "diskpart", "mkfs"];
992
992
  }
993
993
  denyPatterns;
994
994
  allowPatterns;
995
+ dangerousCommands;
995
996
  get name() {
996
997
  return "exec";
997
998
  }
@@ -1037,6 +1038,9 @@ ${stderr}`);
1037
1038
  }
1038
1039
  guardCommand(command, cwd) {
1039
1040
  const normalized = command.trim().toLowerCase();
1041
+ if (this.isDangerousCommand(normalized)) {
1042
+ return "Error: Command blocked by safety guard (dangerous pattern detected)";
1043
+ }
1040
1044
  for (const pattern of this.denyPatterns) {
1041
1045
  if (pattern.test(normalized)) {
1042
1046
  return "Error: Command blocked by safety guard (dangerous pattern detected)";
@@ -1062,6 +1066,26 @@ ${stderr}`);
1062
1066
  }
1063
1067
  return null;
1064
1068
  }
1069
+ isDangerousCommand(command) {
1070
+ const segments = command.split(/\s*(?:\|\||&&|;|\|)\s*/);
1071
+ for (const segment2 of segments) {
1072
+ const match = segment2.trim().match(/^(?:sudo\s+)?([^\s]+)/i);
1073
+ if (!match) {
1074
+ continue;
1075
+ }
1076
+ const token = match[1]?.toLowerCase() ?? "";
1077
+ if (!token) {
1078
+ continue;
1079
+ }
1080
+ if (this.dangerousCommands.includes(token)) {
1081
+ return true;
1082
+ }
1083
+ if (token.startsWith("mkfs")) {
1084
+ return true;
1085
+ }
1086
+ }
1087
+ return false;
1088
+ }
1065
1089
  };
1066
1090
  function truncateOutput(result, maxLen = 1e4) {
1067
1091
  if (result.length <= maxLen) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextclaw-core",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "private": false,
5
5
  "description": "Nextclaw runtime core (agent, channels, providers, config).",
6
6
  "type": "module",