Skip to content

Commit 7a00f97

Browse files
neildgopherbot
authored andcommitted
archive/tar, archive/zip: disable ErrInsecurePath by default
This change is being made late in the release cycle. Disable it by default. Insecure path checks may be enabled by setting GODEBUG=tarinsecurepath=0 or GODEBUG=zipinsecurepath=0. We can enable this by default in Go 1.21 after publicizing the change more broadly and giving users a chance to adapt to the change. For #55356. Change-Id: I549298b3c85d6c8c7fd607c41de1073083f79b1d Reviewed-on: https://go-review.googlesource.com/c/go/+/452616 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
1 parent 28911b2 commit 7a00f97

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

doc/go1.20.html

+16-24
Original file line numberDiff line numberDiff line change
@@ -372,37 +372,29 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
372372
<dl id="archive/tar"><dt><a href="/pkg/archive/tar/">archive/tar</a></dt>
373373
<dd>
374374
<p><!-- https://go.dev/issue/55356 -->
375-
<code>(*Reader).Next</code> will now return the error <code>ErrInsecurePath</code>
376-
when opening an archive which contains file names that are absolute,
377-
refer to a location outside the current directory, contain invalid
378-
characters, or (on Windows) are reserved names such as <code>NUL</code>.
379-
</p>
380-
<p>
381-
Programs that want to operate on archives containing insecure file names may
382-
ignore this error.
383-
</p>
384-
<p>
385-
Insecure tar file name checks may be entirely disabled by setting the
386-
<code>GODEBUG=tarinsecurepath=1</code> environment variable.
375+
When the <code>GODEBUG=tarinsecurepath=0</code> environment variable
376+
is set, <code>(*Reader).Next</code> will return the error
377+
<code>ErrInsecurePath</code> when opening an archive which contains
378+
file names that are absolute, refer to a location outside the current
379+
directory, contain invalid characters, or (on Windows) are reserved
380+
names such as <code>NUL</code>. Programs that perform their own
381+
name sanitization can ignore this error. This behavior will be made
382+
the default in a future version of Go.
387383
</p>
388384
</dd>
389385
</dl><!-- archive/tar -->
390386

391387
<dl id="archive/zip"><dt><a href="/pkg/archive/zip/">archive/zip</a></dt>
392388
<dd>
393389
<p><!-- https://go.dev/issue/55356 -->
394-
<code>NewReader</code> will now return the error <code>ErrInsecurePath</code>
395-
when opening an archive which contains file names that are absolute,
396-
refer to a location outside the current directory, contain invalid
397-
characters, or (on Windows) are reserved names such as <code>NUL</code>.
398-
</p>
399-
<p>
400-
Programs that want to operate on archives containing insecure file names may
401-
ignore this error.
402-
</p>
403-
<p>
404-
Insecure zip file name checks may be entirely disabled by setting the
405-
<code>GODEBUG=zipinsecurepath=1</code> environment variable.
390+
When the <code>GODEBUG=zipinsecurepath=0</code> environment variable
391+
is set, <code>NewReader</code> will return the error
392+
<code>ErrInsecurePath</code> when opening an archive which contains
393+
file names that are absolute, refer to a location outside the current
394+
irectory, contain invalid characters, or (on Windows) are reserved
395+
names such as <code>NUL</code>. Programs that perform their own
396+
name sanitization can ignore this error. This behavior will be made
397+
the default in a future version of Go.
406398
</p>
407399
<p><!-- CL 449955 -->
408400
Reading from a directory file that contains file data will now return an error.

src/archive/tar/reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (tr *Reader) Next() (*Header, error) {
6060
}
6161
hdr, err := tr.next()
6262
tr.err = err
63-
if err == nil && tarinsecurepath.Value() != "1" && !filepath.IsLocal(hdr.Name) {
63+
if err == nil && tarinsecurepath.Value() == "0" && !filepath.IsLocal(hdr.Name) {
6464
err = ErrInsecurePath
6565
}
6666
return hdr, err

src/archive/zip/reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func NewReader(r io.ReaderAt, size int64) (*Reader, error) {
111111
// Zip permits an empty file name field.
112112
continue
113113
}
114-
if zipinsecurepath.Value() == "1" {
114+
if zipinsecurepath.Value() != "0" {
115115
continue
116116
}
117117
// The zip specification states that names must use forward slashes,

0 commit comments

Comments
 (0)