Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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
4 changes: 4 additions & 0 deletions rust/ql/lib/change-notes/2025-08-22-fs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Improved modelling of the `std::fs`, `async_std::fs` and `tokio::fs` libraries. This may cause more alerts to be found by Rust injection queries, particularly `rust/path-injection`.
42 changes: 42 additions & 0 deletions rust/ql/lib/codeql/rust/frameworks/asyncstd/fs.model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
extensions:
- addsTo:
pack: codeql/rust-all
extensible: sourceModel
data:
- ["async_std::fs::read::read", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
- ["async_std::fs::read_to_string::read_to_string", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
- ["async_std::fs::read_link::read_link", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
- ["<async_std::fs::dir_entry::DirEntry>::path", "ReturnValue", "file", "manual"]
- ["<async_std::fs::dir_entry::DirEntry>::file_name", "ReturnValue", "file", "manual"]
- ["<async_std::fs::file::File>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
- ["<async_std::fs::open_options::OpenOptions>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
- addsTo:
pack: codeql/rust-all
extensible: sinkModel
data:
- ["async_std::fs::copy::copy", "Argument[0,1]", "path-injection", "manual"]
- ["async_std::fs::create_dir::create_dir", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::create_dir_all::create_dir_all", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::hard_link::hard_link", "Argument[0,1]", "path-injection", "manual"]
- ["async_std::fs::metadata::metadata", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::read::read", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::read_dir::read_dir", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::read_link::read_link", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::read_to_string::read_to_string", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::remove_dir::remove_dir", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::remove_dir_all::remove_dir_all", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::remove_file::remove_file", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::rename::rename", "Argument[0,1]", "path-injection", "manual"]
- ["async_std::fs::set_permissions::set_permissions", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::symlink_metadata::symlink_metadata", "Argument[0]", "path-injection", "manual"]
- ["async_std::fs::write::write", "Argument[0]", "path-injection", "manual"]
- ["<async_std::fs::dir_builder::DirBuilder>::create", "Argument[0]", "path-injection", "manual"]
- ["<async_std::fs::file::File>::create", "Argument[0]", "path-injection", "manual"]
- ["<async_std::fs::file::File>::open", "Argument[0]", "path-injection", "manual"]
- ["<async_std::fs::open_options::OpenOptions>::open", "Argument[0]", "path-injection", "manual"]
- addsTo:
pack: codeql/rust-all
extensible: summaryModel
data:
- ["async_std::fs::canonicalize::canonicalize", "Argument[0].OptionalStep[normalize-path]", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["async_std::fs::canonicalize::canonicalize", "Argument[0].OptionalBarrier[normalize-path]", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "taint", "manual"]
41 changes: 30 additions & 11 deletions rust/ql/lib/codeql/rust/frameworks/stdlib/fs.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ extensions:
- ["<std::fs::DirEntry>::file_name", "ReturnValue", "file", "manual"]
- ["<std::fs::File>::open", "ReturnValue.Field[core::result::Result::Ok(0)]", "file", "manual"]
- ["<std::fs::File>::open_buffered", "ReturnValue.Field[core::result::Result::Ok(0)]", "file", "manual"]
- ["<std::fs::OpenOptions>::open", "ReturnValue.Field[core::result::Result::Ok(0)]", "file", "manual"]
- addsTo:
pack: codeql/rust-all
extensible: sinkModel
data:
- ["std::fs::copy", "Argument[0]", "path-injection", "manual"]
- ["std::fs::copy", "Argument[1]", "path-injection", "manual"]
- ["std::fs::copy", "Argument[0,1]", "path-injection", "manual"]
- ["std::fs::create_dir", "Argument[0]", "path-injection", "manual"]
- ["std::fs::create_dir_all", "Argument[0]", "path-injection", "manual"]
- ["std::fs::hard_link", "Argument[0]", "path-injection", "manual"]
- ["std::fs::hard_link", "Argument[1]", "path-injection", "manual"]
- ["std::fs::hard_link", "Argument[0,1]", "path-injection", "manual"]
- ["std::fs::metadata", "Argument[0]", "path-injection", "manual"]
- ["std::fs::read", "Argument[0]", "path-injection", "manual"]
- ["std::fs::read_dir", "Argument[0]", "path-injection", "manual"]
Expand All @@ -28,11 +27,9 @@ extensions:
- ["std::fs::remove_dir", "Argument[0]", "path-injection", "manual"]
- ["std::fs::remove_dir_all", "Argument[0]", "path-injection", "manual"]
- ["std::fs::remove_file", "Argument[0]", "path-injection", "manual"]
- ["std::fs::rename", "Argument[0]", "path-injection", "manual"]
- ["std::fs::rename", "Argument[1]", "path-injection", "manual"]
- ["std::fs::rename", "Argument[0,1]", "path-injection", "manual"]
- ["std::fs::set_permissions", "Argument[0]", "path-injection", "manual"]
- ["std::fs::soft_link", "Argument[0]", "path-injection", "manual"]
- ["std::fs::soft_link", "Argument[1]", "path-injection", "manual"]
- ["std::fs::soft_link", "Argument[0,1]", "path-injection", "manual"]
- ["std::fs::symlink_metadata", "Argument[0]", "path-injection", "manual"]
- ["std::fs::write", "Argument[0]", "path-injection", "manual"]
- ["<std::fs::DirBuilder>::create", "Argument[0]", "path-injection", "manual"]
Expand All @@ -41,12 +38,34 @@ extensions:
- ["<std::fs::File>::create_new", "Argument[0]", "path-injection", "manual"]
- ["<std::fs::File>::open", "Argument[0]", "path-injection", "manual"]
- ["<std::fs::File>::open_buffered", "Argument[0]", "path-injection", "manual"]
- ["<std::fs::OpenOptions>::open", "Argument[0]", "path-injection", "manual"]
- addsTo:
pack: codeql/rust-all
extensible: summaryModel
data:
- ["<std::path::PathBuf as core::convert::From>::from", "Argument[0]", "ReturnValue", "taint", "manual"]
- ["std::fs::canonicalize", "Argument[0].OptionalStep[normalize-path]", "ReturnValue.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["std::fs::canonicalize", "Argument[0].OptionalBarrier[normalize-path]", "ReturnValue.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["<std::path::PathBuf as core::convert::From>::from", "Argument[0]", "ReturnValue", "value", "manual"]
- ["<std::path::PathBuf>::as_path", "Argument[Self]", "ReturnValue.Reference", "value", "manual"]
- ["<std::path::PathBuf>::as_mut_os_string", "Argument[Self].Reference", "ReturnValue.Reference", "value", "manual"]
- ["<std::path::PathBuf>::into_os_string", "Argument[Self]", "ReturnValue", "value", "manual"]
- ["<std::path::PathBuf>::into_boxed_path", "Argument[Self]", "ReturnValue.Reference", "value", "manual"]
- ["<std::path::Path>::new", "Argument[0].Reference", "ReturnValue.Reference", "value", "manual"]
- ["<std::path::Path>::join", "Argument[self]", "ReturnValue", "taint", "manual"]
- ["<std::path::Path>::join", "Argument[0]", "ReturnValue", "taint", "manual"]
- ["<std::path::Path>::canonicalize", "Argument[self].OptionalStep[normalize-path]", "ReturnValue.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["<std::path::Path>::canonicalize", "Argument[self].OptionalBarrier[normalize-path]", "ReturnValue.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["<std::path::Path>::as_os_string", "Argument[Self].Reference", "ReturnValue.Reference", "value", "manual"]
- ["<std::path::Path>::as_mut_os_string", "Argument[Self].Reference", "ReturnValue.Reference", "value", "manual"]
- ["<std::path::Path>::canonicalize", "Argument[self].Reference.OptionalStep[normalize-path]", "ReturnValue.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["<std::path::Path>::canonicalize", "Argument[self].Reference.OptionalBarrier[normalize-path]", "ReturnValue.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["<std::path::Path>::extension", "Argument[Self].Reference", "ReturnValue.Field[core::option::Option::Some(0)].Reference", "taint", "manual"]
- ["<std::path::Path>::file_name", "Argument[Self].Reference", "ReturnValue.Field[core::option::Option::Some(0)].Reference", "taint", "manual"]
- ["<std::path::Path>::file_prefix", "Argument[Self].Reference", "ReturnValue.Field[core::option::Option::Some(0)].Reference", "taint", "manual"]
- ["<std::path::Path>::file_stem", "Argument[Self].Reference", "ReturnValue.Field[core::option::Option::Some(0)].Reference", "taint", "manual"]
- ["<std::path::Path>::into_path_buf", "Argument[Self].Reference", "ReturnValue", "value", "manual"]
- ["<std::path::Path>::parent", "Argument[Self].Reference", "ReturnValue.Field[core::option::Option::Some(0)].Reference", "taint", "manual"]
- ["<std::path::Path>::to_path_buf", "Argument[Self].Reference", "ReturnValue", "value", "manual"]
- ["<std::path::Path>::to_str", "Argument[Self].Reference", "ReturnValue.Field[core::option::Option::Some(0)].Reference", "value", "manual"]
- ["<std::path::Path>::with_added_extension", "Argument[Self].Reference", "ReturnValue", "taint", "manual"]
- ["<std::path::Path>::with_extension", "Argument[Self].Reference", "ReturnValue", "taint", "manual"]
- ["<std::path::Path>::with_file_name", "Argument[Self].Reference", "ReturnValue", "taint", "manual"]
- ["<std::path::Path>::with_file_name", "Argument[0]", "ReturnValue", "taint", "manual"]
36 changes: 36 additions & 0 deletions rust/ql/lib/codeql/rust/frameworks/tokio/fs.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,39 @@ extensions:
- ["<tokio::fs::read_dir::DirEntry>::path", "ReturnValue", "file", "manual"]
- ["<tokio::fs::read_dir::DirEntry>::file_name", "ReturnValue", "file", "manual"]
- ["<tokio::fs::file::File>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
- ["<tokio::fs::open_options::OpenOptions>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
- addsTo:
pack: codeql/rust-all
extensible: sinkModel
data:
- ["tokio::fs::copy::copy", "Argument[0,1]", "path-injection", "manual"]
- ["tokio::fs::create_dir::create_dir", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::create_dir_all::create_dir_all", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::hard_link::hard_link", "Argument[0,1]", "path-injection", "manual"]
- ["tokio::fs::metadata::metadata", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::read::read", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::read_dir::read_dir", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::read_link::read_link", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::read_to_string::read_to_string", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::remove_dir::remove_dir", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::remove_dir_all::remove_dir_all", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::remove_file::remove_file", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::rename::rename", "Argument[0,1]", "path-injection", "manual"]
- ["tokio::fs::set_permissions::set_permissions", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::symlink::symlink", "Argument[0,1]", "path-injection", "manual"]
- ["tokio::fs::symlink_dir::symlink_dir", "Argument[0,1]", "path-injection", "manual"]
- ["tokio::fs::symlink_file::symlink_file", "Argument[0,1]", "path-injection", "manual"]
- ["tokio::fs::symlink_metadata::symlink_metadata", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::try_exists::try_exists", "Argument[0]", "path-injection", "manual"]
- ["tokio::fs::write::write", "Argument[0]", "path-injection", "manual"]
- ["<tokio::fs::dir_builder::DirBuilder>::create", "Argument[0]", "path-injection", "manual"]
- ["<tokio::fs::file::File>::create", "Argument[0]", "path-injection", "manual"]
- ["<tokio::fs::file::File>::create_new", "Argument[0]", "path-injection", "manual"]
- ["<tokio::fs::file::File>::open", "Argument[0]", "path-injection", "manual"]
- ["<tokio::fs::open_options::OpenOptions>::open", "Argument[0]", "path-injection", "manual"]
- addsTo:
pack: codeql/rust-all
extensible: summaryModel
data:
- ["tokio::fs::canonicalize::canonicalize", "Argument[0].OptionalStep[normalize-path]", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "taint", "manual"]
- ["tokio::fs::canonicalize::canonicalize", "Argument[0].OptionalBarrier[normalize-path]", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "taint", "manual"]
60 changes: 34 additions & 26 deletions rust/ql/test/library-tests/dataflow/sources/TaintSources.expected
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,40 @@
| test.rs:413:31:413:38 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:418:22:418:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:418:22:418:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:424:22:424:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:425:27:425:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:431:22:431:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:440:31:440:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:445:31:445:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:450:22:450:46 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:456:26:456:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:456:26:456:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:457:31:457:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:457:31:457:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:463:22:463:41 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:473:20:473:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:507:21:507:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:508:21:508:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:516:21:516:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:528:20:528:40 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:575:21:575:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:576:21:576:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:584:21:584:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:601:26:601:53 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:620:26:620:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:672:28:672:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:754:22:754:49 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:780:22:780:50 | ...::new | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:807:16:807:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
| test.rs:807:16:807:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
| test.rs:425:22:425:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:439:27:439:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:450:22:450:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:451:27:451:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:461:22:461:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:470:31:470:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:475:31:475:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:480:22:480:46 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:486:26:486:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:486:26:486:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:487:31:487:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:487:31:487:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:493:22:493:41 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:503:20:503:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:536:50:536:53 | open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:543:67:543:70 | open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:550:101:550:104 | open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:560:21:560:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:561:21:561:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:569:21:569:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:581:20:581:40 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:627:52:627:55 | open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:637:21:637:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:638:21:638:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:646:21:646:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:660:20:660:44 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:671:56:671:59 | open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:688:26:688:53 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:707:26:707:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:759:28:759:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:841:22:841:49 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:867:22:867:50 | ...::new | Flow source 'RemoteSource' of type remote (DEFAULT). |
| test.rs:894:16:894:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
| test.rs:894:16:894:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
| test_futures_io.rs:19:15:19:32 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
| web_frameworks.rs:11:31:11:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
| web_frameworks.rs:11:31:11:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
Expand Down
Loading