Skip to content

Commit ff40fec

Browse files
committed
remove url/checksum arguments from /v2/pkgs/tools/installed endpoint
This is a security risk. They were overriding packager,toolname,version from package index.
1 parent b812e33 commit ff40fec

File tree

2 files changed

+7
-62
lines changed

2 files changed

+7
-62
lines changed

v2/pkgs/tools.go

+7-13
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ func (c *Tools) Installed(ctx context.Context) (tools.ToolCollection, error) {
135135
// Install crawles the Index folder, downloads the specified tool, extracts the archive in the Tools Folder.
136136
// It checks for the Signature specified in the package index.
137137
func (c *Tools) Install(ctx context.Context, payload *tools.ToolPayload) (*tools.Operation, error) {
138-
path := filepath.Join(payload.Packager, payload.Name, payload.Version)
139-
140-
if payload.URL != nil {
141-
return c.install(ctx, path, *payload.URL, *payload.Checksum)
142-
}
143-
144138
list, err := c.Indexes.List(ctx)
145139
if err != nil {
146140
return nil, err
@@ -160,10 +154,7 @@ func (c *Tools) Install(ctx context.Context, payload *tools.ToolPayload) (*tools
160154
for _, tool := range packager.Tools {
161155
if tool.Name == payload.Name &&
162156
tool.Version == payload.Version {
163-
164-
i := findSystem(tool)
165-
166-
return c.install(ctx, path, tool.Systems[i].URL, tool.Systems[i].Checksum)
157+
return c.install(ctx, payload.Packager, tool)
167158
}
168159
}
169160
}
@@ -174,9 +165,12 @@ func (c *Tools) Install(ctx context.Context, payload *tools.ToolPayload) (*tools
174165
payload.Packager, payload.Name, payload.Version))
175166
}
176167

177-
func (c *Tools) install(ctx context.Context, path, url, checksum string) (*tools.Operation, error) {
168+
func (c *Tools) install(ctx context.Context, packager string, tool Tool) (*tools.Operation, error) {
169+
i := findSystem(tool)
170+
path := filepath.Join(packager, tool.Name, tool.Version)
171+
178172
// Download
179-
res, err := http.Get(url)
173+
res, err := http.Get(tool.Systems[i].URL)
180174
if err != nil {
181175
return nil, err
182176
}
@@ -201,7 +195,7 @@ func (c *Tools) install(ctx context.Context, path, url, checksum string) (*tools
201195
sum := sha256.Sum256(buffer.Bytes())
202196
sumString := "SHA-256:" + hex.EncodeToString(sum[:sha256.Size])
203197

204-
if sumString != checksum {
198+
if sumString != tool.Systems[i].Checksum {
205199
os.RemoveAll(path)
206200
return nil, errors.New("checksum doesn't match")
207201
}

v2/pkgs/tools_test.go

-49
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"net/http"
2222
"net/http/httptest"
2323
"os"
24-
"runtime"
2524
"strings"
2625
"testing"
2726

@@ -131,52 +130,4 @@ func TestTools(t *testing.T) {
131130
if len(installed) != 0 {
132131
t.Fatalf("expected %d == %d (%s)", len(installed), 0, "len(installed)")
133132
}
134-
135-
// Install a tool by specifying url and checksum
136-
_, err = service.Install(ctx, &tools.ToolPayload{
137-
Packager: "arduino",
138-
Name: "avrdude",
139-
Version: "6.0.1-arduino2",
140-
URL: strpoint(url()),
141-
Checksum: strpoint(checksum()),
142-
})
143-
if err != nil {
144-
t.Fatal(err)
145-
}
146-
147-
installed, err = service.Installed(ctx)
148-
if err != nil {
149-
t.Fatal(err)
150-
}
151-
if len(installed) != 1 {
152-
t.Fatalf("expected %d == %d (%s)", len(installed), 1, "len(installed)")
153-
}
154-
}
155-
156-
func strpoint(s string) *string {
157-
return &s
158-
}
159-
160-
func url() string {
161-
urls := map[string]string{
162-
"linuxamd64": "https://downloads.arduino.cc/tools/avrdude-6.0.1-arduino2-x86_64-pc-linux-gnu.tar.bz2",
163-
"linux386": "https://downloads.arduino.cc/tools/avrdude-6.0.1-arduino2-i686-pc-linux-gnu.tar.bz2",
164-
"darwinamd64": "https://downloads.arduino.cc/tools/avrdude-6.0.1-arduino2-i386-apple-darwin11.tar.bz2",
165-
"windows386": "https://downloads.arduino.cc/tools/avrdude-6.0.1-arduino2-i686-mingw32.zip",
166-
"windowsamd64": "https://downloads.arduino.cc/tools/avrdude-6.0.1-arduino2-i686-mingw32.zip",
167-
}
168-
169-
return urls[runtime.GOOS+runtime.GOARCH]
170-
}
171-
172-
func checksum() string {
173-
checksums := map[string]string{
174-
"linuxamd64": "SHA-256:2489004d1d98177eaf69796760451f89224007c98b39ebb5577a9a34f51425f1",
175-
"linux386": "SHA-256:6f633dd6270ad0d9ef19507bcbf8697b414a15208e4c0f71deec25ef89cdef3f",
176-
"darwinamd64": "SHA-256:71117cce0096dad6c091e2c34eb0b9a3386d3aec7d863d2da733d9e5eac3a6b1",
177-
"windows386": "SHA-256:6c5483800ba753c80893607e30cade8ab77b182808fcc5ea15fa3019c63d76ae",
178-
"windowsamd64": "SHA-256:6c5483800ba753c80893607e30cade8ab77b182808fcc5ea15fa3019c63d76ae",
179-
}
180-
return checksums[runtime.GOOS+runtime.GOARCH]
181-
182133
}

0 commit comments

Comments
 (0)