Skip to content

format: reject signed numeric tokens in ipv4 and time - #263

Open
sueun-dev wants to merge 1 commit into
santhosh-tekuri:boonfrom
sueun-dev:fix-format-signed-numeric-tokens
Open

format: reject signed numeric tokens in ipv4 and time#263
sueun-dev wants to merge 1 commit into
santhosh-tekuri:boonfrom
sueun-dev:fix-format-signed-numeric-tokens

Conversation

@sueun-dev

Copy link
Copy Markdown

The ipv4 and time format validators parse their numeric tokens with strconv.Atoi, which accepts a leading +/- sign, so signed tokens validate even though the dotted-quad and RFC 3339 grammars are digit-only:

ipv4       "1.2.3.+4"              -> valid (want invalid)
ipv4       "+1.2.3.4"              -> valid
ipv4       "1.2.3.-0"              -> valid
time       "+9:30:00Z"            -> valid
time       "12:+9:00Z"            -> valid
time       "12:00:00+09:+0"       -> valid
date-time  "2020-01-01T+9:30:00Z" -> valid  (date-time reuses the time check)
email      "a@[1.2.3.+4]"         -> valid  (bracketed IPv4 literal reuses ipv4)

validateDuration and validateSemver in the same file already reject non-digit characters with an explicit loop. This adds a small isAllDigits helper and applies it before the three strconv.Atoi call sites (ipv4 octet, time hh:mm:ss, offset hh:mm), so date-time and email inherit the fix.

Added TestFormatRejectsSignedNumericTokens. Checked: go test ./... (including the official JSON-Schema-Test-Suite), go vet ./..., gofmt -l.

The ipv4 and time (and thus date-time and email domain-literal) validators
parsed their numeric tokens with strconv.Atoi, which accepts a leading '+'
or '-' sign. Values like ipv4 "1.2.3.+4" / "+1.2.3.4" / "1.2.3.-0" and
time "+9:30:00Z" / "12:+9:00Z" validated even though the dotted-quad and
RFC 3339 grammars are digit-only.

Reject tokens containing a non-digit before parsing, matching the digit-only
handling already used by validateDuration and validateSemver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant