Skip to content

Commit 50abf73

Browse files
committed
fix(gateway): panic on path without enough components
1 parent 322c51e commit 50abf73

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

gateway/gateway_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ func TestGatewayGet(t *testing.T) {
250250
text string
251251
}{
252252
{"127.0.0.1:8080", "/", http.StatusNotFound, "404 page not found\n"},
253+
{"127.0.0.1:8080", "/ipfs", http.StatusBadRequest, "invalid path \"/ipfs/\": not enough path components\n"},
254+
{"127.0.0.1:8080", "/ipns", http.StatusBadRequest, "invalid path \"/ipns/\": not enough path components\n"},
253255
{"127.0.0.1:8080", "/" + k.Cid().String(), http.StatusNotFound, "404 page not found\n"},
254-
{"127.0.0.1:8080", "/ipfs/this-is-not-a-cid", http.StatusBadRequest, "failed to resolve /ipfs/this-is-not-a-cid: invalid path \"/ipfs/this-is-not-a-cid\": invalid CID: invalid cid: illegal base32 data at input byte 3\n"},
256+
{"127.0.0.1:8080", "/ipfs/this-is-not-a-cid", http.StatusBadRequest, "invalid path \"/ipfs/this-is-not-a-cid\": invalid CID: invalid cid: illegal base32 data at input byte 3\n"},
255257
{"127.0.0.1:8080", k.String(), http.StatusOK, "fnord"},
256258
{"127.0.0.1:8080", "/ipns/nxdomain.example.com", http.StatusInternalServerError, "failed to resolve /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"},
257259
{"127.0.0.1:8080", "/ipns/%0D%0A%0D%0Ahello", http.StatusInternalServerError, "failed to resolve /ipns/\\r\\n\\r\\nhello: " + namesys.ErrResolveFailed.Error() + "\n"},

gateway/handler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ func (i *handler) getOrHeadHandler(w http.ResponseWriter, r *http.Request) {
216216
return
217217
}
218218

219+
if err := contentPath.IsValid(); err != nil {
220+
webError(w, err, http.StatusBadRequest)
221+
return
222+
}
223+
219224
// Detect when explicit Accept header or ?format parameter are present
220225
responseFormat, formatParams, err := customResponseFormat(r)
221226
if err != nil {

0 commit comments

Comments
 (0)