Skip to content

Commit 05a1df0

Browse files
validate SHA1
Signed-off-by: Tim Vaillancourt <[email protected]>
1 parent 6ae6ef3 commit 05a1df0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/ci_workflow_gen.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"os/exec"
2626
"path"
27+
"regexp"
2728
"strings"
2829
"sync"
2930
"text/template"
@@ -248,8 +249,14 @@ func getGitRefSHA(ctx context.Context, url, branchOrTag string) (string, error)
248249
if len(fields) != 2 {
249250
continue
250251
}
252+
sha := fields[0]
251253
if strings.Contains(fields[1], branchOrTag) {
252-
return fields[0], nil
254+
// git SHA1 hashes are 40 hex characters.
255+
match, err := regexp.MatchString(`^[a-zA-Z0-9]{40}$`, sha)
256+
if !match || err != nil {
257+
continue
258+
}
259+
return sha, nil
253260
}
254261
}
255262
return "", fmt.Errorf("cannot parse output of 'git ls-remote' for %q", url)

0 commit comments

Comments
 (0)