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

Hardening suggestions for WebGoat_12_23 / objectmapper-1 #117

Open
wants to merge 3 commits into
base: objectmapper-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<xstream.version>1.4.5</xstream.version>
<!-- do not update necessary for lesson -->
<zxcvbn.version>1.5.2</zxcvbn.version>
<versions.java-security-toolkit>1.2.0</versions.java-security-toolkit>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -248,6 +249,11 @@
<artifactId>jruby</artifactId>
<version>9.3.6.0</version>
</dependency>
<dependency>
<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit</artifactId>
<version>${versions.java-security-toolkit}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -393,6 +399,10 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit</artifactId>
</dependency>
</dependencies>

<repositories>
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/owasp/webgoat/webwolf/FileServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.owasp.webgoat.webwolf;

import io.github.pixee.security.Filenames;
import static org.springframework.http.MediaType.ALL_VALUE;

import java.io.File;
Expand Down Expand Up @@ -79,8 +80,8 @@ public ModelAndView importFile(@RequestParam("file") MultipartFile myFile) throw
var user = (WebGoatUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
var destinationDir = new File(fileLocation, user.getUsername());
destinationDir.mkdirs();
myFile.transferTo(new File(destinationDir, myFile.getOriginalFilename()));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped the file name with a sanitizer call that takes out path escaping characters

log.debug("File saved to {}", new File(destinationDir, myFile.getOriginalFilename()));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped the file name with a sanitizer call that takes out path escaping characters

myFile.transferTo(new File(destinationDir, Filenames.toSimpleFileName(myFile.getOriginalFilename())));
log.debug("File saved to {}", new File(destinationDir, Filenames.toSimpleFileName(myFile.getOriginalFilename())));

return new ModelAndView(
new RedirectView("files", true),
Expand Down Expand Up @@ -126,18 +127,12 @@ public ModelAndView getFiles(HttpServletRequest request) {
return modelAndView;
}

private void print2() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unused private method.

String x = "test";
if (x.equals("test")) {
System.out.println("Hello, World!");
}
System.out.println("Hola");
}

public static class EncryptionExample {

public byte[] encrypt(String text) throws Exception {
int a, b, c;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split variable declarations into their own statements.

int a;
int b;
int c;
System.out.println("Hola");

a = 2;
Expand Down