Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Security Finding: Path/Directory Traversal (CWE-22, High Severity) in MultiPartFileUtils.java:33 #77

Open
2 tasks
joshn-whitesource-app bot opened this issue Feb 7, 2024 · 0 comments
Labels
Mend: code security findings Code security findings detected by Mend

Comments

@joshn-whitesource-app
Copy link
Contributor

joshn-whitesource-app bot commented Feb 7, 2024

Code Security Finding

This finding was first detected on 2023-12-06 01:34pm GMT and is still present in the last scan performed on 2024-02-15 10:26pm GMT:

SeverityVulnerability TypeCWEFileData Flows
HighPath/Directory Traversal

CWE-22

MultiPartFileUtils.java:33

3
Vulnerable Code

public static boolean writeFile(Part part, String savePath, String fileName) throws IOException {
boolean isConverted = false;
OutputStream out = null;
InputStream in = null;
try {
out = new FileOutputStream(savePath + File.separator + fileName);

3 Data Flow/s detected
View Data Flow 1

String fileName = MultiPartFileUtils.getFileName(filePart);

public static String getFileName(final Part part) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

String fileName = MultiPartFileUtils.getFileName(filePart);

MultiPartFileUtils.writeFile(filePart, savePath, fileName);

public static boolean writeFile(Part part, String savePath, String fileName) throws IOException {

out = new FileOutputStream(savePath + File.separator + fileName);

out = new FileOutputStream(savePath + File.separator + fileName);

View Data Flow 2

String fileName = MultiPartFileUtils.getFileName(filePart);

public static String getFileName(final Part part) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

String fileName = MultiPartFileUtils.getFileName(filePart);

boolean isConverted = MultiPartFileUtils.writeFile(filePart, savePath, fileName);

public static boolean writeFile(Part part, String savePath, String fileName) throws IOException {

out = new FileOutputStream(savePath + File.separator + fileName);

out = new FileOutputStream(savePath + File.separator + fileName);

View Data Flow 3

String fileName = MultiPartFileUtils.getFileName(filePart);

public static String getFileName(final Part part) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

for (String content : part.getHeader("content-disposition").split(";")) {

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");

String fileName = MultiPartFileUtils.getFileName(filePart);

boolean isConverted = MultiPartFileUtils.writeFile(filePart, savePath, fileName);

public static boolean writeFile(Part part, String savePath, String fileName) throws IOException {

out = new FileOutputStream(savePath + File.separator + fileName);

out = new FileOutputStream(savePath + File.separator + fileName);

Secure Code Warrior Training Material

● Training

   ▪ Secure Code Warrior Path/Directory Traversal Training

● Videos

   ▪ Secure Code Warrior Path/Directory Traversal Video

● Further Reading

   ▪ OWASP Path Traversal

   ▪ OWASP Input Validation Cheat Sheet

🏴 Suppress Finding
  • ... as False Alarm
  • ... as Acceptable Risk
@joshn-whitesource-app joshn-whitesource-app bot added the Mend: code security findings Code security findings detected by Mend label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mend: code security findings Code security findings detected by Mend
Projects
None yet
Development

No branches or pull requests

0 participants