Package Exports
- secure-rm
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (secure-rm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Completely erases files by making recovery impossible.
❓ Why
When you delete a file using the rm command or fs.unlink in node, it only remove direct pointers to the data disk sectors and make the data recovery possible with common software tools.
Permanent data erasure goes beyond basic file deletion commands, which:
- Allow for selection of a specific standard, based on unique needs, and
- Verify the overwriting method has been successful and removed data across the entire device.
📦 Install
You can use this package in two different ways, the npm module version:
npm install secure-rm --saveOr the command-line version:
npm install secure-rm -gSecure-rm will retry 3 times if an error occur to ensure the task succeeded.
🚀 Getting started
If you want your application to delete specific files with a pass of cryptographically strong pseudo-random data, use one of these code snippets:
Callback version
const srm = require('secure-rm')
srm('./folder/*.js', (err, path) => {
if (err) throw err
console.log(`Successfully removed ${path} !`)
})Promise version
const srm = require('secure-rm')
srm('./folder/*.js')
.then((path) => console.log(`Successfully removed ${path} !`))
.catch((err) => {throw err})Command line version
If you want to delete files on the fly, just use the command line tool:
secure-rm ./folder/*.js📚 Usage
npm module
rm(path[, options] [, callback])
path<String> :- an absolute path (e.g.
D:\data,/d/data); - a relative path (e.g.
./data/file.js,../../data); - a glob pattern (e.g.
./*.js,./**/*,@(pattern|pat*|pat?erN)).
- an absolute path (e.g.
options<Object> (optional) :method<String> : ID of the method (default: 'secure');customMethod<Function> : your own method to remove a file (if specified, priority overmethod);maxBusyTries<Number> : number of retries if an error occur;disableGlob<Boolean> : allow or not file globbing (default: true).
callback<Function> (if missing, return a promise):- returns
err<Error> when finished.
- returns
Examples:
const options = {
method: 'gutmann',
maxBusyTries: 5,
disableGlob: true
}
srm('./data/file*.js', options, (err, path) => {
if (err) throw err
console.log(`Successfully removed ${path} !`)
})const options = {
customMethod: function (file, callback) {
srm.write.init(file)
.then(({ fileSize, file }) => srm.write.zeroes(file, fileSize))
.then(({ fileSize, file }) => srm.write.ones(file, fileSize))
.then(({ fileSize, file }) => srm.write.random(file, fileSize))
.then(({ file }) => srm.write.unlink(file))
.then(() => callback())
.catch((err) => callback(err))
}
srm('./*', options)
.then((path) => console.log(`Successfully removed ${path} !`))
.catch((err) => {throw err})If you want to make your own cutom method, see write.js file for more details.
Events
When running, secure-rm emits events to let you know the progression of the deletion.
You can indeed intercept error and ending events for each file.
srm.event.on('start', (file) => console.log('Starting ' + file))
srm.event.on('unlink', (file) => console.log('Unlinking ' + file))
srm.event.on('done', (file) => console.log('Done ' + file))
srm.event.on('info', (file, info) => console.log('Info ' + info + file))
srm.event.on('warn', (file, err) => console.log('Warning ' + err + file))
srm.event.on('error', (file, err) => console.log('Error ' + err + file))Command line tool
secure-rm <PATHS> [OPTIONS]PATHS:- one or multiple paths (e.g.
D:\data /d/data ./data/file.js ../../data) - supports glob patterns (e.g.
./*.js ./**/* @(pattern|pat*|pat?erN))
- one or multiple paths (e.g.
OPTIONS(flags):-f, --force: avoid checks if you want to use it in a shell or bash file;-h, --help: show CLI help, see below;-m, --method: numerical ID of the method, default is 0. See them detailed below;-r, --retries: max retries if an error occur;-t, --table: show the methods table. See them detailed below;-v, --version: show CLI version;--no-globbing: disable file globbing.
Example:
secure-rm ./folder/*.js ./garbage ./file.js -m 6 -fYou can invoke the built-in help with secure-rm -h:
CLI help:
USAGE
$ secure-rm PATH
OPTIONS
-f, --force avoid checks
-h, --help show CLI help
-m, --method=method [default: secure] select the erasure method
-r, --retries=retries max retries if error
-t, --table show the methods table
-v, --version show CLI version
--[no-]globbing allow or not file globbing
DESCRIPTION
Completely erases files by making recovery impossible.
For extra documentation, go to https://www.npmjs.com/package/secure-rmMethods
| ID | Name | Passes | Description |
|---|---|---|---|
| randomData | Pseudorandom data | 1 | Also kwown as "Australian Information Security Manual Standard ISM 6.2.92" and "New Zealand Information and Communications Technology Standard NZSIT 402" Your data is overwritten with cryptographically strong pseudo-random data. (The data is indistinguishable from random noise.) |
| randomByte | Pseudorandom byte | 1 | Overwriting with a random byte. |
| zeroes | Zeroes | 1 | Overwriting with zeroes. |
| ones | Ones | 1 | Overwriting with ones. |
| secure | Secure-rm method | 3 | Pass 1: Overwriting with random data; Pass 2: Renaming the file with random data; Pass 3: Truncating between 25% and 75% of the file. |
| GOST_R50739-95 | Russian State Standard GOST R 50739-95 | 2 | Pass 1: Overwriting with zeroes; Pass 2: Overwriting with random data. |
| HMG_IS5 | British HMG Infosec Standard 5 | 3 | Also known as "Air Force System Security Instructions AFSSI-5020", "Standard of the American Department of Defense (DoD 5220.22 M)" "National Computer Security Center NCSC-TG-025 Standard" and "Navy Staff Office Publication NAVSO P-5239-26" Pass 1: Overwriting with zeroes; Pass 2: Overwriting with ones; Pass 3: Overwriting with random data as well as verifying the writing of this data. |
| AR380-19 | US Army AR380-19 | 3 | Pass 1: Overwriting with random data; Pass 2: Overwriting with a random byte; Pass 3: Overwriting with the complement of the 2nd pass, and verifying the writing. |
| VSITR | Standard of the Federal Office for Information Security (BSI-VSITR) | 7 | Also known as "Royal Canadian Mounted Police TSSIT OPS-II" Pass 1: Overwriting with zeroes; Pass 2: Overwriting with ones; Pass 3-6: Same as 1-2; Pass 7: Overwriting with a random data as well as review the writing of this character. |
| schneier | Bruce Schneier Algorithm | 7 | Pass 1: Overwriting with zeros; Pass 2: Overwriting with ones; Pass 3-7: Overwriting with random data. |
| pfitzner | Pfitzner Method | 33 | Pass 1-33: Overwriting with random data. |
| gutmann | Peter Gutmann Algorithm | 35 | Pass 1-4: Overwriting with random data; Pass 5: Overwriting with 0x55; Pass 6: Overwriting with 0xAA; Pass 7-9: Overwriting with 0x92 0x49 0x24, then cycling through the bytes; Pass 10-25: Overwriting with 0x00, incremented by 1 at each pass, until 0xFF; Pass 26-28: Same as 7-9; Pass 29-31: Overwriting with 0x6D 0xB6 0xDB, then cycling through the bytes; Pass 32-35: Overwriting with random data. |
Note: Node ensures that the file is correctly written, checking the writing in these algorithms is unnecessary.
🚩 Troubleshooting / Common issues
Should works on OS X, Linux, and Windows.
File systems
secure-rm will only work on file systems that overwrite blocks in place.
List of known file systems that will not work:
- ext3
- ext4
- AthFS – AtheOS
- OneFS
- ssd's at large
- reiserfs
- ...
- especially on the vast majority of journaled file systems.
"WARN Too many open files, cannot ...:"
Don't worry, you've just submited too much file for Node. The tool will retry 3 times to ensure the task succeeded. While you don't get an error, the tool can handle this issue.
If you really need to delete millions of file in one time, split the task (e.g. ./your_folder/a* then ./your_folder/b* ...).
Using Windows:
Be sure to use secure-rm ".\path\file" with doublequotes since back-slashes will always be interpreted as escape characters, not path separators.
Another solution is to double the back-slashes like: secure-rm .\\path\\file
Or if you can, use forward slashes!
📜 Changelog
See the changelog or releases.
📌 TODO
- Release of 1.0.0 (stable API)
- Implement more tests
- TypeScript
- Support of 64bit files
🏗 Contributing
Licensing
This project is under MIT License.