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

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