reject non-RFC3339 timestamp strings in timestamp() conversion#1338
Open
alhudz wants to merge 2 commits into
Open
reject non-RFC3339 timestamp strings in timestamp() conversion#1338alhudz wants to merge 2 commits into
alhudz wants to merge 2 commits into
Conversation
| if t.Unix() < minUnixTime || t.Unix() > maxUnixTime { | ||
| return celErrTimestampOverflow | ||
| str := s.Value().(string) | ||
| if strictRFC3339Pattern.MatchString(str) { |
Collaborator
There was a problem hiding this comment.
Prefer early return on an error for an invalid format as this will provide a more helpful message to the user (or agent).
Contributor
Author
There was a problem hiding this comment.
Done. The pattern check now returns early with invalid RFC 3339 timestamp "<value>" rather than falling through to the generic conversion error, and the regression test asserts the exact message for each rejected form. go test ./... still passes.
Collaborator
There was a problem hiding this comment.
Would you mind adding a little benchmark to see the perf impact of the regex?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repro:
timestamp("2025-01-17T01:00:00,001Z"),timestamp("2025-01-17T1:00:00Z"),timestamp("2025-01-18T01:01:01.001+24:01")andtimestamp("2025-01-17T01:01:01.001+00:60")all evaluate to a value instead of erroring.Cause: the
string-to-timestamp conversion parses withtime.Parse(time.RFC3339, ...), which accepts inputs RFC 3339 forbids: a,fractional separator, single-digit time fields, and offset hours past23or minutes past59. These silently shift the parsed instant or get wrongly accepted.Fix: gate the conversion on a strict RFC 3339 pattern in the callee before
time.Parseruns, so the listed forms report the usual conversion error whiletime.Parsekeeps doing the calendar validation.Closes #1108