Skip to content

Commit

Permalink
Modify S2083(java): Improve the compliant sample (#3472)
Browse files Browse the repository at this point in the history
  • Loading branch information
loris-s-sonarsource authored Nov 30, 2023
1 parent 7cb81aa commit f0db71d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rules/S2083/java/how-to-fix-it/java-se.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public class ExampleController
@Controller
public class ExampleController
{
static private String targetDirectory = "/path/to/target/directory/";
private static String targetDirectory = "/path/to/target/directory/";
private static Path targetPath = new File(targetDirectory).toPath().normalize();
@GetMapping(value = "/delete")
public void delete(@RequestParam("filename") String filename) throws IOException {
File file = new File(targetDirectory + filename);
String canonicalDestinationPath = file.getCanonicalPath();
File file = new File(targetPath + filename);
if (!canonicalDestinationPath.startsWith(targetDirectory)) {
if (!file.toPath().normalize().startsWith(targetPath)) {
throw new IOException("Entry is outside of the target directory");
}
Expand Down

0 comments on commit f0db71d

Please sign in to comment.