codeql icon indicating copy to clipboard operation
codeql copied to clipboard

LGTM.com - false positive - Uncontrolled data used in path expression

Open alan-techdev opened this issue 5 years ago • 4 comments

Description of the false positive

Please take a look at this as in line 187 it gets the directory as a String from a message contextual property

Object directory = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_DIRECTORY);

the Directory can be any path . If we can say it is a tmp directory on the linux which will end up like "/tmp" If we follow the recommendation it is not applicable since the class AttachmentUtil has no idea what is being stored in the message contextual property ATTACHMENT_DIRECTORY)

URL to the alert on the project page on LGTM.com https://github.com/apache/cxf/pull/768/files#annotation_1255142036

https://lgtm.com/projects/g/apache/cxf/snapshot/018c47bd2be8213910b34d1cfb2aabf796c40b7e/files/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?sort=name&dir=ASC&mode=heatmap#x5d0eff0d14e724ce:1

alan-techdev avatar Apr 04 '21 11:04 alan-techdev

This doesn't seem like a false positive to me. Because any value can be stored in the message contextual property ATTACHMENT_DIRECTORY, this data is potentially tainted and should not be used without sanitizing. Before using the directory string, you will need to sanitize and remove any potentially dangerous components (eg- ..).

Or, are you saying that the output directory can be any location on the file system and so there is no security issue here? I am not familiar with this code. In general, this is bad practice, though in this specific case, it might be warranted.

aeisenberg avatar Apr 05 '21 16:04 aeisenberg

@aeisenberg thanks for commenting on the issue. Please look at the report bug also at CXF project Actually from the test cases the directory is a full path directory on the file system such as /tmp or /dev/null
As far as I can see from the Uncontrolled data used in path expression it states

Do not allow directory separators such as “/” or “\” (depending on the file system).

This is my main objection since it will break the code and make the java.io.File object as an invalid directory The test case uses "/dev/null"or "/tmp"
I will discuss the issue with the CXF contributors and see the actual usage of the directory . If you are saying apply the sanitize on ".." , this will be fine since the directory ( I am not sure but will double check) is a full path directory structure on the file system .

alan-techdev avatar Apr 05 '21 17:04 alan-techdev

The issue is sorted now by following the recommendation from @aeisenberg to remove dangerous component such as ".." from the directory name. There are still a list of 38 errors for the CXF project . I am going to create a separate issue for addressing this list on CXF Jira system . Many thanks for Andrew Eisenberg for his valuable feedback

alan-techdev avatar Apr 05 '21 19:04 alan-techdev

Happy to help. 🎉

aeisenberg avatar Apr 05 '21 19:04 aeisenberg