Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Safely reject invalid-length span and trace ids (#1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopat authored Apr 2, 2020
1 parent 84d38db commit d3cf45e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugin/ochttp/propagation/b3/b3.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func ParseTraceID(tid string) (trace.TraceID, bool) {
return trace.TraceID{}, false
}
b, err := hex.DecodeString(tid)
if err != nil {
if err != nil || len(b) > 16 {
return trace.TraceID{}, false
}
var traceID trace.TraceID
Expand All @@ -90,7 +90,7 @@ func ParseSpanID(sid string) (spanID trace.SpanID, ok bool) {
return trace.SpanID{}, false
}
b, err := hex.DecodeString(sid)
if err != nil {
if err != nil || len(b) > 8 {
return trace.SpanID{}, false
}
start := 8 - len(b)
Expand Down
22 changes: 22 additions & 0 deletions plugin/ochttp/propagation/b3/b3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ func TestHTTPFormat_FromRequest(t *testing.T) {
wantSc: trace.SpanContext{},
wantOk: false,
},
{
name: "invalid >128-bit trace ID + 64-bit span ID; no sampling header",
makeReq: func() *http.Request {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req.Header.Set(TraceIDHeader, "0020000000000001002000000000000111")
req.Header.Set(SpanIDHeader, "0020000000000001")
return req
},
wantSc: trace.SpanContext{},
wantOk: false,
},
{
name: "128-bit trace ID; invalid span ID; no sampling header",
makeReq: func() *http.Request {
Expand All @@ -114,6 +125,17 @@ func TestHTTPFormat_FromRequest(t *testing.T) {
wantSc: trace.SpanContext{},
wantOk: false,
},
{
name: "128-bit trace ID; invalid >64 bit span ID; no sampling header",
makeReq: func() *http.Request {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req.Header.Set(TraceIDHeader, "463ac35c9f6413ad48485a3953bb6124")
req.Header.Set(SpanIDHeader, "002000000000000111")
return req
},
wantSc: trace.SpanContext{},
wantOk: false,
},
{
name: "128-bit trace ID + 64-bit span ID; sampled=true",
makeReq: func() *http.Request {
Expand Down

0 comments on commit d3cf45e

Please sign in to comment.