Skip to content

Commit

Permalink
Base32-encode etag values (#1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr authored Jan 8, 2025
1 parent 04e98e5 commit 995ee5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/apk/apk/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package apk

import (
"context"
"encoding/base32"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -331,6 +332,11 @@ func etagFromResponse(resp *http.Response) (string, bool) {
}
// When we get etags, they appear to be quoted.
etag := strings.Trim(remoteEtag[0], `"`)

// To ensure these things are safe filenames, base32 encode them.
// (Avoiding base64 due to case sensitive filesystems.)
etag = base32.StdEncoding.EncodeToString([]byte(etag))

return etag, etag != ""
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/apk/apk/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package apk

import (
"context"
"encoding/base32"
"fmt"
"io/fs"
"net/http"
Expand Down Expand Up @@ -192,7 +193,7 @@ func TestGetRepositoryIndexes(t *testing.T) {
require.NoErrorf(t, err, "unable to get indexes")
require.Greater(t, len(indexes), 0, "no indexes found")
// check that the contents are the same
index1, err := os.ReadFile(filepath.Join(repoDir, "APKINDEX", "an-etag.tar.gz"))
index1, err := os.ReadFile(filepath.Join(repoDir, "APKINDEX", base32.StdEncoding.EncodeToString([]byte("an-etag"))+".tar.gz"))
require.NoError(t, err, "unable to read cache index file")
index2, err := os.ReadFile(filepath.Join(testPrimaryPkgDir, indexFilename))
require.NoError(t, err, "unable to read previous index file")
Expand Down

0 comments on commit 995ee5a

Please sign in to comment.