Skip to content

Commit 9b53a1d

Browse files
authored
fix: treat empty and whitespace-only URIs as not insecure (OSPS-BR-03.01) (#245)
Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent f8c8819 commit 9b53a1d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

evaluation_plans/osps/build_release/steps.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ func getLinks(data data.Payload) []string {
236236
}
237237

238238
func insecureURI(uri string) bool {
239-
if strings.HasPrefix(uri, "https://") ||
239+
if strings.TrimSpace(uri) == "" ||
240+
strings.HasPrefix(uri, "https://") ||
240241
strings.HasPrefix(uri, "ssh:") ||
241242
strings.HasPrefix(uri, "git:") ||
242243
strings.HasPrefix(uri, "git@") {

evaluation_plans/osps/build_release/steps_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ func TestMultipleVariables(t *testing.T) {
124124

125125
}
126126

127+
func TestInsecureURI(t *testing.T) {
128+
tests := []struct {
129+
name string
130+
uri string
131+
expected bool
132+
}{
133+
{"empty string is not insecure", "", false},
134+
{"whitespace string is not insecure", " ", false},
135+
{"https is not insecure", "https://example.com", false},
136+
{"ssh is not insecure", "ssh://example.com", false},
137+
{"git protocol is not insecure", "git://example.com", false},
138+
{"git@ is not insecure", "git@github.com:org/repo.git", false},
139+
{"http is insecure", "http://example.com", true},
140+
{"ftp is insecure", "ftp://example.com", true},
141+
}
142+
143+
for _, tt := range tests {
144+
t.Run(tt.name, func(t *testing.T) {
145+
assert.Equal(t, tt.expected, insecureURI(tt.uri), tt.name)
146+
})
147+
}
148+
}
149+
127150
func TestUnTrustedVarsRegex(t *testing.T) {
128151

129152
expression, err := regexp.Compile(untrustedVarsRegex)

0 commit comments

Comments
 (0)