Skip to content

Unmarshal Tag Omitempty

Description

The `omitempty` key is used in a struct field, which can lead to encoding errors. The developer likely intended to use ",omitempty" instead.

Examples

Insecure Code

go
type T struct { X string `json:"omitempty"` }

Secure Code

go
type T struct { X string `json:"omitempty,"` }

Remediation

Add a comma before 'omitempty' in the struct field tag.

Rule Details

FieldValue
IDCODE-0508
CategoryInsecureConfig
SeverityMEDIUM
CWECWE-172
ConfidenceHIGH
ImpactLOW
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsencoding-error, struct-field
OWASPN/A

References