Skip to content

Commit 4ab6495

Browse files
committed
prevent panic caused by accessing unexported fields
This PR fixes a panic caused by predicate trying to access unexported fields without properly checking if the field is exported. When this happens, reflection package panics. Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
1 parent 93c5cee commit 4ab6495

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ func getFieldByTag(ival interface{}, tagName string, fieldNames []string) (inter
180180
valType := val.Type()
181181
for i := 0; i < valType.NumField(); i++ {
182182
tagValue := valType.Field(i).Tag.Get(tagName)
183+
// Always skip unexported fields.
184+
// This is important to avoid panics when accessing unexported fields.
185+
if !valType.Field(i).IsExported() {
186+
continue
187+
}
183188

184189
// If it's an embedded field, traverse it.
185190
if tagValue == "" && valType.Field(i).Anonymous {

0 commit comments

Comments
 (0)