fix(config): reject unknown fields in a YAML config file

This commit is contained in:
aykhans committed 2026-09-30 00:14:51 +04:00
1 parent fb8443fd25
commit 68de415645
1 file changed
+5 -2
+5 -2
View File
@@ -1,6 +1,7 @@
package config
import (
"bytes"
"context"
"fmt"
"io"
@@ -235,8 +236,10 @@ func (parser ConfigFileParser) ParseYAML(data []byte) (*Config, error) {
parsedData = &configYAML{}
)
err := yaml.Unmarshal(data, &parsedData)
if err != nil {
decoder := yaml.NewDecoder(bytes.NewReader(data))
decoder.KnownFields(true)
// The decoder returns a bare io.EOF for an empty file, errors.Is would also match a wrapped one.
if err := decoder.Decode(parsedData); err != nil && err != io.EOF { //nolint:errorlint
return nil, types.NewUnmarshalError(err)
}