Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from chrono to time 0.3.3 to avoid vulns #297

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsonschema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ percent-encoding = "2"
regex = "1"
fancy-regex = "^0.7.1"
base64 = ">= 0.2"
chrono = ">= 0.2"
time = { version = ">= 0.3.3", features = ["parsing", "macros"] }
reqwest = { version = ">= 0.10", features = ["blocking", "json"], optional = true}
parking_lot = ">= 0.1"
num-cmp = ">= 0.1"
Expand Down
11 changes: 8 additions & 3 deletions jsonschema/src/keywords/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Validator for `format` keyword.
use std::{net::IpAddr, str::FromStr};

use chrono::{DateTime, NaiveDate};
use fancy_regex::Regex;
use serde_json::{Map, Value};
use url::Url;
Expand Down Expand Up @@ -85,7 +84,12 @@ impl Validate for DateValidator {
validate!("date");
fn is_valid(&self, _: &JSONSchema, instance: &Value) -> bool {
if let Value::String(item) = instance {
if NaiveDate::parse_from_str(item, "%Y-%m-%d").is_ok() {
if time::Date::parse(
item,
&time::macros::format_description!("[year]-[month]-[day]"),
)
.is_ok()
{
// Padding with zeroes is ignored by the underlying parser. The most efficient
// way to check it will be to use a custom parser that won't ignore zeroes,
// but this regex will do the trick and costs ~20% extra time in this validator.
Expand All @@ -105,7 +109,8 @@ impl Validate for DateTimeValidator {
validate!("date-time");
fn is_valid(&self, _: &JSONSchema, instance: &Value) -> bool {
if let Value::String(item) = instance {
DateTime::parse_from_rfc3339(item).is_ok()
time::OffsetDateTime::parse(item, &time::format_description::well_known::Rfc3339)
.is_ok()
} else {
true
}
Expand Down