Skip to content

Commit 625c66e

Browse files
alexjgStranger6667
authored andcommitted
fix: Switch from chrono to time 0.3.3
Due to a CVE in chrono[0] we switch to time 0.3.3. Chrono actually depends on an older, similarly vulnerable version of `time` but newer versions of `time` seem to offer everything we need to validate dates and times anyway. [0] rustsec/advisory-db#1082 Signed-off-by: Alex Good <[email protected]>
1 parent 8d1d598 commit 625c66e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

jsonschema/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ percent-encoding = "2"
2929
regex = "1"
3030
fancy-regex = "^0.7.1"
3131
base64 = ">= 0.2"
32-
chrono = ">= 0.2"
32+
time = { version = ">= 0.3.3", features = ["parsing", "macros"] }
3333
reqwest = { version = ">= 0.10", features = ["blocking", "json"], optional = true}
3434
parking_lot = ">= 0.1"
3535
num-cmp = ">= 0.1"

jsonschema/src/keywords/format.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Validator for `format` keyword.
22
use std::{net::IpAddr, str::FromStr};
33

4-
use chrono::{DateTime, NaiveDate};
54
use fancy_regex::Regex;
65
use serde_json::{Map, Value};
76
use url::Url;
@@ -85,7 +84,12 @@ impl Validate for DateValidator {
8584
validate!("date");
8685
fn is_valid(&self, _: &JSONSchema, instance: &Value) -> bool {
8786
if let Value::String(item) = instance {
88-
if NaiveDate::parse_from_str(item, "%Y-%m-%d").is_ok() {
87+
if time::Date::parse(
88+
item,
89+
&time::macros::format_description!("[year]-[month]-[day]"),
90+
)
91+
.is_ok()
92+
{
8993
// Padding with zeroes is ignored by the underlying parser. The most efficient
9094
// way to check it will be to use a custom parser that won't ignore zeroes,
9195
// but this regex will do the trick and costs ~20% extra time in this validator.
@@ -105,7 +109,8 @@ impl Validate for DateTimeValidator {
105109
validate!("date-time");
106110
fn is_valid(&self, _: &JSONSchema, instance: &Value) -> bool {
107111
if let Value::String(item) = instance {
108-
DateTime::parse_from_rfc3339(item).is_ok()
112+
time::OffsetDateTime::parse(item, &time::format_description::well_known::Rfc3339)
113+
.is_ok()
109114
} else {
110115
true
111116
}

0 commit comments

Comments
 (0)