security: fix dir traversal issue
This commit is contained in:
+15
-3
@@ -264,14 +264,26 @@ func (hs *HTTPServer) getPluginAssets(c *models.ReqContext) {
|
||||
return
|
||||
}
|
||||
|
||||
requestedFile := filepath.Clean(macaron.Params(c.Req)["*"])
|
||||
pluginFilePath := filepath.Join(plugin.PluginDir, requestedFile)
|
||||
requestedFile := filepath.Clean(filepath.Join("/",macaron.Params(c.Req)["*"]))
|
||||
rel, err := filepath.Rel("/", requestedFile)
|
||||
if err != nil {
|
||||
// this should not never fail
|
||||
c.JsonApiErr(500, "Relative path found", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !plugin.IncludedInSignature(requestedFile) {
|
||||
if !plugin.IncludedInSignature(rel) {
|
||||
hs.log.Warn("Access to requested plugin file will be forbidden in upcoming Grafana versions as the file "+
|
||||
"is not included in the plugin signature", "file", requestedFile)
|
||||
}
|
||||
|
||||
absPluginDir, err := filepath.Abs(plugin.PluginDir)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to get plugin absolute path", nil)
|
||||
return
|
||||
}
|
||||
|
||||
pluginFilePath := filepath.Join(absPluginDir, rel)
|
||||
// It's safe to ignore gosec warning G304 since we already clean the requested file path and subsequently
|
||||
// use this with a prefix of the plugin's directory, which is set during plugin loading
|
||||
// nolint:gosec
|
||||
|
||||
Reference in New Issue
Block a user