]> Cypherpunks.ru repositories - gostls13.git/commit
os, net/http: avoid escapes from os.DirFS and http.Dir on Windows
authorDamien Neil <dneil@google.com>
Thu, 10 Nov 2022 20:16:27 +0000 (12:16 -0800)
committerDamien Neil <dneil@google.com>
Tue, 6 Dec 2022 23:50:47 +0000 (23:50 +0000)
commit7dc9fcb13de7bb20b11f6a526865545cc9142c2c
tree81ee5646ad7f562a29fce73744e2f43469acbd31
parente535d6776c060da5f1947c4290159be0eb60ed6c
os, net/http: avoid escapes from os.DirFS and http.Dir on Windows

Do not permit access to Windows reserved device names (NUL, COM1, etc.)
via os.DirFS and http.Dir filesystems.

Avoid escapes from os.DirFS(`\`) on Windows. DirFS would join the
the root to the relative path with a path separator, making
os.DirFS(`\`).Open(`/foo/bar`) open the path `\\foo\bar`, which is
a UNC name. Not only does this not open the intended file, but permits
reference to any file on the system rather than only files on the
current drive.

Make os.DirFS("") invalid, with all file access failing. Previously,
a root of "" was interpreted as "/", which is surprising and probably
unintentional.

Fixes CVE-2022-41720
Fixes #56694

Change-Id: I275b5fa391e6ad7404309ea98ccc97405942e0f0
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1663834
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/455362
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Jenny Rakoczy <jenny@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/455716
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
src/go/build/deps_test.go
src/internal/safefilepath/path.go [new file with mode: 0644]
src/internal/safefilepath/path_other.go [new file with mode: 0644]
src/internal/safefilepath/path_test.go [new file with mode: 0644]
src/internal/safefilepath/path_windows.go [new file with mode: 0644]
src/net/http/fs.go
src/net/http/fs_test.go
src/os/file.go
src/os/os_test.go