Harden external catalog validation
This commit is contained in:
@@ -14,8 +14,11 @@ import (
|
||||
|
||||
// LoadedProfileMetadata identifies one profile accepted by LoadFSRepository.
|
||||
type LoadedProfileMetadata struct {
|
||||
ID string
|
||||
Path string
|
||||
// ID is the normalized profile ID.
|
||||
ID string
|
||||
// Path is the safe root-relative source path.
|
||||
Path string
|
||||
// ExplicitFields lists the sorted top-level YAML fields present in source.
|
||||
ExplicitFields []string
|
||||
}
|
||||
|
||||
@@ -42,24 +45,24 @@ func LoadFSRepository(ctx context.Context, fsys fs.FS, root string) (Repository,
|
||||
}
|
||||
fileMetadata, err := readProfileFileMetadata(data)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("%w: %s: %v", ErrInvalidYAML, filecatalog.DisplayPath(root, path), err)
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrInvalidYAML, filecatalog.DisplayPath(root, path))
|
||||
}
|
||||
if fileMetadata.hasRawAPIKey {
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrRawAPIKeyNotAllowed, filecatalog.DisplayPath(root, path))
|
||||
}
|
||||
definition, err := decodeProfile(data)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("%w: %s: %v", ErrInvalidYAML, filecatalog.DisplayPath(root, path), err)
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrInvalidYAML, filecatalog.DisplayPath(root, path))
|
||||
}
|
||||
definition.ExtraParams, err = jsonvalue.CopyMap(definition.ExtraParams)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("%w: %s: %v", ErrInvalidProfile, filecatalog.DisplayPath(root, path), err)
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrInvalidProfile, filecatalog.DisplayPath(root, path))
|
||||
}
|
||||
if err := NormalizeAndValidateDefinition(definition); err != nil {
|
||||
return nil, nil, fmt.Errorf("%w: %s: %v", ErrInvalidProfile, filecatalog.DisplayPath(root, path), err)
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrInvalidProfile, filecatalog.DisplayPath(root, path))
|
||||
}
|
||||
if _, exists := repository.profiles[definition.ID]; exists {
|
||||
return nil, nil, fmt.Errorf("%w: duplicate execution profile id %q", ErrInvalidProfile, definition.ID)
|
||||
return nil, nil, fmt.Errorf("%w: %s: duplicate profile ID", ErrInvalidProfile, filecatalog.DisplayPath(root, path))
|
||||
}
|
||||
repository.profiles[definition.ID] = *definition
|
||||
fields := append([]string(nil), fileMetadata.explicitFields...)
|
||||
|
||||
Reference in New Issue
Block a user