Skip to content

Commit 02b9229

Browse files
committed
Rust: Update StartswithCall.
1 parent 6941e7f commit 02b9229

File tree

2 files changed

+4
-4
lines changed
  • rust/ql
    • lib/codeql/rust/frameworks/stdlib
    • test/query-tests/security/CWE-022/src

2 files changed

+4
-4
lines changed

rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private import codeql.rust.internal.PathResolution
1414
*/
1515
private class StartswithCall extends Path::SafeAccessCheck::Range, CfgNodes::MethodCallExprCfgNode {
1616
StartswithCall() {
17-
this.getAstNode().(Resolvable).getResolvedPath() = "<crate::path::Path>::starts_with"
17+
this.getMethodCallExpr().getStaticTarget().getCanonicalPath() = "<std::path::Path>::starts_with"
1818
}
1919

2020
override predicate checks(Cfg::CfgNode e, boolean branch) {

rust/ql/test/query-tests/security/CWE-022/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn tainted_path_handler_folder_good(Query(file_path): Query<String>) -> Result<S
2929
if !file_path.starts_with(public_path) {
3030
return Err(Error::from_status(StatusCode::BAD_REQUEST));
3131
}
32-
fs::read_to_string(file_path).map_err(InternalServerError) // $ path-injection-checked path-injection-sink
32+
fs::read_to_string(file_path).map_err(InternalServerError) // $ path-injection-sink MISSING: path-injection-checked
3333
}
3434

3535
//#[handler]
@@ -42,7 +42,7 @@ fn tainted_path_handler_folder_almost_good1(
4242
if !file_path.starts_with(public_path) {
4343
return Err(Error::from_status(StatusCode::BAD_REQUEST));
4444
}
45-
fs::read_to_string(file_path).map_err(InternalServerError) // $ path-injection-checked path-injection-sink MISSING: Alert[rust/path-injection]=remote2 -- we cannot resolve the `join` call above, because it needs a `PathBuf -> Path` `Deref`
45+
fs::read_to_string(file_path).map_err(InternalServerError) // $ path-injection-sink MISSING: path-injection-checked Alert[rust/path-injection]=remote2 -- we cannot resolve the `join` call above, because it needs a `PathBuf -> Path` `Deref`
4646
}
4747

4848
//#[handler]
@@ -54,7 +54,7 @@ fn tainted_path_handler_folder_good_simpler(Query(file_path): Query<String>) ->
5454
if !file_path.starts_with(public_path) {
5555
return Err(Error::from_status(StatusCode::BAD_REQUEST));
5656
}
57-
fs::read_to_string(file_path).map_err(InternalServerError) // $ path-injection-checked path-injection-sink
57+
fs::read_to_string(file_path).map_err(InternalServerError) // $ path-injection-sink MISSING: path-injection-checked
5858
}
5959

6060
//#[handler]

0 commit comments

Comments
 (0)