-
Notifications
You must be signed in to change notification settings - Fork 43
[PM-41690] fix: CXF import crash on negative timestamps #1362
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| mod dashlane_import_test; | ||
| mod negative_timestamp_test; | ||
| mod one_password_import_test; | ||
| mod sample_import_test; |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎨 Thanks for adding comprehensive test coverage. As described in another comment, this PR does not resolve the crash when these negative values are nested within a #[test]
fn poc_collections_negative_timestamp_still_crashes() {
let input = r#"{
"id": "DZSXp7iBQY-Fg-OofakQtQ", "username": "u", "email": "e",
"collections": [{
"id": "DZSXp7iBQY-Fg-OofakQtQ",
"creationAt": -11644473600,
"modifiedAt": -11644473600,
"title": "C",
"items": []
}],
"items": []
}"#;
let result = parse_cxf(input.to_string());
assert!(result.is_ok(), "{:?}", result.err());
}🎨 If you agree with the code changes I've suggested in #[test]
fn test_sanitize_valid_timestamps_unchanged_returns_borrowed() {
let input = r#"{"id":"test","items":[{"id":"1","creationAt":1759783057,"modifiedAt":1759783057,"title":"Test","credentials":[]}]}"#;
let result = sanitize_timestamps(input);
assert!(matches!(result, std::borrow::Cow::Borrowed(_)));
}
#[test]
fn test_sanitize_negative_timestamp_in_collection() {
let input = r#"{"id":"test","items":[],"collections":[{"id":"c1","creationAt":-11644473600,"modifiedAt":-11644473600,"title":"C","items":[]}]}"#;
let result = sanitize_timestamps(input);
assert!(result.contains(r#""creationAt":null"#));
assert!(result.contains(r#""modifiedAt":null"#));
}
#[test]
fn test_sanitize_negative_timestamp_in_sub_collection() {
let input = r#"{"id":"test","items":[],"collections":[{"id":"c1","title":"C","items":[],
"subCollections":[{"id":"c2","creationAt":-11644473600,"title":"Sub","items":[]}]}]}"#;
let result = sanitize_timestamps(input);
assert!(result.contains(r#""creationAt":null"#));
}
#[test]
fn test_parse_cxf_with_negative_timestamps_falls_back_to_current_time() {
let input = r#"{
"id": "DZSXp7iBQY-Fg-OofakQtQ", "username": "u", "email": "e",
"collections": [{"id":"c1","creationAt":-11644473600,"modifiedAt":-11644473600,"title":"C","items":[]}],
"items": [{
"id": "9OF-QjVDQo2Wp2xWPw6ZhA",
"creationAt": -11644473600, "modifiedAt": -11644473600,
"title": "Test Entry",
"credentials": [{"type":"basic-auth","username":{"id":"u","fieldType":"string","value":"testuser"},
"password":{"id":"p","fieldType":"concealed-string","value":"testpass"},
"urls":["https://example.com"]}]
}]
}"#;
let ciphers = parse_cxf(input.to_string()).expect("should not error on negative timestamps");
let cipher = ciphers.first().unwrap();
assert!(cipher.creation_date > Utc::now() - chrono::Duration::seconds(5));
}🎨 You will also want to update existing tests in this file to expect
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @harr1424 - Merged in your updates and fixed the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| //! Tests for handling negative timestamps in CXF import. | ||
| //! | ||
| //! Some credential managers (e.g., Google Password Manager) export timestamps | ||
| //! as the Windows FILETIME epoch (-11644473600) when no real date exists. | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::cxf::import::{parse_cxf, sanitize_timestamps}; | ||
|
|
||
| #[test] | ||
| fn test_sanitize_negative_creation_at() { | ||
| let input = r#"{"id":"test","items":[{"id":"1","creationAt":-11644473600,"modifiedAt":1759783057,"title":"Test","credentials":[]}]}"#; | ||
| let result = sanitize_timestamps(input); | ||
| assert!(result.contains(r#""creationAt":0"#)); | ||
| assert!(result.contains(r#""modifiedAt":1759783057"#)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_sanitize_negative_modified_at() { | ||
| let input = r#"{"id":"test","items":[{"id":"1","creationAt":1759783057,"modifiedAt":-11644473600,"title":"Test","credentials":[]}]}"#; | ||
| let result = sanitize_timestamps(input); | ||
| assert!(result.contains(r#""creationAt":1759783057"#)); | ||
| assert!(result.contains(r#""modifiedAt":0"#)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_sanitize_both_negative() { | ||
| let input = r#"{"id":"test","items":[{"id":"1","creationAt":-11644473600,"modifiedAt":-11644473600,"title":"Test","credentials":[]}]}"#; | ||
| let result = sanitize_timestamps(input); | ||
| assert!(result.contains(r#""creationAt":0"#)); | ||
| assert!(result.contains(r#""modifiedAt":0"#)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_sanitize_valid_timestamps_unchanged() { | ||
| let input = r#"{"id":"test","items":[{"id":"1","creationAt":1759783057,"modifiedAt":1759783057,"title":"Test","credentials":[]}]}"#; | ||
| let result = sanitize_timestamps(input); | ||
| assert!(result.contains(r#""creationAt":1759783057"#)); | ||
| assert!(result.contains(r#""modifiedAt":1759783057"#)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_cxf_with_negative_timestamps_does_not_error() { | ||
| let input = r#"{ | ||
| "id": "DZSXp7iBQY-Fg-OofakQtQ", | ||
| "username": "user@example.com", | ||
| "email": "user@example.com", | ||
| "fullName": "Test User", | ||
| "collections": [], | ||
| "items": [{ | ||
| "id": "9OF-QjVDQo2Wp2xWPw6ZhA", | ||
| "creationAt": -11644473600, | ||
| "modifiedAt": -11644473600, | ||
| "title": "Test Entry", | ||
| "credentials": [{ | ||
| "type": "basic-auth", | ||
| "username": { | ||
| "id": "-eZX0Gw-TzOsBFwt67N7ZA", | ||
| "fieldType": "string", | ||
| "value": "testuser" | ||
| }, | ||
| "password": { | ||
| "id": "wgu3wTcXSYawrGMWMtaANg", | ||
| "fieldType": "concealed-string", | ||
| "value": "testpass" | ||
| }, | ||
| "urls": ["https://example.com"] | ||
| }] | ||
| }] | ||
| }"#; | ||
| let result = parse_cxf(input.to_string()); | ||
| assert!(result.is_ok(), "parse_cxf should not error on negative timestamps: {:?}", result.err()); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.