Skip to content

Truly independent web browser

LibJS: Reject a UTC offset hour of 24 in an ISO date-time string

Shannon Boothc057aa98422d
diff --git a/Libraries/LibJS/Rust/src/runtime/date_parser.rs b/Libraries/LibJS/Rust/src/runtime/date_parser.rs
index c9d4dc0baea..4b3072ec249 100644
--- a/Libraries/LibJS/Rust/src/runtime/date_parser.rs
+++ b/Libraries/LibJS/Rust/src/runtime/date_parser.rs
@@ -1041,6 +1041,11 @@ impl DateParser {
return Err("Invalid timezone offset format.");
}
+ // The hour of a UTC offset is at most 23: https://tc39.es/ecma262/#sec-date-time-string-format
+ if self.timezone_hours.is_some_and(|hours| hours > 23) {
+ return Err("Timezone offset hour out of range.");
+ }
+
Ok(())
}
diff --git a/Tests/LibJS/Runtime/builtins/Date/Date.parse.js b/Tests/LibJS/Runtime/builtins/Date/Date.parse.js
index e284912286f..cd7009de924 100644
--- a/Tests/LibJS/Runtime/builtins/Date/Date.parse.js
+++ b/Tests/LibJS/Runtime/builtins/Date/Date.parse.js
@@ -246,3 +246,9 @@ test("Round trip Date.prototype.to*String", () => {
expect(Date.parse(epoch.toISOString())).toBe(epoch.valueOf());
expect(Date.parse(epoch.toUTCString())).toBe(epoch.valueOf());
});
+
+test("UTC offset hour out of range", () => {
+ expect(Date.parse("2000-01-01T10:00:00+24:00")).toBeNaN();
+ expect(Date.parse("2000-01-01T10:00:00-24:00")).toBeNaN();
+ expect(Date.parse("2000-01-01T10:00:00+23:59")).toBe(946634460000);
+});