Skip to content

Commit 97cff15

Browse files
committed
docs: more security info
1 parent 2b72abc commit 97cff15

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,66 @@ If you are familiar with how tar works, most of this will hopefully be
77
straightforward for you. If not, then hopefully this module can teach
88
you useful unix skills that may come in handy someday :)
99

10+
## Security Information
11+
12+
Significant efforts have been taken to harden this library
13+
against a wide variety of filesystem based attacks, especially as
14+
it is used to unpack packages that are published by unknown
15+
agents to [the npm registry](https://npmjs.com/).
16+
17+
A brief overview of some of the hardening that has gone into this
18+
implementation. (Note that most of these are disabled if
19+
`preservePaths: true` is set in the options.)
20+
21+
- Paths that attempt to walk up outside of the extraction target
22+
are ignored, and a warning is raised.
23+
- `Link` and `SymbolicLink` entries are not allowed to target
24+
locations outside of the extraction folder.
25+
- Extraction is not allowed through a symbolic link that appears
26+
within the extraction target.
27+
- Absolute paths are turned into relative paths underneath the
28+
extraction target.
29+
- Character Device, Block Device, and FIFO entries are never
30+
extracted.
31+
- File and directory ownership is not mutated unless `forceChown`
32+
is set, or the extraction is run as root.
33+
- File and directory modes in the archive are ignored, unless
34+
the `chmod: true` option is set.
35+
36+
**However**, care must still be taken when dealing with data from
37+
unknown sources, especially when extracting files, with this or
38+
any library, no matter how hardened it may be.
39+
40+
1. **NEVER** extract tarball data into a folder that could be
41+
potentially controlled by an unknown actor. A clever attacker
42+
can swap out the target of an extracted file with a symbolic
43+
link to some location of their choosing, resulting in writing
44+
files outside the target folder. There is no reasonable way to
45+
harden against this category of attack, and security reports
46+
about it will be closed. TOCTOU exposure is unavoidable when
47+
creating files based on entries in an archive file.
48+
2. If you are unpacking tarballs that may come from an unknown
49+
source, it is **highly recommended** that you use a filter
50+
function that rejects all hardlinks and symbolic links. Link
51+
files are historically the root of nearly every file
52+
extraction vulnerability. (npm filters links out of package
53+
artifacts for this reason.)
54+
3. If you are extracting tarballs that are compressed (eg, with
55+
gzip, brotli, or zstd), then it is a very good idea to also
56+
filter out any files that are excessively large. Even if you
57+
are restricting the size of the archive file itself, an
58+
excessively large file of repetitive data can compress down
59+
very small, and extract to take up a lot of disk space.
60+
4. **Stay up to date.** Old versions of tar are not maintained or
61+
tested for newly discovered security advisories, and should be
62+
assumed to contain every known security vulnerability, and
63+
many that are unknown.
64+
65+
If you find a security vulnerability in node-tar, where it is not
66+
properly enforcing the intended security protections, then please
67+
report it using the GitHub Security Advisories system, where it
68+
will be triaged and corrected if possible.
69+
1070
## Background
1171

1272
A "tar file" or "tarball" is an archive of file system entries

0 commit comments

Comments
 (0)