Skip to content

Commit cb615f2

Browse files
committed
Rust: tained path: improve example
1 parent 521e3e3 commit cb615f2

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

rust/ql/src/queries/security/CWE-022/examples/TaintedPathGoodFolder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{env::home_dir, fs, path::PathBuf};
55
fn tainted_path_handler(Query(file_path): Query<String>) -> Result<String, Error> {
66
let public_path = home_dir().unwrap().join("public");
77
let file_path = public_path.join(PathBuf::from(file_path));
8+
let file_path = file_path.canonicalize().unwrap();
89
// GOOD: ensure that the path stays within the public folder
910
if !file_path.starts_with(public_path) {
1011
return Err(Error::from_status(StatusCode::BAD_REQUEST));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn tainted_path_handler_folder_good(
2828
) -> Result<String> {
2929
let public_path = home_dir().unwrap().join("public");
3030
let file_path = public_path.join(PathBuf::from(file_path));
31+
let file_path = file_path.canonicalize().unwrap();
3132
// GOOD: ensure that the path stays within the public folder
3233
if !file_path.starts_with(public_path) {
3334
return Err(Error::from_status(StatusCode::BAD_REQUEST));

0 commit comments

Comments
 (0)