Skip to content

Commit 793ad66

Browse files
acme/autocert: properly clean DirCache paths
Don't assume the path passed into the DirCache methods is absolute, and clean it before further operating on it. Put and Delete are not attacker controlled, but clean them anyway. Fixes #53082 Fixes CVE-2022-30636 Change-Id: I755f525a737da60ccba07ebce4d41cc8faebfcca Reviewed-on: https://go-review.googlesource.com/c/crypto/+/408694 Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 6f7dac9 commit 793ad66

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

acme/autocert/cache.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type DirCache string
4141

4242
// Get reads a certificate data from the specified file name.
4343
func (d DirCache) Get(ctx context.Context, name string) ([]byte, error) {
44-
name = filepath.Join(string(d), name)
44+
name = filepath.Join(string(d), filepath.Clean("/"+name))
4545
var (
4646
data []byte
4747
err error
@@ -82,7 +82,7 @@ func (d DirCache) Put(ctx context.Context, name string, data []byte) error {
8282
case <-ctx.Done():
8383
// Don't overwrite the file if the context was canceled.
8484
default:
85-
newName := filepath.Join(string(d), name)
85+
newName := filepath.Join(string(d), filepath.Clean("/"+name))
8686
err = os.Rename(tmp, newName)
8787
}
8888
}()
@@ -96,7 +96,7 @@ func (d DirCache) Put(ctx context.Context, name string, data []byte) error {
9696

9797
// Delete removes the specified file name.
9898
func (d DirCache) Delete(ctx context.Context, name string) error {
99-
name = filepath.Join(string(d), name)
99+
name = filepath.Join(string(d), filepath.Clean("/"+name))
100100
var (
101101
err error
102102
done = make(chan struct{})

0 commit comments

Comments
 (0)