You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LGTM.com - false positive - Zip Slip when guard FileNameUtils#normalize is used #9205
Depending on how sophisticated the guard detection should be, FileNameUtils#normalize might not on its own be enough to sanitize the path. In the code example you have shown, the code uses java.io.File to construct the path and therefore seems to be safe.
However, if code uses java.nio.file.Path, then FileNameUtils#normalize would not suffice for sanitization because Path.resolve behaves differently for absolute paths and paths with a different root component. For example on Windows:
So apparently FilenameUtils.normalize would only be a valid sanitizer if it's used directly on the user input AND the result is prefixed with a trusted path (i.e. not used as an absolute path), and Path.resolve is NOT used to do so.
Activity
hvitved commentedon May 19, 2022
@github/codeql-java one for you.
Marcono1234 commentedon May 21, 2022
Depending on how sophisticated the guard detection should be,
FileNameUtils#normalizemight not on its own be enough to sanitize the path. In the code example you have shown, the code usesjava.io.Fileto construct the path and therefore seems to be safe.However, if code uses
java.nio.file.Path, thenFileNameUtils#normalizewould not suffice for sanitization becausePath.resolvebehaves differently for absolute paths and paths with a different root component. For example on Windows:Note that I am not a member of this project.
atorralba commentedon May 23, 2022
Aside from what @Marcono1234 pointed out, depending on how
FilenameUtils.normalizeitself is used, it won't be a proper sanitizer either. For example:would return
/unsafe/.So apparently
FilenameUtils.normalizewould only be a valid sanitizer if it's used directly on the user input AND the result is prefixed with a trusted path (i.e. not used as an absolute path), andPath.resolveis NOT used to do so.