Skip to content

Unmarshal Tag is Dash

Description

Struct field can be decoded with the `-` key because the JSON tag starts with a `-` but is followed by a comma, potentially leading to encoding errors.

Examples

Insecure Code

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

Secure Code

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

Remediation

Remove the comma after the `-` in the JSON tag to prevent encoding errors.

Rule Details

FieldValue
IDCODE-0245
CategoryInsecureConfig
SeverityMEDIUM
CWECWE-172
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsencoding-error, json-tag
OWASPN/A

References