mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 06:30:54 +08:00
fix(intercept): destructive commands score high; chunk batch decisions to the server limit
The destructive shell signal is worth 60 instead of 50, so a destructive command alone scores 10 + 60 = 70, high. The level thresholds are unchanged. The approvals page sends the selection in sequential calls of at most 100 ids, the server limit (maxBatchDecide), instead of one call that the server would refuse with 400 when more than 100 rows are selected. If a call fails, sending stops: its ids and the later ones stay selected with the error, and ids already decided stay decided. The final toast gives the totals.
This commit is contained in:
+2
-1
@@ -47,7 +47,8 @@ const shellBase = 10
|
||||
|
||||
// shellSignals are additive; each counts once, and reasons follow this order.
|
||||
var shellSignals = []riskSignal{
|
||||
reSignal("destructive command (rm -r, dd, mkfs, shred, truncate, DROP TABLE, DELETE FROM, shutdown)", 50,
|
||||
// 60 so that a destructive command alone reaches high: 10 + 60 = 70.
|
||||
reSignal("destructive command (rm -r, dd, mkfs, shred, truncate, DROP TABLE, DELETE FROM, shutdown)", 60,
|
||||
`(?i)\brm\s+([^;&|]*\s)?(-[a-z]*r[a-z]*|--recursive)(\s|$)|\bdd\s+[^;&|]*\b(if|of)=|\bmkfs\b|\bshred\b|\btruncate\b|\bdrop\s+table\b|\bdelete\s+from\b|\bshutdown\b`),
|
||||
reSignal("privilege change (sudo, su, chmod 777, setcap)", 40,
|
||||
`(^|[\s;&|(])(sudo|su)(\s|$)|\bchmod\s+(-\w+\s+)*0?777\b|\bsetcap\b`),
|
||||
|
||||
+10
-9
@@ -30,16 +30,17 @@ func TestScoreRisk(t *testing.T) {
|
||||
reasons []string
|
||||
}{
|
||||
{"plain command", "Bash", bash("ls -la"), 10, "low", nil},
|
||||
{"rm -rf", "Bash", bash("rm -rf /tmp/x"), 60, "medium", []string{sig(destructive)}},
|
||||
{"rm -R", "Bash", bash("rm -R build"), 60, "medium", []string{sig(destructive)}},
|
||||
{"destructive alone is high", "Bash", bash("rm -rf ./cache"), 70, "high", []string{sig(destructive)}},
|
||||
{"rm -rf", "Bash", bash("rm -rf /tmp/x"), 70, "high", []string{sig(destructive)}},
|
||||
{"rm -R", "Bash", bash("rm -R build"), 70, "high", []string{sig(destructive)}},
|
||||
{"rm of a file named -r suffix", "Bash", bash("rm file-r"), 10, "low", nil},
|
||||
{"dd", "Bash", bash("dd if=/dev/zero of=/dev/sda"), 60, "medium", []string{sig(destructive)}},
|
||||
{"mkfs", "Bash", bash("mkfs.ext4 /dev/sdb1"), 60, "medium", []string{sig(destructive)}},
|
||||
{"shred", "Bash", bash("shred -u key.pem"), 60, "medium", []string{sig(destructive)}},
|
||||
{"truncate", "Bash", bash("truncate -s 0 app.log"), 60, "medium", []string{sig(destructive)}},
|
||||
{"drop table", "Bash", bash(`psql -c "DROP TABLE users"`), 60, "medium", []string{sig(destructive)}},
|
||||
{"delete from", "Bash", bash(`psql -c "delete from users"`), 60, "medium", []string{sig(destructive)}},
|
||||
{"shutdown", "Bash", bash("shutdown -h now"), 60, "medium", []string{sig(destructive)}},
|
||||
{"dd", "Bash", bash("dd if=/dev/zero of=/dev/sda"), 70, "high", []string{sig(destructive)}},
|
||||
{"mkfs", "Bash", bash("mkfs.ext4 /dev/sdb1"), 70, "high", []string{sig(destructive)}},
|
||||
{"shred", "Bash", bash("shred -u key.pem"), 70, "high", []string{sig(destructive)}},
|
||||
{"truncate", "Bash", bash("truncate -s 0 app.log"), 70, "high", []string{sig(destructive)}},
|
||||
{"drop table", "Bash", bash(`psql -c "DROP TABLE users"`), 70, "high", []string{sig(destructive)}},
|
||||
{"delete from", "Bash", bash(`psql -c "delete from users"`), 70, "high", []string{sig(destructive)}},
|
||||
{"shutdown", "Bash", bash("shutdown -h now"), 70, "high", []string{sig(destructive)}},
|
||||
{"sudo", "Bash", bash("sudo id"), 50, "medium", []string{sig(privilege)}},
|
||||
{"su", "Bash", bash("su - root"), 50, "medium", []string{sig(privilege)}},
|
||||
{"chmod 777", "Bash", bash("chmod -R 777 /srv"), 50, "medium", []string{sig(privilege)}},
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestInterceptBatchDecideHTTP(t *testing.T) {
|
||||
}
|
||||
return id
|
||||
}
|
||||
id1, id2, id3 := pending("ls"), pending("rm -rf /tmp/x"), pending("sudo rm -rf / ; cat /etc/shadow")
|
||||
id1, id2, id3 := pending("ls"), pending("nmap -sV target.example"), pending("sudo rm -rf / ; cat /etc/shadow")
|
||||
|
||||
// The pending JSON keeps every historical field and adds risk.
|
||||
var historical map[string]any
|
||||
|
||||
@@ -642,6 +642,9 @@ function serverColumnCount() {
|
||||
|
||||
type Selection = { selected: Set<number>; toggle: (id: number) => void; toggleAll: () => void };
|
||||
|
||||
// Server limit on ids per batch-decide call (maxBatchDecide in server/intercept.go).
|
||||
const batchDecideMax = 100;
|
||||
|
||||
function ApprovalTable({
|
||||
rows,
|
||||
busy,
|
||||
@@ -938,24 +941,39 @@ export function ApprovalRecords({ taskId }: { taskId?: string }) {
|
||||
setSelected(selectedRows.length === pending.length ? new Set() : new Set(pending.map((row) => row.id))),
|
||||
};
|
||||
|
||||
// Each id is decided by the server exactly like a single decision; a failed
|
||||
// id stays pending and selected, with its error listed.
|
||||
// Each id is decided by the server exactly like a single decision. The server
|
||||
// takes at most 100 ids per call (maxBatchDecide in server/intercept.go) and
|
||||
// the pending queue is not paginated, so the selection goes out in sequential
|
||||
// chunks of at most batchDecideMax ids. If a chunk cannot be sent (network
|
||||
// error, 400), sending stops: its ids and the later ones stay selected with
|
||||
// the error, and chunks already decided stay decided. A failed id stays
|
||||
// pending and selected, with its error listed.
|
||||
const batchDecide = async (decision: "allowed" | "denied") => {
|
||||
const ids = selectedRows.map((row) => row.id);
|
||||
if (!ids.length || decisionLock.current) return;
|
||||
decisionLock.current = true;
|
||||
setDeciding(true);
|
||||
let decided = 0;
|
||||
const failed: { id: number; error: string }[] = [];
|
||||
try {
|
||||
const res = await api.interceptBatchDecide(ids, decision);
|
||||
for (let start = 0; start < ids.length; start += batchDecideMax) {
|
||||
try {
|
||||
const res = await api.interceptBatchDecide(ids.slice(start, start + batchDecideMax), decision);
|
||||
decided += res.decided;
|
||||
for (const r of res.results) if (!r.ok) failed.push({ id: r.id, error: r.error || "Not decided" });
|
||||
} catch (e) {
|
||||
const error = `Not sent: ${(e as Error).message || "request failed"}`;
|
||||
for (const id of ids.slice(start)) failed.push({ id, error });
|
||||
break;
|
||||
}
|
||||
}
|
||||
request.current++;
|
||||
const failed = res.results.filter((r) => !r.ok).map((r) => ({ id: r.id, error: r.error || "Not decided" }));
|
||||
setBatchErrors(failed);
|
||||
setSelected(new Set(failed.map((f) => f.id)));
|
||||
setRevision((v) => v + 1);
|
||||
if (res.decided) toast.success(`${res.decided} ${decision === "allowed" ? "allowed" : "denied"}`);
|
||||
if (res.failed) toast.error(`${res.failed} not decided, see the errors above the pending list`);
|
||||
} catch (e) {
|
||||
toast.error((e as Error).message);
|
||||
const verb = decision === "allowed" ? "allowed" : "denied";
|
||||
if (failed.length) toast.error(`${decided} ${verb}, ${failed.length} not decided (see the errors listed above)`);
|
||||
else toast.success(`${decided} ${verb}`);
|
||||
} finally {
|
||||
decisionLock.current = false;
|
||||
setDeciding(false);
|
||||
|
||||
Reference in New Issue
Block a user