MCPcopy Create free account
hub / github.com/cortexproject/cortex / validateTemplateFilename

Function validateTemplateFilename

pkg/alertmanager/multitenant.go:1394–1405  ·  view source on GitHub ↗

validateTemplateFilename validated the template filename and returns error if it's not valid. The validation done in this function is a first fence to avoid having a tenant submitting a config which may escape the per-tenant data directory on disk.

(filename string)

Source from the content-addressed store, hash-verified

1392// The validation done in this function is a first fence to avoid having a tenant submitting
1393// a config which may escape the per-tenant data directory on disk.
1394func validateTemplateFilename(filename string) error {
1395 if filepath.Base(filename) != filename {
1396 return fmt.Errorf("invalid template name %q: the template name cannot contain any path", filename)
1397 }
1398
1399 // Further enforce no path in the template name.
1400 if filepath.Dir(filepath.Clean(filename)) != "." {
1401 return fmt.Errorf("invalid template name %q: the template name cannot contain any path", filename)
1402 }
1403
1404 return nil
1405}
1406
1407// safeTemplateFilepath builds and return the template filepath within the provided dir.
1408// This function also performs a security check to make sure the provided templateName

Callers 1

validateUserConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected