Skip to main content
Level 2
May 4, 2021 6:43 PM UTC

Adobe Cloud manager - Sonar issue - reads a file whose location might be specified by user input

Hi All,

 

We are seeing below issue in Sonar for below inline code, tried different approached but not able to resolve the issue:

 

Sonar Issue:

java/io/File.createTempFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File; reads a file whose location might be specified by user input

Vulnerability

Major

 

findsecbugs:PATH_TRAVERSAL_IN

cwe,owasp-a4,wasc

https://www.adobe.com/go/aem_cmcq_path_traversal_in_en

 

 

Code:

String fileName = pdfArray[pdfArray.length - 2];

File tempDir = Files.createTempDirectory(null).toFile();

File htmlFile = File.createTempFile(FilenameUtils.getName(fileName),PlatformConstants.HTML_SUFFIX, tempDir);

 

Thanks in advance

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

10 replies

SureshDhulipudi
Community Advisor
Community Advisor
May 5, 2021 1:24 AM UTC

Did you try creating a separate method for createFile

 

static File createTempDir(File parentDir) throws IOException {
return Files.createTempDirectory(<param1>, <param2>,<param3>);
}

Translate
Mar 22, 2022 3:40 PM UTC

We tried applying the above mentioned suggestions but still its showing the vulnerability in Sonar.

Error:::reads a file whose location might be specified by user input Vulnerability

Translate
Aug 28, 2023 7:03 PM UTC

Hello, were you able to solve the problem? I find myself with the same problem, the adaptations have already been added according to the documentation and it keeps showing me the error.

Translate
vjleo94
Level 3
Oct 31, 2024 3:31 PM UTC

Hi,

Were you able to find a solution for this ?

Please share.

Best regards,

Vijaya Kumar A

Translate
Level 2
Nov 27, 2024 2:07 PM UTC

Hello @1905403

 

Anyone could share solution for this?  Regards!

Translate
daniel-strmecki
Adobe Champion, Community Advisor, UG Leader
Adobe Champion, Community Advisor, UG Leader
Nov 27, 2024 8:40 PM UTC

Hi @toimrank,

this warning suggests a cross-site scripting vulnerability. Are you creating the fileName from any user-provided parameters, like GET params in a Sling Servlet?

 

Good luck,

Daniel

Translate
Nov 28, 2024 7:05 AM UTC

Hi @daniel-strmecki ,

 

Thanks for your support, it is not my case. It is a private method with local params. 

Regards,

Ana.

Translate
daniel-strmecki
Adobe Champion, Community Advisor, UG Leader
Adobe Champion, Community Advisor, UG Leader
Nov 28, 2024 7:40 AM UTC

Hi @ana_belénca,

not sure how "smart" this rule in SonarQube is, but in more advanced vulnerability scanning tools like Snyk would check all the places where you call the method and if you are passing any user-provided params.

 

Good luck,

Daniel

Translate
kautuk_sahni
Level 9
Dec 16, 2024 10:51 AM UTC

@toimrank Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Translate
Kautuk Sahni
Level 2
Dec 16, 2024 10:54 AM UTC

Hello @kautuk_sahni 

 

Finally we have to refactor all code, so we have not fixed this error. We cannot add a possible solution.

 

Regards,

Ana 

Translate