From abcbdd9a2e5c563fa5d7d3a62625151cd86e892b Mon Sep 17 00:00:00 2001 From: Sascha <1823032+derSascha@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:43:39 +0200 Subject: [PATCH] Fix user-agent parsing of security releases (#1119) Co-authored-by: Sascha Wolke --- backend/useragent/user_agent.go | 2 +- backend/useragent/user_agent_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/useragent/user_agent.go b/backend/useragent/user_agent.go index 3056fe626..55f59dcd9 100644 --- a/backend/useragent/user_agent.go +++ b/backend/useragent/user_agent.go @@ -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") ) diff --git a/backend/useragent/user_agent_test.go b/backend/useragent/user_agent_test.go index fb47a82b0..ea97df3e7 100644 --- a/backend/useragent/user_agent_test.go +++ b/backend/useragent/user_agent_test.go @@ -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)",