@@ -1144,17 +1144,21 @@ func (s StatusHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
1144
1144
}
1145
1145
}
1146
1146
1147
- func storeTemplateFile (tenantTemplateDir , templateFileName , content string ) (changed bool , _ error ) {
1147
+ // storeTemplateFile stores template file with given content into specific directory.
1148
+ // Since templateFileName is provided by end-user, it is verified that it doesn't do any path-traversal.
1149
+ // Returns true, if file content has changed (new or updated file), false if file with the same name
1150
+ // and content was already stored locally.
1151
+ func storeTemplateFile (dir , templateFileName , content string ) (bool , error ) {
1148
1152
if templateFileName != filepath .Base (templateFileName ) {
1149
1153
return false , fmt .Errorf ("template file name '%s' is not not valid" , templateFileName )
1150
1154
}
1151
1155
1152
- err := os .MkdirAll (tenantTemplateDir , 0755 )
1156
+ err := os .MkdirAll (dir , 0755 )
1153
1157
if err != nil {
1154
- return false , fmt .Errorf ("unable to create Alertmanager templates directory %q: %s" , tenantTemplateDir , err )
1158
+ return false , fmt .Errorf ("unable to create Alertmanager templates directory %q: %s" , dir , err )
1155
1159
}
1156
1160
1157
- file := filepath .Join (tenantTemplateDir , templateFileName )
1161
+ file := filepath .Join (dir , templateFileName )
1158
1162
// Check if the template file already exists and if it has changed
1159
1163
if tmpl , err := ioutil .ReadFile (file ); err == nil && string (tmpl ) == content {
1160
1164
return false , nil
0 commit comments