Habr•November 3, 2026•🇷🇺Translated from Russian

How to Avoid Becoming the Hero of 'My Program Deleted 800 GB': Safe Recursive Deletion in Bash and Python

A recent article on Habr explores how seemingly simple recursive deletion code can lead to catastrophic data loss, using the example of Telegram Desktop accidentally cleaning a custom folder and removing around 800 GB of projects and programs.

The author notes that many projects contain cleanup routines for caches, temporary files, or build artifacts that receive minimal review and later fail when variables are empty or unexpected symlinks appear.

Classic pitfalls with empty variables

Well-known incidents include the 2015 Steam Linux client bug where an unset STEAMROOT variable expanded rm -rf "$STEAMROOT/"* into rm -rf "/"*, and the 2011 Bumblebee installer that contained an extra space turning one path into rm -rf /usr /lib/nvidia-current/xorg/xorg.

Hardened Bash practices

The recommended Bash template begins with set -euo pipefail, followed by explicit checks such as ${CACHE_DIR:?CACHE_DIR not set}, double quotes around paths, and the -- separator. Additional safeguards include verifying the target is a real directory (not a symlink), resolving it with realpath, and rejecting paths that match forbidden roots like /, /home, or /usr.

The final deletion step uses find with -mindepth 1 and --one-file-system to avoid crossing mount points while still removing hidden files.

Safe Python implementation

In Python, the article warns that shutil.rmtree has identical risks and introduces a safe_rmtree function that rejects empty paths, symlinks, and targets outside a pre-defined allowed root. It relies on Path.resolve(strict=True) and is_relative_to rather than string prefix checks, and refuses to run on platforms where shutil.rmtree.avoids_symlink_attacks is False.

A dry-run mode and explicit exception handling for read-only files on Windows are also provided.

Practical recommendations

Additional advice includes using tempfile.TemporaryDirectory, leaving marker files in shared cache locations, moving files to a trash directory before final deletion, and always logging operations. The author stresses that deletion code should be reviewed as carefully as any security-sensitive routine because a single unchecked line can destroy all user data.

Related articles

Habr•Other

Rostelecom Refactors InfoSec Careers: Matching Employee Skills to Evolving Business Priorities

Rostelecom's information security block developed a systematic approach to reassess employee expertise and redirect talent to new roles when business structures change rapidly. In one case, an architect hired for a specific team was reassigned after the unit was disbanded, initially moving to a similar position that did not fully align with his broader competencies. HR-business partner Olga Lapshina examined the specialist's full background, including prior work in audits, methodology development, regulatory documentation, university teaching, and scientific research, plus strong mentoring abilities with younger staff. These skills matched the needs of the methodology department, leading to a transfer supported by an individual development plan and a mentor via the internal Tochka Rosta platform. Within two months the employee contributed improvements that accelerated preliminary InfoSec audits by 30 percent and risk assessments by 20 percent while expanding threat scenario coverage by 10 percent. The initiative demonstrates Rostelecom's emphasis on horizontal career movement and retention of experienced professionals through structured career tracks.

AntiMalware•Other

Hackers tamper with refrigeration units in European supermarkets, setting temperatures to +50 °C

Attackers gained unauthorized access to refrigeration and freezer control systems in supermarkets across several European countries, including Sweden, Belgium, Luxembourg, and Estonia. In multiple locations they altered temperature settings to +50 °C, risking widespread spoilage of perishable goods. The incidents primarily affected older, unpatched Danfoss controllers that had been connected to networks for remote maintenance. Estonian manufacturer Kitman Coldtech reported that one attack on a legacy Danfoss system was detected and stopped within approximately ten minutes, preventing any damage. Similar intrusions were confirmed by Swedish chains ICA and Coop, following earlier incidents in French supermarkets in October that resulted in product losses. Experts note that legacy industrial controllers remain attractive targets because they are often left exposed once placed online for convenience.

Habr•Other

AmneziaWG Container for MikroTik Routers Delivers Top Performance Six Months After Launch

A developer released an AmneziaWG container for MikroTik devices in February 2026 and has since added major improvements in speed, protocol support, and stability. The lightweight container leverages the router's native WireGuard implementation for cryptography while handling AmneziaWG obfuscation in software. Performance now reaches 250-350 Mbit/s on models such as Hap Ax3 and RB5009B after switching to C code and increasing buffer sizes with RouterOS 7.24. New features include server mode for connecting multiple MikroTik devices, random port hopping, IPv6 support, dynamic DNS, and offline configuration. The project survived an early GitHub ban caused by test scripts and has grown to over 370 stars while remaining fully offline and privacy-focused.

Habr•Other

Building Resilient DoH Failover on MikroTik RouterOS to Handle Unreachable Cloudflare Responses

A network administrator encountered a persistent issue in a branch office where pages like Tailwind CSS CDN failed to load despite valid DNS responses from Cloudflare DoH. The problem stemmed from unreachable IP addresses such as 8.6.112.0 and 8.47.69.0 returned by the resolver, which RouterOS treated as healthy because it only checked for valid IP types rather than route reachability. RouterOS supports only a single active DoH upstream via the use-doh-server parameter, requiring custom scripting for failover between multiple endpoints like Cloudflare and dns.google. The solution involved static DNS entries for bootstrap addresses, certificate trust anchors including SSL.com TLS ECC Root CA 2022, and a health monitor script that probes using DNS-JSON API calls instead of switching the resolver directly. Multiple iterations addressed issues like cache-based false positives, plain DNS fallback risks from provider spoofing, and clock validation to prevent certificate failures. The final implementation uses thresholds for failure and recovery to avoid flapping and ensures post-switch verification before committing to a backup endpoint.