Skip to content

Commit

Permalink
vuln check
Browse files Browse the repository at this point in the history
  • Loading branch information
integrationninjas committed Mar 1, 2024
1 parent 0779d09 commit e68b1d9
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.integrationninjas.springbootexample.controller;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -10,8 +13,6 @@
@RestController
public class TestController {

private static final String SECRET_API_KEY = "integrationninjas";

@GetMapping
public Object hello() {
Map<String, String> object = new HashMap<>();
Expand All @@ -20,13 +21,17 @@ public Object hello() {
return object;
}

@GetMapping("/secret")
public String getSecret(@RequestParam String apiKey) {
if (apiKey.equals(SECRET_API_KEY)) {
return "The secret data is: ...";
} else {
return "Unauthorized!";
@GetMapping("/readfile")
public String readFile(@RequestParam String fileName) {
StringBuilder content = new StringBuilder();
try {
Files.lines(Paths.get(fileName))
.forEach(line -> content.append(line).append("\n"));
// Files.lines() does not require explicit closing, but this comment illustrates the vulnerability.
} catch (IOException e) {
return "Error reading file: " + e.getMessage();
}
return "File content: " + content.toString();
}

}

0 comments on commit e68b1d9

Please sign in to comment.