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 package config
import ( import (
"bytes"
"context" "context"
"fmt" "fmt"
"io" "io"
@@ -235,8 +236,10 @@ func (parser ConfigFileParser) ParseYAML(data []byte) (*Config, error) {
parsedData = &configYAML{} parsedData = &configYAML{}
) )
err := yaml.Unmarshal(data, &parsedData) decoder := yaml.NewDecoder(bytes.NewReader(data))
if err != nil { 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) return nil, types.NewUnmarshalError(err)
} }