Skip to content

Commit 4d2a123

Browse files
fix: Fixed out-of-scope parsing for scope deffinitions containing a scheme
fixes #4
1 parent 1c1b61b commit 4d2a123

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,13 +1012,28 @@ func parseOutOfScopes(targetURL *url.URL, outOfScope string, targetIP net.IP) bo
10121012
return true
10131013
}
10141014
} else {
1015-
outOfScopeURL, err := url.Parse("https://" + outOfScope)
1015+
// The scope has no wildcards
1016+
1017+
var outOfScopeURL *url.URL
1018+
var err error
1019+
1020+
schemeRegex, _ := regexp.Compile(`^\w+:`)
1021+
//if the outofscope starts with a scheme...
1022+
if schemeRegex.MatchString(outOfScope) {
1023+
// Parse it as it is
1024+
outOfScopeURL, err = url.Parse(outOfScope)
1025+
} else {
1026+
// Add a scheme to it so it can be parsed as a URL
1027+
outOfScopeURL, err = url.Parse("https://" + outOfScope)
1028+
}
1029+
10161030
if err != nil {
10171031
if !chainMode {
10181032
warning("Couldn't parse out-of-scope \"" + outOfScope + "\" as a URL.")
10191033
}
10201034
return false
10211035
}
1036+
10221037
if removePortFromHost(targetURL) == outOfScopeURL.Host {
10231038
return true
10241039

main_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ func Test_parseOutOfScopes(t *testing.T) {
7070
value = parseOutOfScopes(assetURL, outOfScopeString, nil)
7171
equals(t, true, value)
7272

73+
// Test - in-scope URL with a URL-like out-of-scope string with an unusual scheme
74+
assetURL, _ = url.Parse("https://zendesk.internal.example.com")
75+
outOfScopeString = "mongodb://sometool.internal.example.com"
76+
value = parseOutOfScopes(assetURL, outOfScopeString, nil)
77+
equals(t, false, value)
78+
79+
// Test - out-of-scope URL with a URL-like out-of-scope string with an unusual scheme
80+
assetURL, _ = url.Parse("https://zendesk.internal.example.com")
81+
outOfScopeString = "mongodb://zendesk.internal.example.com"
82+
value = parseOutOfScopes(assetURL, outOfScopeString, nil)
83+
equals(t, true, value)
84+
7385
// Test with a bad function invocation, providing both an assetURL and an assetIP
7486
// Only the assetURL should be used in this case
7587
assetURL, _ = url.Parse("https://zendesk.internal.example.com")

0 commit comments

Comments
 (0)