Skip to content

reject non-RFC3339 timestamp strings in timestamp() conversion#1338

Open
alhudz wants to merge 2 commits into
cel-expr:masterfrom
alhudz:timestamp-rfc3339-strict
Open

reject non-RFC3339 timestamp strings in timestamp() conversion#1338
alhudz wants to merge 2 commits into
cel-expr:masterfrom
alhudz:timestamp-rfc3339-strict

Conversation

@alhudz

@alhudz alhudz commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Repro: timestamp("2025-01-17T01:00:00,001Z"), timestamp("2025-01-17T1:00:00Z"), timestamp("2025-01-18T01:01:01.001+24:01") and timestamp("2025-01-17T01:01:01.001+00:60") all evaluate to a value instead of erroring.
Cause: the string-to-timestamp conversion parses with time.Parse(time.RFC3339, ...), which accepts inputs RFC 3339 forbids: a , fractional separator, single-digit time fields, and offset hours past 23 or minutes past 59. 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.Parse runs, so the listed forms report the usual conversion error while time.Parse keeps doing the calendar validation.

Closes #1108

Comment thread common/types/string.go Outdated
if t.Unix() < minUnixTime || t.Unix() > maxUnixTime {
return celErrTimestampOverflow
str := s.Value().(string)
if strictRFC3339Pattern.MatchString(str) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer early return on an error for an invalid format as this will provide a more helpful message to the user (or agent).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a little benchmark to see the perf impact of the regex?

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.

cel-go inherits RFC 3339 parsing bugs from Golang's time.Parse()

2 participants