dsh-delete-guard 0.0.0-stage → 2.4.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/SECURITY.md ADDED
@@ -0,0 +1,88 @@
1
+ # Security notes
2
+
3
+ ## What this plugin is
4
+
5
+ A **policy layer** on top of the model's tool calls. It intercepts the command
6
+ text a model is about to run and either refuses it or redirects it to a tool that
7
+ moves the target into the OS Recycle Bin.
8
+
9
+ It is **not** a sandbox. It does not confine what a process may do to the file
10
+ system, and it is not meant to stop a deliberate attacker who already controls the
11
+ command line.
12
+
13
+ ## What it does protect
14
+
15
+ - An agent deleting files the user still needs — the ordinary failure mode. Every
16
+ recognised delete is refused and redirected to `file_trash`
17
+ (`SHFileOperationW(FOF_ALLOWUNDO)`), so the item is recoverable from Explorer.
18
+ - Volumes whose file system has no bin at all (exFAT/FAT32): refused before the
19
+ shell is called, because `SHFileOperationW` erases there and still reports
20
+ success.
21
+ - **Deletion on a share, which has no bin.** `file_trash` copies the item to a
22
+ local NTFS volume, verifies the copy (entry set, kinds, sizes), recycles the
23
+ staging folder, and only then removes the original. The guarantee is about
24
+ **content**, not about the original path: after a successful delete the bytes are
25
+ in the local bin and the item at the share path is gone, because there is no bin
26
+ on that volume to hold it. The step order is the safety property — any failure
27
+ before the last step leaves the original untouched, and the last step runs only
28
+ after the bridge confirms the staged copy is in the bin. A share root, a tree
29
+ containing a reparse point, and a staging volume without room are all refused
30
+ before any copy.
31
+ - Irreversible side doors: permanent-erase programs, erases performed through
32
+ .NET APIs, `Invoke-Expression`, deletes delegated to `cmd.exe`, and every
33
+ spelling of emptying the Recycle Bin.
34
+ - **Content destroyed without a delete verb**: a command that reads a file and
35
+ overwrites that same file (`Get-Content f … | Set-Content f`, `sed -i f`,
36
+ `cat f > f`), and a command that slices with an unchecked `$null`-able endpoint
37
+ and then writes the result. Both are refused, and the refusal names the
38
+ copy-then-verify recipe that makes the write undoable. This is the one class
39
+ where routing to the bin cannot help: on a UNC share there is no bin
40
+ (`scripts/recycle-bin.ps1` refuses it), so prevention is the whole remedy.
41
+ Record:
42
+ [docs/incidents/2026-11-14-full-file-rewrite-truncation.md](docs/incidents/2026-11-14-full-file-rewrite-truncation.md).
43
+
44
+ ## Out of scope (by design, and verified as limits)
45
+
46
+ The full list, with evidence, is in [README.md](README.md) 「不挡什么」; the per-rule measurements live in the maintainer's engineering notes (not shipped). The ones that matter for
47
+ a security read:
48
+
49
+ - `Add-Type` compiles arbitrary C#; nothing textual can stop it from calling
50
+ `DeleteFileW`. The guard names the bin-specific API (`SHEmptyRecycleBin`) and
51
+ leaves the general case to the operating system's permissions.
52
+ - Commands assembled at run time (`& $cmd`, `$c='Clear-Recycle'+'Bin'; & $c`) are
53
+ invisible to a text-level parser.
54
+ - A delete split across two `terminal_send` calls cannot be assembled from either
55
+ half.
56
+ - Tools outside the covered list (`pwsh`, `powershell`, `cmd`, `bash`, `sh`,
57
+ `zsh`, `shell`, `terminal_send`, `terminal_write`) are not inspected at all.
58
+ - Deletes inside a script file whose body the guard never sees: it refuses the
59
+ write and the inline forms it can see, not the executed body.
60
+ - Overwrites that do not read the file first (`echo x > notes.md`,
61
+ `Invoke-WebRequest -OutFile`, `git checkout --`). Those are deliberate rewrites,
62
+ not read-modify-write: the new content does not depend on the old, and refusing
63
+ them would mean refusing `write`/`edit` too. README 「不挡什么」 lists them.
64
+ - Post-hoc rollback. There is no "compare the size afterwards and restore": the
65
+ old bytes are needed *before* the write, `tools/post-execute` can only turn a
66
+ result into feedback, and a per-call tree snapshot is O(workspace) and would
67
+ still miss a target outside the workspace.
68
+ - A rule that asks. `{ kind: 'ask' }` resolves to allow in the same tick wherever
69
+ approvals are auto-granted — the default for unattended deployments — so this
70
+ plugin denies rather than asks. A rule that only looks present is worse than no
71
+ rule.
72
+ - Staging a share delete is a *copy*, not an image: ACLs, alternate data streams,
73
+ sparse ranges and ownership are not reproduced (timestamps are), and the
74
+ verification compares entry sets, kinds and sizes rather than hashes. Content
75
+ recovery is the goal; a byte-for-byte clone is not what you get. The cost is also
76
+ honest: O(size) in time and the same in free space on the staging volume, so a
77
+ very large tree can exceed the tool call's timeout.
78
+
79
+ ## Reporting
80
+
81
+ Once this repository is public, use a GitHub Security Advisory (or a private
82
+ message to the maintainer) rather than a public issue for anything that lets a
83
+ recognised delete bypass the Recycle Bin.
84
+
85
+ Please include: the exact command text, which tool carried it, the DSH version,
86
+ and whether the target was on NTFS, a UNC path, or another file system. Do not
87
+ paste real paths from a private machine — reduce them to the smallest form that
88
+ still reproduces the behaviour.
@@ -0,0 +1,16 @@
1
+ # dsh-delete-guard bundle patch.
2
+ #
3
+ # Mounts the recycle-bin guard into the DSH profile. The plugin has a host half
4
+ # only: it hooks `tools/pre-execute` and registers two tools. No core file is
5
+ # touched and no existing plugin source is modified.
6
+ - insert:
7
+ - id: delete-guard
8
+ name: 'dsh-delete-guard'
9
+ config:
10
+ enabled: true
11
+ blockDestructiveCommands: true
12
+ forbidEmptyRecycleBin: true
13
+ forbidWipe: true
14
+ blockScriptDeletes: true
15
+ blockTruncatingWrites: true
16
+ uncRecoverableMove: true