@rhize/skill-forge 0.11.1 → 0.11.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.
package/dist/cli.js CHANGED
@@ -131,7 +131,32 @@ function collectNpxPackageSpecs(args) {
131
131
  }
132
132
  return { packageFlagSpecs, positionalSpec };
133
133
  }
134
+ var ISO_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
135
+ var PATH_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
136
+ function looksLikeFsPath(v) {
137
+ if (!/^(?:\/|~\/|\.\.?\/)/.test(v)) return false;
138
+ const segments = v.replace(/^~/, "").split("/").filter(Boolean);
139
+ return segments.length >= 2 && segments.every((seg) => PATH_SEGMENT_RE.test(seg));
140
+ }
141
+ function looksLikeBareUrl(v) {
142
+ let url;
143
+ try {
144
+ url = new URL(v);
145
+ } catch {
146
+ return false;
147
+ }
148
+ if (!["http:", "https:", "ws:", "wss:", "file:"].includes(url.protocol)) return false;
149
+ if (url.username !== "" || url.password !== "") return false;
150
+ if (url.search !== "") return false;
151
+ return true;
152
+ }
153
+ function looksStructuredNonSecret(value) {
154
+ const v = value.trim().replace(/^[[\s'"]+/, "").replace(/[\]\s'",]+$/, "");
155
+ if (v === "") return false;
156
+ return ISO_TIMESTAMP_RE.test(v) || looksLikeBareUrl(v) || looksLikeFsPath(v);
157
+ }
134
158
  function looksHighEntropy(value) {
159
+ if (looksStructuredNonSecret(value)) return false;
135
160
  if (/\s/.test(value)) return false;
136
161
  if (value.length < 20) return false;
137
162
  const hasLower = /[a-z]/.test(value);
@@ -1024,6 +1049,37 @@ import { execFile } from "child_process";
1024
1049
  import { delimiter as delimiter2, join as join9 } from "path";
1025
1050
  import { promisify } from "util";
1026
1051
  var execFileAsync = promisify(execFile);
1052
+ var RM_RF_TARGET_RE = /\brm\s+(?:-[a-z]+\s+)+("[^"]*"|'[^']*'|[^\s;|&)"'`]+)/i;
1053
+ function refineRmRf(line) {
1054
+ const match = line.match(RM_RF_TARGET_RE);
1055
+ if (!match) {
1056
+ return { severity: "HIGH", message: "recursive force-delete (rm -rf) with an unparseable target \u2014 verify the path is scoped" };
1057
+ }
1058
+ const target = match[1].replace(/^["']|["']$/g, "").trim();
1059
+ if (target.includes("$") || target.includes("`")) {
1060
+ return {
1061
+ severity: "HIGH",
1062
+ message: `recursive force-delete of "${target}" \u2014 the target is a shell expansion; if it is empty or unset this can delete far more than intended`
1063
+ };
1064
+ }
1065
+ if (target === "/" || target === "/*" || target === "*" || target === "." || target === ".." || target === "~" || target === "~/") {
1066
+ return { severity: "HIGH", message: `recursive force-delete of "${target}" \u2014 this targets the filesystem root, the home directory, or everything in the working directory` };
1067
+ }
1068
+ if (target.startsWith("~")) {
1069
+ return { severity: "HIGH", message: `recursive force-delete of "${target}" \u2014 targets a path inside the home directory, outside any project` };
1070
+ }
1071
+ if (target.split("/").includes("..")) {
1072
+ return { severity: "HIGH", message: `recursive force-delete of "${target}" \u2014 the target escapes the current directory via ".."` };
1073
+ }
1074
+ if (target.startsWith("/")) {
1075
+ const segments = target.split("/").filter(Boolean);
1076
+ if (segments.length < 3) {
1077
+ return { severity: "HIGH", message: `recursive force-delete of "${target}" \u2014 a shallow absolute path like this is a system directory` };
1078
+ }
1079
+ return { severity: "MEDIUM", message: `recursive force-delete of "${target}" \u2014 an absolute path outside any project directory` };
1080
+ }
1081
+ return null;
1082
+ }
1027
1083
  var DENY_RULES = [
1028
1084
  {
1029
1085
  rule: "curl-pipe-shell",
@@ -1047,7 +1103,8 @@ var DENY_RULES = [
1047
1103
  rule: "destructive-rm-rf",
1048
1104
  severity: "HIGH",
1049
1105
  pattern: /\brm\s+-[a-z]*r[a-z]*f[a-z]*\b|\brm\s+-[a-z]*f[a-z]*r[a-z]*\b/i,
1050
- message: "recursive force-delete (rm -rf) \u2014 verify the target path is scoped"
1106
+ message: "recursive force-delete (rm -rf) \u2014 verify the target path is scoped",
1107
+ refine: refineRmRf
1051
1108
  },
1052
1109
  {
1053
1110
  rule: "credential-file-access",
@@ -1102,11 +1159,13 @@ function scanStaticRules(targetPath) {
1102
1159
  for (const rule of DENY_RULES) {
1103
1160
  for (let i = 0; i < lines.length; i++) {
1104
1161
  if (rule.pattern.test(lines[i])) {
1162
+ const refined = rule.refine ? rule.refine(lines[i]) : { severity: rule.severity, message: rule.message };
1163
+ if (!refined) continue;
1105
1164
  findings.push({
1106
- severity: rule.severity,
1165
+ severity: refined.severity,
1107
1166
  rule: rule.rule,
1108
1167
  file,
1109
- detail: `line ${i + 1}: ${rule.message}`
1168
+ detail: `line ${i + 1}: ${refined.message}`
1110
1169
  });
1111
1170
  }
1112
1171
  }
@@ -1243,14 +1302,22 @@ function scanJsonConfig(file, parsed) {
1243
1302
  }
1244
1303
  if (node.env && typeof node.env === "object" && !Array.isArray(node.env)) {
1245
1304
  for (const [key, value] of Object.entries(node.env)) {
1246
- if (typeof value !== "string" || isPlaceholderValue(value)) continue;
1247
- if (looksCredentialKey(key) || looksHighEntropy(value)) {
1305
+ if (typeof value !== "string") continue;
1306
+ const kind = classifyCredentialAssignment(key, value);
1307
+ if (kind === "inline-secret") {
1248
1308
  findings.push({
1249
1309
  severity: "HIGH",
1250
1310
  rule: "mcp-inline-credential-value",
1251
1311
  file,
1252
1312
  detail: `env.${key} has an inline credential value \u2014 emit an empty string and document that the user must fill it in`
1253
1313
  });
1314
+ } else if (kind === "file-path") {
1315
+ findings.push({
1316
+ severity: "LOW",
1317
+ rule: "mcp-credential-file-path",
1318
+ file,
1319
+ detail: `env.${key} points at a credential file rather than an inline secret \u2014 the value leaks nothing, but keep that file out of version control`
1320
+ });
1254
1321
  }
1255
1322
  }
1256
1323
  }
@@ -1262,15 +1329,29 @@ var DANGEROUS_FLAG_RE = /--dangerously-[\w-]+|--no-sandbox\b/g;
1262
1329
  var CREDENTIAL_ASSIGNMENT_RE = /["']?([A-Za-z][A-Za-z0-9_]*)["']?\s*[:=]\s*["']([^"']{6,})["']/g;
1263
1330
  var CREDENTIAL_ASSIGNMENT_UNQUOTED_RE = /^\s*(?:export\s+|-\s+)?([A-Za-z][A-Za-z0-9_]*)\s*[:=]\s*(\S+)/;
1264
1331
  var LEADING_QUOTE_RE = /^["']/;
1332
+ function classifyCredentialAssignment(key, value) {
1333
+ if (isPlaceholderValue(value)) return "none";
1334
+ const credentialKey = looksCredentialKey(key);
1335
+ if (credentialKey && looksStructuredNonSecret(value) && !/^[a-z]+:\/\//i.test(value.trim())) return "file-path";
1336
+ if (credentialKey || looksHighEntropy(value)) return "inline-secret";
1337
+ return "none";
1338
+ }
1265
1339
  function pushCredentialFinding(findings, file, lineNo, varName, value) {
1266
- if (isPlaceholderValue(value)) return;
1267
- if (looksCredentialKey(varName) || looksHighEntropy(value)) {
1340
+ const kind = classifyCredentialAssignment(varName, value);
1341
+ if (kind === "inline-secret") {
1268
1342
  findings.push({
1269
1343
  severity: "HIGH",
1270
1344
  rule: "mcp-inline-credential-value",
1271
1345
  file,
1272
1346
  detail: `line ${lineNo}: inline credential value assigned to ${varName}`
1273
1347
  });
1348
+ } else if (kind === "file-path") {
1349
+ findings.push({
1350
+ severity: "LOW",
1351
+ rule: "mcp-credential-file-path",
1352
+ file,
1353
+ detail: `line ${lineNo}: ${varName} points at a credential file rather than an inline secret \u2014 the value leaks nothing, but keep that file out of version control`
1354
+ });
1274
1355
  }
1275
1356
  }
1276
1357
  function scanTextFile(file, content, allowCredentialCheck) {