Blame SOURCES/011-CVE-2021-43813.patch

50c0ae
commit ea77415cfe2cefe46ffce233076a1409abaa8df7
50c0ae
Author: Will Browne <wbrowne@users.noreply.github.com>
50c0ae
Date:   Fri Dec 10 11:29:12 2021 +0000
50c0ae
50c0ae
    apply fix (#42969)
50c0ae
50c0ae
diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go
50c0ae
index e6370a29e7..c7199c716e 100644
50c0ae
--- a/pkg/plugins/plugins.go
50c0ae
+++ b/pkg/plugins/plugins.go
50c0ae
@@ -491,15 +491,15 @@ func GetPluginMarkdown(pluginId string, name string) ([]byte, error) {
50c0ae
 	}
50c0ae
 
50c0ae
 	// nolint:gosec
50c0ae
-	// We can ignore the gosec G304 warning on this one because `plug.PluginDir` is based
50c0ae
-	// on plugin the folder structure on disk and not user input.
50c0ae
-	path := filepath.Join(plug.PluginDir, fmt.Sprintf("%s.md", strings.ToUpper(name)))
50c0ae
+	// We can ignore the gosec G304 warning since we have cleaned the requested file path and subsequently
50c0ae
+	// use this with a prefix of the plugin's directory, which is set during plugin loading
50c0ae
+	path := filepath.Join(plug.PluginDir, mdFilepath(strings.ToUpper(name)))
50c0ae
 	exists, err := fs.Exists(path)
50c0ae
 	if err != nil {
50c0ae
 		return nil, err
50c0ae
 	}
50c0ae
 	if !exists {
50c0ae
-		path = filepath.Join(plug.PluginDir, fmt.Sprintf("%s.md", strings.ToLower(name)))
50c0ae
+		path = filepath.Join(plug.PluginDir, mdFilepath(strings.ToLower(name)))
50c0ae
 	}
50c0ae
 
50c0ae
 	exists, err = fs.Exists(path)
50c0ae
@@ -511,8 +511,8 @@ func GetPluginMarkdown(pluginId string, name string) ([]byte, error) {
50c0ae
 	}
50c0ae
 
50c0ae
 	// nolint:gosec
50c0ae
-	// We can ignore the gosec G304 warning on this one because `plug.PluginDir` is based
50c0ae
-	// on plugin the folder structure on disk and not user input.
50c0ae
+	// We can ignore the gosec G304 warning since we have cleaned the requested file path and subsequently
50c0ae
+	// use this with a prefix of the plugin's directory, which is set during plugin loading
50c0ae
 	data, err := ioutil.ReadFile(path)
50c0ae
 	if err != nil {
50c0ae
 		return nil, err
50c0ae
@@ -520,6 +520,10 @@ func GetPluginMarkdown(pluginId string, name string) ([]byte, error) {
50c0ae
 	return data, nil
50c0ae
 }
50c0ae
 
50c0ae
+func mdFilepath(mdFilename string) string {
50c0ae
+	return filepath.Clean(filepath.Join("/", fmt.Sprintf("%s.md", mdFilename)))
50c0ae
+}
50c0ae
+
50c0ae
 // gets plugin filenames that require verification for plugin signing
50c0ae
 func collectPluginFilesWithin(rootDir string) ([]string, error) {
50c0ae
 	var files []string