From 5672ec0a526bfeaff6913f6126d4aa4c481bf5d6 Mon Sep 17 00:00:00 2001 From: vjeffrey Date: Mon, 19 Aug 2024 05:52:06 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20return=20error=20when=20invalid?= =?UTF-8?q?=20host=20value=20is=20provided=20for=20atlassian=20provider=20?= =?UTF-8?q?(#4567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/atlassian/connection/jira/connection.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index 573cb59b17..d268227092 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -6,6 +6,7 @@ package jira import ( "context" "errors" + "net/url" "os" v2 "github.com/ctreminiom/go-atlassian/jira/v2" @@ -26,13 +27,18 @@ type JiraConnection struct { name string } +func isValidHostValue(val string) bool { + u, err := url.Parse(val) + return err == nil && u.Scheme != "" && u.Host != "" +} + func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*JiraConnection, error) { host := conf.Options["host"] if host == "" { host = os.Getenv("ATLASSIAN_HOST") } - if host == "" { - return nil, errors.New("you must provide an Atlassian host e.g. via ATLASSIAN_HOST env or via the --host flag") + if host == "" || !isValidHostValue(host) { + return nil, errors.New("you must provide an Atlassian host e.g. via ATLASSIAN_HOST env or via the --host flag. Host must be prefixed with https://") } user := conf.Options["user"]