From b9cacbc3474ffd6442a203fe2c5d11f6fe89050c Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Wed, 26 Jul 2023 11:50:37 -0700 Subject: [PATCH] Do not allow issue and pr templates to be symlinks (#7756) --- pkg/githubtemplate/github_template.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/githubtemplate/github_template.go b/pkg/githubtemplate/github_template.go index 9cba70d5c..c52c3e4b4 100644 --- a/pkg/githubtemplate/github_template.go +++ b/pkg/githubtemplate/github_template.go @@ -2,6 +2,7 @@ package githubtemplate import ( "fmt" + "io/fs" "os" "path" "regexp" @@ -28,7 +29,6 @@ mainLoop: if err != nil { continue } - // detect multiple templates in a subdirectory for _, file := range files { if strings.EqualFold(file.Name(), name) && file.IsDir() { @@ -37,7 +37,8 @@ mainLoop: break } for _, tf := range templates { - if strings.HasSuffix(tf.Name(), ".md") { + if strings.HasSuffix(tf.Name(), ".md") && + file.Type() != fs.ModeSymlink { results = append(results, path.Join(dir, file.Name(), tf.Name())) } } @@ -48,6 +49,7 @@ mainLoop: } } } + sort.Strings(results) return results } @@ -62,19 +64,22 @@ func FindLegacy(rootDir string, name string) string { rootDir, path.Join(rootDir, "docs"), } + for _, dir := range candidateDirs { files, err := os.ReadDir(dir) if err != nil { continue } - // detect a single template file for _, file := range files { - if namePattern.MatchString(file.Name()) && !file.IsDir() { + if namePattern.MatchString(file.Name()) && + !file.IsDir() && + file.Type() != fs.ModeSymlink { return path.Join(dir, file.Name()) } } } + return "" }