dcg

Windows Filesystem

windows.filesystem

Protects against recursive/forced filesystem destruction on Windows: cmd `del /s`, `rd /s`, `format <drive>:`, PowerShell `Remove-Item -Recurse (with or without `-Force`; aliases included), `Clear-Content`, `Clear-RecycleBin`, and the .NET recursive-delete APIs `[System.IO.Directory]::Delete($path, $true)` and `<DirectoryInfo>.Delete($true)`.

  • 11blocking rules
  • 2safe patterns
  • 8Critical
  • 2High
  • 1Medium
~/.config/dcg/config.toml
[packs]
enabled = ["windows.filesystem"]

Evaluated when a command contains del, DEL, erase, ERASE, rd, RD, rmdir, RMDIR, format, FORMAT.

Recorded verdicts

  • rd /s /q C:\Users\me\projectBlockedwindows.filesystem:rd-recursive

Blocking rules

Each rule ID is windows.filesystem:<name>. Use it in allowlists and [policy.rules].

  1. del-recursive

    Critical

    del /s recursively deletes every matching file in a directory tree.

    Explanation
    `del /s` recurses into subdirectories and deletes matching files; combined with `/q` there is no per-file prompt and `/f` forces read-only files too. A wrong path or a wildcard at a high level (e.g. `del /s /q C:\src\*`) destroys a whole tree with no Recycle Bin and no undo. Safer alternatives: - Scope the path precisely and drop /q so deletions are confirmed - Move the directory to %TEMP% instead of deleting it outright
  2. directoryinfo-delete-recursive

    Critical

    .Delete($true) on a DirectoryInfo object recursively deletes the directory tree.

    Explanation
    `<DirectoryInfo>.Delete($true)` — for example `(Get-Item $path).Delete($true)` or a `[System.IO.DirectoryInfo]` variable — recursively deletes the directory and all of its contents, bypassing the Recycle Bin exactly like `[System.IO.Directory]::Delete($path, $true)`. Safer alternatives: - Preview with the cmdlet equivalent: Remove-Item -Recurse <path> -WhatIf - Move the directory to a temp/trash location instead of deleting it
  3. dotnet-directory-delete-recursive

    Critical

    [System.IO.Directory]::Delete with a true recursive flag deletes an entire directory tree.

    Explanation
    `[System.IO.Directory]::Delete($path, $true)` (or the `[IO.Directory]` accelerator spelling) is the .NET equivalent of `Remove-Item -Recurse -Force`: it removes the directory and everything under it, bypasses the Recycle Bin, and needs no external tool — plain PowerShell can call it directly. A wrong path, relative path, or variable expansion destroys an entire working tree with no undo. Safer alternatives: - Preview with the cmdlet equivalent: Remove-Item -Recurse <path> -WhatIf - Move the directory to a temp/trash location instead of deleting it
  4. format-drive

    Critical

    format <drive>: erases an entire volume.

    Explanation
    `format X:` re-creates the filesystem on a whole volume, destroying all data on it. With `/q` (quick) and `/y` it proceeds with no confirmation. A wrong drive letter formats the wrong disk. Safer alternatives: - Run `Get-Volume` / `wmic logicaldisk get name` and confirm the exact drive first - Back up the volume before any format
  5. rd-recursive

    Critical

    rd /s deletes a directory and its entire contents.

    Explanation
    `rd /s` (alias `rmdir /s`) removes a directory and every file and subfolder under it; with `/q` it does so without confirmation. `rd /s /q C:\path` is the Windows equivalent of `rm -rf` and bypasses the Recycle Bin entirely. Safer alternatives: - Drop /q so the removal is confirmed - Move the directory to %TEMP% first so it can be recovered
  6. remove-item-recurse

    Critical

    Remove-Item -Recurse permanently deletes a tree with no Recycle Bin.

    Explanation
    `Remove-Item -Recurse` (or an alias such as `rm`/`del`/`ri`) permanently deletes a directory and everything under it. `-Force` is not required for recursive deletion; it only broadens removal to hidden/read-only items. Remove-Item bypasses the Recycle Bin, so a wrong path can destroy a profile, repository, or drive tree with no undo. Safer alternatives: - Re-run with -WhatIf to preview what would be removed - Move-Item the target to a temp location instead of deleting
  7. remove-item-recurse-force

    Critical

    Remove-Item -Recurse -Force deletes a tree with no Recycle Bin and no prompt.

    Explanation
    `Remove-Item -Recurse -Force` (or an alias such as `rm`/`del`/`ri`) deletes a directory and everything under it. `-Recurse` permanently descends and removes the whole tree; `-Force` additionally includes hidden/read-only items. Remove-Item does not use the Recycle Bin. Pointed at a profile, repo, or drive root this is catastrophic and irreversible. Safer alternatives: - Re-run with -WhatIf to preview what would be removed - Move-Item the target to a temp location instead of deleting
  8. windows-filesystem-semantic-unverified

    Critical

    The Windows filesystem command contains unresolved shell syntax in an executable or destructive option position.

    Explanation
    Review the fully expanded Windows command before allowing execution. Dynamic or malformed shell syntax in the executable or recursive/forced option roles can conceal an irreversible filesystem operation.
  9. clear-content

    High

    Clear-Content empties a file's contents in place with no undo.

    Explanation
    `Clear-Content` (alias `clc`) deletes everything inside a file while keeping the file itself — the previous contents are gone with no Recycle Bin entry. Run against logs, source, or config this silently destroys data. Safer alternatives: - Read or back up the file first (Get-Content / Copy-Item) - If you must blank it, keep a copy: Copy-Item <f> <f>.bak first
  10. dotnet-directory-delete

    High

    [System.IO.Directory]::Delete removes a directory outside the Recycle Bin.

    Explanation
    `[System.IO.Directory]::Delete` permanently removes the target directory. With a dynamic second argument the call can still recurse: PowerShell coerces any truthy value — including every non-empty string — to `$true`. Even the single-argument form deletes the directory (when empty) with no Recycle Bin entry. Safer alternatives: - Preview with the cmdlet equivalent: Remove-Item <path> -WhatIf - Move the directory to a temp/trash location instead of deleting it
  11. clear-recyclebin

    Medium

    Clear-RecycleBin permanently purges the Recycle Bin.

    Explanation
    `Clear-RecycleBin` empties the Recycle Bin, permanently destroying every file that was previously deleted into it — the usual last line of recovery for an accidental delete. With `-Force` it does so without confirmation. Safer alternatives: - Restore or review the Recycle Bin contents before purging - Leave the Recycle Bin intact so recent deletes remain recoverable

Safe patterns

Checked first. A command that matches one is never blocked by this pack.

  • whatif-preview
  • del-help