Skip to content

Commit

Permalink
Fix user-agent parsing of security releases (#1119)
Browse files Browse the repository at this point in the history
Co-authored-by: Sascha Wolke <dersascha@users.noreply.github.com>
  • Loading branch information
derSascha and derSascha authored Oct 21, 2024
1 parent 4600bc1 commit abcbdd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/useragent/user_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var (
userAgentRegex = regexp.MustCompile(`^Grafana/([0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?) \(([a-zA-Z0-9]+); ([a-zA-Z0-9]+)\)$`)
userAgentRegex = regexp.MustCompile(`^Grafana/([0-9]+\.[0-9]+\.[0-9]+(?:[^\s]+)?) \(([a-zA-Z0-9]+); ([a-zA-Z0-9]+)\)$`)
errInvalidFormat = errors.New("invalid user agent format")
)

Expand Down
8 changes: 8 additions & 0 deletions backend/useragent/user_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func TestParse(t *testing.T) {
os: "darwin",
arch: "amd64",
},
}, {
name: "valid (with security suffix)",
userAgent: "Grafana/11.2.2+security-01 (darwin; amd64)",
expected: &UserAgent{
grafanaVersion: "11.2.2+security-01",
os: "darwin",
arch: "amd64",
},
},
{
name: "invalid (missing os + arch)",
Expand Down

0 comments on commit abcbdd9

Please sign in to comment.