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)
| 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. |
| 1394 | func 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 |
no outgoing calls
no test coverage detected