File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -123,9 +123,22 @@ fn verify_base_dir(folder: &Path) -> Result<PathBuf> {
123123 path = dunce:: canonicalize ( & path)
124124 . with_context ( || format ! ( "Could not canonicalize {path:?}" ) ) ?;
125125
126+ //check whether it still stars with cwd
127+ if !path. starts_with ( & cwd) {
128+ anyhow:: bail!( "Provided path escapes the current working directory: {path:?}" ) ;
129+ }
130+
126131 if path. is_file ( ) {
127132 anyhow:: bail!( "Provided path is a file, expected a directory: {path:?}" ) ;
128133 }
134+ } else if let Some ( parent) = path. parent ( ) {
135+ let canonical_parent = dunce:: canonicalize ( parent)
136+ . with_context ( || format ! ( "Could not canonicalize parent directory {parent:?}" ) ) ?;
137+ if !canonical_parent. starts_with ( & cwd) {
138+ anyhow:: bail!( "Provided path resolves outside the current working directory: {path:?}" ) ;
139+ }
140+ } else {
141+ anyhow:: bail!( "Provided path has no valid parent directory: {path:?}" ) ;
129142 }
130143
131144 Ok ( path)
You can’t perform that action at this time.
0 commit comments