Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ extensions:
- ["lang:alloc", "<crate::string::String>::as_str", "Argument[self]", "ReturnValue", "taint", "manual"]
- ["lang:alloc", "<crate::string::String>::as_bytes", "Argument[self]", "ReturnValue", "taint", "manual"]
- ["lang:alloc", "<_ as crate::string::ToString>::to_string", "Argument[self]", "ReturnValue", "taint", "manual"]
- ["lang:alloc", "<crate::string::String>::parse", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
- ["lang:alloc", "<crate::string::String>::trim", "Argument[self]", "ReturnValue.Reference", "taint", "manual"]
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ extensions:
- ["lang:core", "crate::ptr::write_unaligned", "Argument[1]", "Argument[0].Reference", "value", "manual"]
- ["lang:core", "crate::ptr::write_volatile", "Argument[1]", "Argument[0].Reference", "value", "manual"]
# Str
- ["lang:core", "<str>::as_str", "Argument[self]", "ReturnValue", "taint", "manual"]
- ["lang:core", "<str>::as_bytes", "Argument[self]", "ReturnValue", "taint", "manual"]
- ["lang:core", "<str>::to_string", "Argument[self]", "ReturnValue", "taint", "manual"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function <str>::as_str is value preserving, it just returns self. I think as_bytes should be considered value preserving as well. It is defined as and doesn't change the value, only its type.

    pub const fn as_bytes(&self) -> &[u8] {
        // SAFETY: const sound because we transmute two types with the same layout
        unsafe { mem::transmute(self) }
    }

I'm a little in doubt of whether to consider str::to_string to be value preserving as well. I'm not sure whether we consider copies to be taint or value preserving in other cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Done.

I'm a little in doubt of whether to consider str::to_string to be value preserving as well.

I would say no, because in general to_string is not value preserving.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it's only value "preserving" for String and str.

- ["lang:core", "<str>::parse", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
- ["lang:core", "<str>::trim", "Argument[self]", "ReturnValue.Reference", "taint", "manual"]
- addsTo:
pack: codeql/rust-all
extensible: sourceModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,7 @@ storeStep
| file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Err(0)].Reference in lang:core::_::<crate::result::Result>::as_ref | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Err(0)] in lang:core::_::<crate::result::Result>::as_ref |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Ok(0)] in lang:alloc::_::<crate::collections::btree::node::NodeRef>::search_tree_for_bifurcation | Ok | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::collections::btree::node::NodeRef>::search_tree_for_bifurcation |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Ok(0)] in lang:alloc::_::<crate::string::String as crate::str::traits::FromStr>::from_str | Ok | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String as crate::str::traits::FromStr>::from_str |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Ok(0)] in lang:alloc::_::<crate::string::String>::parse | Ok | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::parse |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Ok(0)] in lang:core::_::<crate::alloc::layout::Layout>::align_to | Ok | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::alloc::layout::Layout>::align_to |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Ok(0)] in lang:core::_::<crate::alloc::layout::Layout>::array | Ok | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::alloc::layout::Layout>::array |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Field[crate::result::Result::Ok(0)] in lang:core::_::<crate::alloc::layout::Layout>::extend | Ok | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::alloc::layout::Layout>::extend |
Expand Down Expand Up @@ -2240,6 +2241,7 @@ storeStep
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:alloc::_::<crate::rc::UniqueRc as crate::convert::AsRef>::as_ref | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::rc::UniqueRc as crate::convert::AsRef>::as_ref |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:alloc::_::<crate::string::String as crate::borrow::Borrow>::borrow | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String as crate::borrow::Borrow>::borrow |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:alloc::_::<crate::string::String as crate::borrow::BorrowMut>::borrow_mut | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String as crate::borrow::BorrowMut>::borrow_mut |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:alloc::_::<crate::string::String>::trim | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::trim |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:alloc::_::<crate::sync::Arc as crate::borrow::Borrow>::borrow | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::sync::Arc as crate::borrow::Borrow>::borrow |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:alloc::_::<crate::sync::Arc as crate::convert::AsRef>::as_ref | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::sync::Arc as crate::convert::AsRef>::as_ref |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:alloc::_::<crate::vec::Vec as crate::borrow::Borrow>::borrow | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::vec::Vec as crate::borrow::Borrow>::borrow |
Expand All @@ -2263,6 +2265,7 @@ storeStep
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:core::_::<crate::option::Option>::insert | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::option::Option>::insert |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:core::_::<crate::panic::unwind_safe::AssertUnwindSafe as crate::ops::deref::Deref>::deref | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::panic::unwind_safe::AssertUnwindSafe as crate::ops::deref::Deref>::deref |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:core::_::<crate::panic::unwind_safe::AssertUnwindSafe as crate::ops::deref::DerefMut>::deref_mut | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::panic::unwind_safe::AssertUnwindSafe as crate::ops::deref::DerefMut>::deref_mut |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:core::_::<str>::trim | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<str>::trim |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:core::_::<usize as crate::slice::index::SliceIndex>::index | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<usize as crate::slice::index::SliceIndex>::index |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:core::_::<usize as crate::slice::index::SliceIndex>::index_mut | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<usize as crate::slice::index::SliceIndex>::index_mut |
| file://:0:0:0:0 | [summary] to write: ReturnValue.Reference in lang:proc_macro::_::<&[u8] as crate::bridge::rpc::DecodeMut>::decode | &ref | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:proc_macro::_::<&[u8] as crate::bridge::rpc::DecodeMut>::decode |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
| test.rs:62:9:62:24 | ...::digest | test.rs:62:26:62:37 | password_arr | test.rs:62:9:62:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:62:26:62:37 | password_arr | Sensitive data (password) |
| test.rs:64:9:64:24 | ...::digest | test.rs:64:26:64:37 | password_vec | test.rs:64:9:64:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:64:26:64:37 | password_vec | Sensitive data (password) |
| test.rs:77:9:77:33 | ...::new_with_prefix | test.rs:77:35:77:42 | password | test.rs:77:9:77:33 | ...::new_with_prefix | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:77:35:77:42 | password | Sensitive data (password) |
| test.rs:81:9:81:24 | ...::digest | test.rs:81:26:81:33 | password | test.rs:81:9:81:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:81:26:81:33 | password | Sensitive data (password) |
| test.rs:83:9:83:24 | ...::digest | test.rs:83:26:83:33 | password | test.rs:83:9:83:24 | ...::digest | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | test.rs:83:26:83:33 | password | Sensitive data (password) |
edges
| test.rs:14:26:14:39 | credit_card_no | test.rs:14:9:14:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
| test.rs:15:26:15:33 | password | test.rs:15:9:15:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
Expand All @@ -26,10 +28,16 @@ edges
| test.rs:62:26:62:37 | password_arr | test.rs:62:9:62:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
| test.rs:64:26:64:37 | password_vec | test.rs:64:9:64:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
| test.rs:77:35:77:42 | password | test.rs:77:9:77:33 | ...::new_with_prefix | provenance | MaD:2 Sink:MaD:2 |
| test.rs:81:26:81:33 | password | test.rs:81:26:81:40 | password.trim() [&ref] | provenance | MaD:5 |
| test.rs:81:26:81:40 | password.trim() [&ref] | test.rs:81:9:81:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
| test.rs:83:26:83:33 | password | test.rs:83:26:83:44 | password.as_bytes() | provenance | MaD:4 |
| test.rs:83:26:83:44 | password.as_bytes() | test.rs:83:9:83:24 | ...::digest | provenance | MaD:1 Sink:MaD:1 |
models
| 1 | Sink: repo:https://github.com/RustCrypto/traits:digest; <_ as crate::digest::Digest>::digest; hasher-input; Argument[0] |
| 2 | Sink: repo:https://github.com/RustCrypto/traits:digest; <_ as crate::digest::Digest>::new_with_prefix; hasher-input; Argument[0] |
| 3 | Sink: repo:https://github.com/stainless-steel/md5:md5; crate::compute; hasher-input; Argument[0] |
| 4 | Summary: lang:core; <str>::as_bytes; Argument[self]; ReturnValue; taint |
| 5 | Summary: lang:core; <str>::trim; Argument[self]; ReturnValue.Reference; taint |
nodes
| test.rs:14:9:14:24 | ...::digest | semmle.label | ...::digest |
| test.rs:14:26:14:39 | credit_card_no | semmle.label | credit_card_no |
Expand Down Expand Up @@ -57,4 +65,10 @@ nodes
| test.rs:64:26:64:37 | password_vec | semmle.label | password_vec |
| test.rs:77:9:77:33 | ...::new_with_prefix | semmle.label | ...::new_with_prefix |
| test.rs:77:35:77:42 | password | semmle.label | password |
| test.rs:81:9:81:24 | ...::digest | semmle.label | ...::digest |
| test.rs:81:26:81:33 | password | semmle.label | password |
| test.rs:81:26:81:40 | password.trim() [&ref] | semmle.label | password.trim() [&ref] |
| test.rs:83:9:83:24 | ...::digest | semmle.label | ...::digest |
| test.rs:83:26:83:33 | password | semmle.label | password |
| test.rs:83:26:83:44 | password.as_bytes() | semmle.label | password.as_bytes() |
subpaths
4 changes: 2 additions & 2 deletions rust/ql/test/query-tests/security/CWE-328/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ fn test_hash_code_patterns(

// hash transformed data
_ = md5::Md5::digest(harmless.trim());
_ = md5::Md5::digest(password.trim()); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
_ = md5::Md5::digest(password.trim()); // $ Alert[rust/weak-sensitive-data-hashing]
_ = md5::Md5::digest(harmless.as_bytes());
_ = md5::Md5::digest(password.as_bytes()); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
_ = md5::Md5::digest(password.as_bytes()); // $ Alert[rust/weak-sensitive-data-hashing]
_ = md5::Md5::digest(std::str::from_utf8(harmless_arr).unwrap());
_ = md5::Md5::digest(std::str::from_utf8(password_arr).unwrap()); // $ MISSING: Alert[rust/weak-sensitive-data-hashing]
}
Expand Down