Modify S2083(java): Improve the compliant sample (#3472)
This commit is contained in:
parent
7cb81aa05a
commit
f0db71d524
@ -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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user