Skip to content

fix: reject invalid CloudEvent time values - #677

Open
eisen0419 wants to merge 1 commit into
cloudevents:mainfrom
eisen0419:fix/reject-invalid-time-header
Open

eisen0419 wants to merge 1 commit into
cloudevents:mainfrom
eisen0419:fix/reject-invalid-time-header

Conversation

@eisen0419

Copy link
Copy Markdown

DateParser.parse fell back to new Date() when Date.parse() returned Invalid Date, and shouldParse skipped empty string values before they reached the parser. As a result, HTTP.toEvent replaced malformed or empty ce-time / time values with the current UTC timestamp instead of failing validation (and HTTP.isEvent returned true).

Changes

  • Validate present time strings in DateParser.parse against RFC 3339 date-time (including calendar month/day bounds and UTC/numeric offsets) and throw ValidationError("invalid time, must be RFC 3339") on malformed or non-string inputs instead of substituting new Date().
  • Route present ce-time / time attributes (including "") through DateParser in src/message/http/index.ts, while keeping omitted, undefined, and JSON null values on the existing default path per the CloudEvents JSON format spec.
  • Use nullish coalescing (??) in CloudEvent construction so falsy values such as "", 0, or false are not silently defaulted to the current timestamp before schema validation.
  • Add parser, HTTP binary/structured (v1 and v0.3), and constructor validation tests in test/integration/time_validation_test.ts.

Fixes #386

Malformed time strings were replaced with the current timestamp. Reject
them with ValidationError, and still default time when it is omitted.

Signed-off-by: eisen0419 <[email protected]>

This branch has not been deployed

No deployments
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.

SHOULD throw if time has an invalid value?

1 participant