Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential cross-site scripting issue #2697

Merged
merged 4 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/collector/app/handler/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package handler

import (
"fmt"
"html"
"io/ioutil"
"mime"
"net/http"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (aH *APIHandler) SaveSpan(w http.ResponseWriter, r *http.Request) {
}

if _, ok := acceptedThriftFormats[contentType]; !ok {
http.Error(w, fmt.Sprintf("Unsupported content type: %v", contentType), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("Unsupported content type: %v", html.EscapeString(contentType)), http.StatusBadRequest)
return
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/collector/app/zipkin/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package zipkin
import (
"compress/gzip"
"fmt"
"html"
"io"
"io/ioutil"
"mime"
Expand Down Expand Up @@ -100,7 +101,8 @@ func (aH *APIHandler) saveSpans(w http.ResponseWriter, r *http.Request) {
return
}
if err != nil {
http.Error(w, fmt.Sprintf(handler.UnableToReadBodyErrFormat, err), http.StatusBadRequest)
safeErr := html.EscapeString(err.Error())
http.Error(w, fmt.Sprintf(handler.UnableToReadBodyErrFormat, safeErr), http.StatusBadRequest)
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/zipkin/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ func TestJsonFormat(t *testing.T) {
},
{
payload: createSpan("bar", "", "1", "1", 156, 15145, false, annoJSON, binAnnoJSON),
expected: "Unable to process request body: strconv.ParseUint: parsing \"\": invalid syntax\n",
expected: "Unable to process request body: strconv.ParseUint: parsing "": invalid syntax\n",
statusCode: http.StatusBadRequest,
},
{
payload: createSpan("bar", "ZTA", "1", "1", 156, 15145, false, "", ""),
expected: "Unable to process request body: strconv.ParseUint: parsing \"ZTA\": invalid syntax\n",
expected: "Unable to process request body: strconv.ParseUint: parsing "ZTA": invalid syntax\n",
statusCode: http.StatusBadRequest,
},
{
Expand Down