Skip to content
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
7 changes: 6 additions & 1 deletion internal/topsrv/nginx/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,13 @@ func (c *LogCollector) recordLine(p *ParsedLine) { //nolint:gocognit,nestif

func normalizeURI(request string) string {
parts := strings.SplitN(request, " ", 3)
// A well-formed $request is "METHOD URI HTTP/x.y" — at least one space.
// Binary handshakes (TLS ClientHello hitting an HTTP port, SSH probes, etc.)
// arrive as a single space-less blob; without this guard they bypassed
// normalizePath entirely and pushed raw bytes into the uri label, blowing
// past Prometheus' 256-byte cap.
if len(parts) < 2 {
return request
return invalidMarker
}
path := parts[1]
if i := strings.IndexByte(path, '?'); i >= 0 {
Expand Down
9 changes: 8 additions & 1 deletion internal/topsrv/nginx/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,16 @@ func TestNormalizeURI(t *testing.T) {
{"GET /people/tommy-brewster-6401345/ HTTP/1.1", "/people/:slug/"},
// hex hashes in media URLs — truncated by depth
{"GET /media/roles/e/ef/d763d0a80cfe86a9fcc378db4d5935bf.jpg HTTP/1.1", "/media/roles/:rest"},
// Garbage $request with no spaces (TLS handshake hitting plain HTTP port,
// raw SSH probe, etc.) must NOT bypass normalization and pollute the uri
// label — pre-0.1.3 it was returned verbatim and blew past the 256-byte
// Prometheus label cap downstream.
{"\x06\x00\x00\x003_xgDcA\x00\x00\x00\x00\x00\x00\x00\xB0(\xC7\xEF~", invalidMarker},
{"", invalidMarker},
{"GET", invalidMarker},
}
for _, tt := range tests {
assert.Equal(t, tt.want, normalizeURI(tt.request), tt.request)
assert.Equal(t, tt.want, normalizeURI(tt.request), "%q", tt.request)
}
}

Expand Down
Loading