Closed bigfish43tor closed 2 years ago
Good catch! Took me a while to take a look at this. You could do the following to make it work.
libsast -p .\rules\test.yaml .\src\ --ignore-paths src/to_ignore
Nevertheless this will be fixed in the next release.
Bug description
The implementation of the
--ignore-paths
option is not working correctly on Windows. Let’s assume our working directory isC:\Users\Administrator\Documents\project
and includes the following directories and files:rules\test.yaml
src\to_ignore\file_to_ignore.txt
Contents of test.yaml:
Contents of file_to_ignore.txt:
test
Libsast command executed in in powershell:
libsast -p .\rules\test.yaml .\src\ --ignore-paths src\to_ignore
Expected behavior
Libsast should ignore the path and not display any output.
Actual behavior
Libsast does not ignore the path and outputs the following:
Solution
The
validate_file()
function withinscanner.py
is implemented in the following way:ignore_paths = any(pp in path.as_posix() for pp in self.ignore_paths)
As a result, you check if an ignored path (=string) is found in a posix representation of the file path. This check will work on *nix systems, but not on Windows because backslashes are used to separate directories and files within the path.
Please consider converting the
pp
variable to a Path and using the posix representation for pp as well so you compare the same path representations with each other.