@oked/sdk 0.2.0 → 0.2.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.
- package/dist/classify.js +88 -6
- package/package.json +1 -1
package/dist/classify.js
CHANGED
|
@@ -101,12 +101,11 @@ const HIGH_STAKES_COMMANDS = [
|
|
|
101
101
|
/\bnpm\s+publish\b/,
|
|
102
102
|
/\bnpm\s+unpublish\b/,
|
|
103
103
|
/\bnpx\s+.*\s+deploy\b/,
|
|
104
|
-
// ssh
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
/\bssh\s+(?:\S+\s+)*\S+@\S+/,
|
|
104
|
+
// NOTE: ssh is intentionally NOT a blanket high_stakes here. ssh is a
|
|
105
|
+
// transport — the real effect is whatever runs on the remote host — so it's
|
|
106
|
+
// classified by its remote command in classifySshStage (a read-only remote
|
|
107
|
+
// diagnostic shouldn't prompt; a destructive one still does). scp/rsync to a
|
|
108
|
+
// remote ARE file transfers (outward writes) and stay in HIGH_STAKES_STAGE.
|
|
110
109
|
// himalaya destructive ops. message delete + folder delete/expunge/purge
|
|
111
110
|
// wipe mail from the server irreversibly; account delete wipes local config.
|
|
112
111
|
/\bhimalaya\s+message\s+delete\b/,
|
|
@@ -540,6 +539,83 @@ function classifyEnvStage(stage) {
|
|
|
540
539
|
}
|
|
541
540
|
return "safe"; // `env` / `env -u X` with no command just prints the environment
|
|
542
541
|
}
|
|
542
|
+
// ssh options that consume a following argument token (the rest are flags).
|
|
543
|
+
const SSH_ARG_OPTS = new Set([
|
|
544
|
+
"-b", "-c", "-D", "-E", "-e", "-F", "-I", "-i", "-J", "-L", "-l", "-m",
|
|
545
|
+
"-O", "-o", "-p", "-Q", "-R", "-S", "-W", "-w",
|
|
546
|
+
]);
|
|
547
|
+
/**
|
|
548
|
+
* `ssh [opts] [user@]host [remote command]` — ssh is a transport, so the tier
|
|
549
|
+
* comes from the REMOTE command, classified by the same effect rules as a local
|
|
550
|
+
* one (`ssh host ls` → safe; `ssh host 'rm -rf /data'` → high_stakes). An ssh
|
|
551
|
+
* with no command opens an interactive shell, and port/dynamic forwarding
|
|
552
|
+
* (`-L`/`-R`/`-D`/`-W`) grants opaque access — neither is inspectable, so both
|
|
553
|
+
* get a `review` floor (one prompt for remote access). Returns null if the stage
|
|
554
|
+
* isn't an ssh invocation. Excludes `ssh-keygen`/`ssh-add`/`ssh-keyscan` (the
|
|
555
|
+
* `^ssh\s` anchor requires whitespace, not a hyphen).
|
|
556
|
+
*/
|
|
557
|
+
function classifySshStage(stage) {
|
|
558
|
+
const lead = /^ssh\s+/.exec(stage);
|
|
559
|
+
if (!lead)
|
|
560
|
+
return null;
|
|
561
|
+
const readToken = (from) => {
|
|
562
|
+
let i = from;
|
|
563
|
+
let quote = null;
|
|
564
|
+
while (i < stage.length) {
|
|
565
|
+
const ch = stage[i];
|
|
566
|
+
if (quote) {
|
|
567
|
+
if (ch === quote)
|
|
568
|
+
quote = null;
|
|
569
|
+
i++;
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
if (ch === '"' || ch === "'") {
|
|
573
|
+
quote = ch;
|
|
574
|
+
i++;
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (/\s/.test(ch))
|
|
578
|
+
break;
|
|
579
|
+
i++;
|
|
580
|
+
}
|
|
581
|
+
return i;
|
|
582
|
+
};
|
|
583
|
+
let i = lead[0].length;
|
|
584
|
+
let sawForward = false;
|
|
585
|
+
while (i < stage.length) {
|
|
586
|
+
while (i < stage.length && /\s/.test(stage[i]))
|
|
587
|
+
i++;
|
|
588
|
+
if (i >= stage.length)
|
|
589
|
+
break;
|
|
590
|
+
const start = i;
|
|
591
|
+
i = readToken(i);
|
|
592
|
+
const tok = stage.slice(start, i);
|
|
593
|
+
if (tok.startsWith("-")) {
|
|
594
|
+
if (/^-[LRDW]/.test(tok))
|
|
595
|
+
sawForward = true; // forwarding/tunnel
|
|
596
|
+
if (SSH_ARG_OPTS.has(tok)) { // separated option arg
|
|
597
|
+
while (i < stage.length && /\s/.test(stage[i]))
|
|
598
|
+
i++;
|
|
599
|
+
i = readToken(i);
|
|
600
|
+
}
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
// First non-option token is the [user@]host. Everything after it is the
|
|
604
|
+
// remote command (usually a single quoted string).
|
|
605
|
+
if (sawForward)
|
|
606
|
+
return "review";
|
|
607
|
+
let rest = stage.slice(i).trim();
|
|
608
|
+
if (!rest)
|
|
609
|
+
return "review"; // interactive shell
|
|
610
|
+
// Strip one wrapping quote layer so the remote command's own operators
|
|
611
|
+
// (`;`, `|`) are classified as command separators, not quoted data.
|
|
612
|
+
if (rest.length >= 2 && (rest[0] === '"' || rest[0] === "'") && rest[rest.length - 1] === rest[0]) {
|
|
613
|
+
rest = rest.slice(1, -1);
|
|
614
|
+
}
|
|
615
|
+
return classifyBashCommand(rest);
|
|
616
|
+
}
|
|
617
|
+
return "review"; // only options / a bare host token → treat as remote access
|
|
618
|
+
}
|
|
543
619
|
function classifyBashCommand(command) {
|
|
544
620
|
if (!command)
|
|
545
621
|
return "safe";
|
|
@@ -597,6 +673,12 @@ function classifyBashCommand(command) {
|
|
|
597
673
|
const envTier = classifyEnvStage(trimmed);
|
|
598
674
|
if (envTier !== null)
|
|
599
675
|
return envTier;
|
|
676
|
+
// ssh is a transport — classify the remote command it runs (interactive /
|
|
677
|
+
// port-forwarding ssh has no inspectable command → review floor). scp/rsync
|
|
678
|
+
// to a remote are file transfers and stay high_stakes (HIGH_STAKES_STAGE).
|
|
679
|
+
const sshTier = classifySshStage(trimmed);
|
|
680
|
+
if (sshTier !== null)
|
|
681
|
+
return sshTier;
|
|
600
682
|
// sudo: privilege escalation. A high-stakes inner command was already caught
|
|
601
683
|
// by the full-string scan above (\b patterns match through the `sudo` prefix);
|
|
602
684
|
// anything else still warrants review.
|