diff --git a/languages/java/custom/models/path-injection.model.yml b/languages/java/custom/models/path-injection.model.yml new file mode 100644 index 00000000..bdeeae42 --- /dev/null +++ b/languages/java/custom/models/path-injection.model.yml @@ -0,0 +1,31 @@ +extensions: + - addsTo: + pack: codeql/java-all + extensible: sinkModel + data: + # Servlet multipart upload: `Part.write(fileName)` writes the uploaded content to `fileName`. + - ["jakarta.servlet.http", "Part", True, "write", "(String)", "", "Argument[0]", "path-injection", "manual"] + - ["javax.servlet.http", "Part", True, "write", "(String)", "", "Argument[0]", "path-injection", "manual"] + # Spring multipart upload: `MultipartFile.transferTo(dest)` writes the uploaded content to `dest`. + - [ + "org.springframework.web.multipart", + "MultipartFile", + True, + "transferTo", + "(File)", + "", + "Argument[0]", + "path-injection", + "manual" + ] + - [ + "org.springframework.web.multipart", + "MultipartFile", + True, + "transferTo", + "(Path)", + "", + "Argument[0]", + "path-injection", + "manual" + ] diff --git a/languages/java/custom/models/qlpack.yml b/languages/java/custom/models/qlpack.yml new file mode 100644 index 00000000..1dac0733 --- /dev/null +++ b/languages/java/custom/models/qlpack.yml @@ -0,0 +1,7 @@ +name: languages-java-custom-models +version: 0.0.1 +library: true +extensionTargets: + codeql/java-all: "*" +dataExtensions: + - "**/*.model.yml" diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/ContentDispositionUpload.java b/languages/java/custom/test/PathInjectionUsernameUpload/ContentDispositionUpload.java new file mode 100644 index 00000000..b7f236ff --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/ContentDispositionUpload.java @@ -0,0 +1,36 @@ +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.function.Supplier; +import org.springframework.web.multipart.MultipartFile; + +// Upload handler that stores the file under a fixed root using the raw client-supplied +// original file name, via a shared helper that resolves the name against the root. +public class ContentDispositionUpload { + private Path contentDispositionRoot = Paths.get("/content-disposition/"); + + private Path root = Paths.get("/static/uploads/"); + + private static String store(Path root, String fileName, Supplier validator, MultipartFile file) + throws IOException { + if (validator.get()) { + Files.copy(file.getInputStream(), root.resolve(fileName), StandardCopyOption.REPLACE_EXISTING); // $ Alert + return fileName; + } + return null; + } + + public String uploadContentDisposition(MultipartFile file) throws IOException { + return store(contentDispositionRoot, file.getOriginalFilename(), () -> true, file); // $ Source + } + + public String uploadPrefixed(MultipartFile file) throws IOException { + return store(root, System.nanoTime() + "_" + file.getOriginalFilename(), () -> true, file); // $ Source + } + + public String uploadSafe(MultipartFile file) throws IOException { + return store(root, java.util.UUID.randomUUID() + ".png", () -> true, file); + } +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/JakartaServletUpload.java b/languages/java/custom/test/PathInjectionUsernameUpload/JakartaServletUpload.java new file mode 100644 index 00000000..ada6798e --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/JakartaServletUpload.java @@ -0,0 +1,16 @@ +import java.io.IOException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.Part; + +public class JakartaServletUpload { + private final String uploadDir = "/var/app/uploads"; + + public void doPost(HttpServletRequest request) throws IOException { + String username = request.getParameter("username"); // $ Source + Part part = request.getPart("file"); + + part.write(uploadDir + "/" + username + ".png"); // $ Alert + + part.write(uploadDir + "/avatar.png"); + } +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/JavaxServletUpload.java b/languages/java/custom/test/PathInjectionUsernameUpload/JavaxServletUpload.java new file mode 100644 index 00000000..c4bb4dcd --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/JavaxServletUpload.java @@ -0,0 +1,16 @@ +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.Part; + +public class JavaxServletUpload { + private final String uploadDir = "/var/app/uploads"; + + public void doPost(HttpServletRequest request) throws IOException { + String username = request.getParameter("username"); // $ Source + Part part = request.getPart("file"); + + part.write(uploadDir + "/" + username + ".png"); // $ Alert + + part.write(uploadDir + "/avatar.png"); + } +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/ProfileController.java b/languages/java/custom/test/PathInjectionUsernameUpload/ProfileController.java new file mode 100644 index 00000000..6973da87 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/ProfileController.java @@ -0,0 +1,81 @@ +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Paths; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; + +@Controller +public class ProfileController { + private final String uploadDir = "/var/app/resources/images"; + + private String storedUsername = "alice"; + + @RequestMapping("/profile") + public String processProfile( + @RequestParam(value = "username", required = true) String username, // $ Source + @RequestParam(value = "file", required = false) MultipartFile file) + throws IOException { + String extension = ".png"; + + // String concatenation into `new File(String)` then `MultipartFile.transferTo(File)` + String path = uploadDir + File.separator + username + extension; + file.transferTo(new File(path)); // $ Alert + + File dest = new File(uploadDir + "/" + username + ".png"); + file.transferTo(dest); // $ Alert + + // `new File(File, String)` child argument + file.transferTo(new File(new File(uploadDir), username + ".png")); // $ Alert + + // `MultipartFile.transferTo(Path)` + file.transferTo(Paths.get(uploadDir, username + ".png")); // $ Alert + file.transferTo(Paths.get(uploadDir).resolve(username + ".png")); // $ Alert + + // Already detected without custom models: `File` constructor summary into a built-in sink + new FileOutputStream(new File(uploadDir + "/" + username + ".png")).close(); // $ Alert + + return "profile"; + } + + @RequestMapping("/profile/update") + public String updateProfile( + @RequestParam(value = "username", required = true) String username, // $ Source + @RequestParam(value = "file", required = false) MultipartFile file) // $ Source + throws IOException { + // An equality check on one branch does not sanitize the merged path below + if (!username.equals(storedUsername)) { + storedUsername = username.toLowerCase(); + } + + if (file != null && !file.isEmpty()) { + String extension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); // $ Source + String path = uploadDir + File.separator + username + extension; + file.transferTo(new File(path)); // $ Alert + } + + return "profile"; + } + + @RequestMapping("/profile/safe") + public String processProfileSafe( + @RequestParam(value = "username", required = true) String username, + @RequestParam(value = "file", required = false) MultipartFile file) + throws IOException { + // Constant destination: not tainted + file.transferTo(new File(uploadDir + "/avatar.png")); + + // Value that does not come from the request: not a source + file.transferTo(new File(uploadDir + "/" + storedUsername + ".png")); + + // Path traversal check sanitizes the request value + if (username.contains("..") || username.contains("/") || username.contains("\\")) { + return "error"; + } + file.transferTo(new File(uploadDir + "/" + username + ".png")); + + return "profile"; + } +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.expected b/languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.expected new file mode 100644 index 00000000..2c13271b --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.expected @@ -0,0 +1,89 @@ +#select +| ContentDispositionUpload.java:19:47:19:68 | resolve(...) | ContentDispositionUpload.java:26:46:26:71 | getOriginalFilename(...) : String | ContentDispositionUpload.java:19:47:19:68 | resolve(...) | This path depends on a $@. | ContentDispositionUpload.java:26:46:26:71 | getOriginalFilename(...) | user-provided value | +| ContentDispositionUpload.java:19:47:19:68 | resolve(...) | ContentDispositionUpload.java:30:54:30:79 | getOriginalFilename(...) : String | ContentDispositionUpload.java:19:47:19:68 | resolve(...) | This path depends on a $@. | ContentDispositionUpload.java:30:54:30:79 | getOriginalFilename(...) | user-provided value | +| JakartaServletUpload.java:12:20:12:54 | ... + ... | JakartaServletUpload.java:9:27:9:58 | getParameter(...) : String | JakartaServletUpload.java:12:20:12:54 | ... + ... | This path depends on a $@. | JakartaServletUpload.java:9:27:9:58 | getParameter(...) | user-provided value | +| JavaxServletUpload.java:12:20:12:54 | ... + ... | JavaxServletUpload.java:9:27:9:58 | getParameter(...) : String | JavaxServletUpload.java:12:20:12:54 | ... + ... | This path depends on a $@. | JavaxServletUpload.java:9:27:9:58 | getParameter(...) | user-provided value | +| ProfileController.java:25:25:25:38 | new File(...) | ProfileController.java:18:13:18:78 | username : String | ProfileController.java:25:25:25:38 | new File(...) | This path depends on a $@. | ProfileController.java:18:13:18:78 | username | user-provided value | +| ProfileController.java:28:25:28:28 | dest | ProfileController.java:18:13:18:78 | username : String | ProfileController.java:28:25:28:28 | dest | This path depends on a $@. | ProfileController.java:18:13:18:78 | username | user-provided value | +| ProfileController.java:31:25:31:72 | new File(...) | ProfileController.java:18:13:18:78 | username : String | ProfileController.java:31:25:31:72 | new File(...) | This path depends on a $@. | ProfileController.java:18:13:18:78 | username | user-provided value | +| ProfileController.java:34:25:34:63 | get(...) | ProfileController.java:18:13:18:78 | username : String | ProfileController.java:34:25:34:63 | get(...) | This path depends on a $@. | ProfileController.java:18:13:18:78 | username | user-provided value | +| ProfileController.java:35:25:35:71 | resolve(...) | ProfileController.java:18:13:18:78 | username : String | ProfileController.java:35:25:35:71 | resolve(...) | This path depends on a $@. | ProfileController.java:18:13:18:78 | username | user-provided value | +| ProfileController.java:38:30:38:74 | new File(...) | ProfileController.java:18:13:18:78 | username : String | ProfileController.java:38:30:38:74 | new File(...) | This path depends on a $@. | ProfileController.java:18:13:18:78 | username | user-provided value | +| ProfileController.java:56:29:56:42 | new File(...) | ProfileController.java:45:13:45:78 | username : String | ProfileController.java:56:29:56:42 | new File(...) | This path depends on a $@. | ProfileController.java:45:13:45:78 | username | user-provided value | +| ProfileController.java:56:29:56:42 | new File(...) | ProfileController.java:46:13:46:78 | file : MultipartFile | ProfileController.java:56:29:56:42 | new File(...) | This path depends on a $@. | ProfileController.java:46:13:46:78 | file | user-provided value | +| ProfileController.java:56:29:56:42 | new File(...) | ProfileController.java:54:32:54:57 | getOriginalFilename(...) : String | ProfileController.java:56:29:56:42 | new File(...) | This path depends on a $@. | ProfileController.java:54:32:54:57 | getOriginalFilename(...) | user-provided value | +edges +| ContentDispositionUpload.java:16:44:16:58 | fileName : String | ContentDispositionUpload.java:19:60:19:67 | fileName : String | provenance | | +| ContentDispositionUpload.java:19:60:19:67 | fileName : String | ContentDispositionUpload.java:19:47:19:68 | resolve(...) | provenance | MaD:12 Sink:MaD:3 | +| ContentDispositionUpload.java:26:46:26:71 | getOriginalFilename(...) : String | ContentDispositionUpload.java:16:44:16:58 | fileName : String | provenance | Src:MaD:9 | +| ContentDispositionUpload.java:30:28:30:79 | ... + ... : String | ContentDispositionUpload.java:16:44:16:58 | fileName : String | provenance | | +| ContentDispositionUpload.java:30:54:30:79 | getOriginalFilename(...) : String | ContentDispositionUpload.java:30:28:30:79 | ... + ... : String | provenance | Src:MaD:9 | +| JakartaServletUpload.java:9:27:9:58 | getParameter(...) : String | JakartaServletUpload.java:12:20:12:54 | ... + ... | provenance | Src:MaD:7 Sink:MaD:1 | +| JavaxServletUpload.java:9:27:9:58 | getParameter(...) : String | JavaxServletUpload.java:12:20:12:54 | ... + ... | provenance | Src:MaD:8 Sink:MaD:4 | +| ProfileController.java:18:13:18:78 | username : String | ProfileController.java:25:34:25:37 | path : String | provenance | | +| ProfileController.java:18:13:18:78 | username : String | ProfileController.java:27:30:27:64 | ... + ... : String | provenance | | +| ProfileController.java:18:13:18:78 | username : String | ProfileController.java:31:25:31:72 | new File(...) | provenance | AdditionalTaintStep Sink:MaD:5 | +| ProfileController.java:18:13:18:78 | username : String | ProfileController.java:34:46:34:62 | ... + ... : String | provenance | | +| ProfileController.java:18:13:18:78 | username : String | ProfileController.java:35:54:35:70 | ... + ... : String | provenance | | +| ProfileController.java:18:13:18:78 | username : String | ProfileController.java:38:39:38:73 | ... + ... : String | provenance | | +| ProfileController.java:25:34:25:37 | path : String | ProfileController.java:25:25:25:38 | new File(...) | provenance | MaD:10 Sink:MaD:5 | +| ProfileController.java:27:21:27:65 | new File(...) : File | ProfileController.java:28:25:28:28 | dest | provenance | Sink:MaD:5 | +| ProfileController.java:27:30:27:64 | ... + ... : String | ProfileController.java:27:21:27:65 | new File(...) : File | provenance | MaD:10 | +| ProfileController.java:34:25:34:63 | new ..[] { .. } : String[] [[]] : String | ProfileController.java:34:25:34:63 | get(...) | provenance | MaD:13 Sink:MaD:6 | +| ProfileController.java:34:46:34:62 | ... + ... : String | ProfileController.java:34:25:34:63 | new ..[] { .. } : String[] [[]] : String | provenance | | +| ProfileController.java:35:54:35:70 | ... + ... : String | ProfileController.java:35:25:35:71 | resolve(...) | provenance | MaD:12 Sink:MaD:6 | +| ProfileController.java:38:39:38:73 | ... + ... : String | ProfileController.java:38:30:38:74 | new File(...) | provenance | MaD:10 Sink:MaD:2 | +| ProfileController.java:45:13:45:78 | username : String | ProfileController.java:56:38:56:41 | path : String | provenance | | +| ProfileController.java:46:13:46:78 | file : MultipartFile | ProfileController.java:54:32:54:35 | file : MultipartFile | provenance | | +| ProfileController.java:54:32:54:35 | file : MultipartFile | ProfileController.java:54:32:54:57 | getOriginalFilename(...) : String | provenance | MaD:14 | +| ProfileController.java:54:32:54:57 | getOriginalFilename(...) : String | ProfileController.java:54:32:54:112 | substring(...) : String | provenance | Src:MaD:9 MaD:11 | +| ProfileController.java:54:32:54:112 | substring(...) : String | ProfileController.java:56:38:56:41 | path : String | provenance | | +| ProfileController.java:56:38:56:41 | path : String | ProfileController.java:56:29:56:42 | new File(...) | provenance | MaD:10 Sink:MaD:5 | +models +| 1 | Sink: jakarta.servlet.http; Part; true; write; (String); ; Argument[0]; path-injection; manual | +| 2 | Sink: java.io; FileOutputStream; false; FileOutputStream; ; ; Argument[0]; path-injection; manual | +| 3 | Sink: java.nio.file; Files; false; copy; (InputStream,Path,CopyOption[]); ; Argument[1]; path-injection; manual | +| 4 | Sink: javax.servlet.http; Part; true; write; (String); ; Argument[0]; path-injection; manual | +| 5 | Sink: org.springframework.web.multipart; MultipartFile; true; transferTo; (File); ; Argument[0]; path-injection; manual | +| 6 | Sink: org.springframework.web.multipart; MultipartFile; true; transferTo; (Path); ; Argument[0]; path-injection; manual | +| 7 | Source: jakarta.servlet; ServletRequest; false; getParameter; (String); ; ReturnValue; remote; manual | +| 8 | Source: javax.servlet; ServletRequest; false; getParameter; (String); ; ReturnValue; remote; manual | +| 9 | Source: org.springframework.web.multipart; MultipartFile; true; getOriginalFilename; (); ; ReturnValue; remote; manual | +| 10 | Summary: java.io; File; false; File; ; ; Argument[0]; Argument[this]; taint; manual | +| 11 | Summary: java.lang; String; false; substring; ; ; Argument[this]; ReturnValue; taint; manual | +| 12 | Summary: java.nio.file; Path; true; resolve; ; ; Argument[0]; ReturnValue; taint; manual | +| 13 | Summary: java.nio.file; Paths; true; get; ; ; Argument[1].ArrayElement; ReturnValue; taint; manual | +| 14 | Summary: org.springframework.web.multipart; MultipartFile; true; getOriginalFilename; ; ; Argument[this]; ReturnValue; taint; manual | +nodes +| ContentDispositionUpload.java:16:44:16:58 | fileName : String | semmle.label | fileName : String | +| ContentDispositionUpload.java:19:47:19:68 | resolve(...) | semmle.label | resolve(...) | +| ContentDispositionUpload.java:19:60:19:67 | fileName : String | semmle.label | fileName : String | +| ContentDispositionUpload.java:26:46:26:71 | getOriginalFilename(...) : String | semmle.label | getOriginalFilename(...) : String | +| ContentDispositionUpload.java:30:28:30:79 | ... + ... : String | semmle.label | ... + ... : String | +| ContentDispositionUpload.java:30:54:30:79 | getOriginalFilename(...) : String | semmle.label | getOriginalFilename(...) : String | +| JakartaServletUpload.java:9:27:9:58 | getParameter(...) : String | semmle.label | getParameter(...) : String | +| JakartaServletUpload.java:12:20:12:54 | ... + ... | semmle.label | ... + ... | +| JavaxServletUpload.java:9:27:9:58 | getParameter(...) : String | semmle.label | getParameter(...) : String | +| JavaxServletUpload.java:12:20:12:54 | ... + ... | semmle.label | ... + ... | +| ProfileController.java:18:13:18:78 | username : String | semmle.label | username : String | +| ProfileController.java:25:25:25:38 | new File(...) | semmle.label | new File(...) | +| ProfileController.java:25:34:25:37 | path : String | semmle.label | path : String | +| ProfileController.java:27:21:27:65 | new File(...) : File | semmle.label | new File(...) : File | +| ProfileController.java:27:30:27:64 | ... + ... : String | semmle.label | ... + ... : String | +| ProfileController.java:28:25:28:28 | dest | semmle.label | dest | +| ProfileController.java:31:25:31:72 | new File(...) | semmle.label | new File(...) | +| ProfileController.java:34:25:34:63 | get(...) | semmle.label | get(...) | +| ProfileController.java:34:25:34:63 | new ..[] { .. } : String[] [[]] : String | semmle.label | new ..[] { .. } : String[] [[]] : String | +| ProfileController.java:34:46:34:62 | ... + ... : String | semmle.label | ... + ... : String | +| ProfileController.java:35:25:35:71 | resolve(...) | semmle.label | resolve(...) | +| ProfileController.java:35:54:35:70 | ... + ... : String | semmle.label | ... + ... : String | +| ProfileController.java:38:30:38:74 | new File(...) | semmle.label | new File(...) | +| ProfileController.java:38:39:38:73 | ... + ... : String | semmle.label | ... + ... : String | +| ProfileController.java:45:13:45:78 | username : String | semmle.label | username : String | +| ProfileController.java:46:13:46:78 | file : MultipartFile | semmle.label | file : MultipartFile | +| ProfileController.java:54:32:54:35 | file : MultipartFile | semmle.label | file : MultipartFile | +| ProfileController.java:54:32:54:57 | getOriginalFilename(...) : String | semmle.label | getOriginalFilename(...) : String | +| ProfileController.java:54:32:54:112 | substring(...) : String | semmle.label | substring(...) : String | +| ProfileController.java:56:29:56:42 | new File(...) | semmle.label | new File(...) | +| ProfileController.java:56:38:56:41 | path : String | semmle.label | path : String | +subpaths diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.qlref b/languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.qlref new file mode 100644 index 00000000..574c8395 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.qlref @@ -0,0 +1,4 @@ +query: Security/CWE/CWE-022/TaintedPath.ql +postprocess: + - utils/test/PrettyPrintModels.ql + - utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/ServletRequest.java b/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/ServletRequest.java new file mode 100644 index 00000000..41453abd --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/ServletRequest.java @@ -0,0 +1,5 @@ +package jakarta.servlet; + +public interface ServletRequest { + String getParameter(String name); +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/HttpServletRequest.java b/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/HttpServletRequest.java new file mode 100644 index 00000000..416c9110 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/HttpServletRequest.java @@ -0,0 +1,7 @@ +package jakarta.servlet.http; + +import jakarta.servlet.ServletRequest; + +public interface HttpServletRequest extends ServletRequest { + Part getPart(String name); +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/Part.java b/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/Part.java new file mode 100644 index 00000000..8729c9de --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/Part.java @@ -0,0 +1,9 @@ +package jakarta.servlet.http; + +import java.io.IOException; + +public interface Part { + String getSubmittedFileName(); + + void write(String fileName) throws IOException; +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/ServletRequest.java b/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/ServletRequest.java new file mode 100644 index 00000000..ec72d7c2 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/ServletRequest.java @@ -0,0 +1,5 @@ +package javax.servlet; + +public interface ServletRequest { + String getParameter(String name); +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/HttpServletRequest.java b/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/HttpServletRequest.java new file mode 100644 index 00000000..07ad951e --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/HttpServletRequest.java @@ -0,0 +1,7 @@ +package javax.servlet.http; + +import javax.servlet.ServletRequest; + +public interface HttpServletRequest extends ServletRequest { + Part getPart(String name); +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/Part.java b/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/Part.java new file mode 100644 index 00000000..6c83dc03 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/Part.java @@ -0,0 +1,9 @@ +package javax.servlet.http; + +import java.io.IOException; + +public interface Part { + String getSubmittedFileName(); + + void write(String fileName) throws IOException; +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/stereotype/Controller.java b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/stereotype/Controller.java new file mode 100644 index 00000000..1a95c7d2 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/stereotype/Controller.java @@ -0,0 +1,12 @@ +package org.springframework.stereotype; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Controller { + String value() default ""; +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestMapping.java b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestMapping.java new file mode 100644 index 00000000..ff9ba598 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestMapping.java @@ -0,0 +1,12 @@ +package org.springframework.web.bind.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface RequestMapping { + String[] value() default {}; +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestParam.java b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestParam.java new file mode 100644 index 00000000..b1ce0344 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestParam.java @@ -0,0 +1,14 @@ +package org.springframework.web.bind.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +public @interface RequestParam { + String value() default ""; + + boolean required() default true; +} diff --git a/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/multipart/MultipartFile.java b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/multipart/MultipartFile.java new file mode 100644 index 00000000..e6c47fb0 --- /dev/null +++ b/languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/multipart/MultipartFile.java @@ -0,0 +1,20 @@ +package org.springframework.web.multipart; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; + +public interface MultipartFile { + String getName(); + + String getOriginalFilename(); + + boolean isEmpty(); + + InputStream getInputStream() throws IOException; + + void transferTo(File dest) throws IOException, IllegalStateException; + + default void transferTo(Path dest) throws IOException, IllegalStateException {} +} diff --git a/languages/java/custom/test/qlpack.yml b/languages/java/custom/test/qlpack.yml index 1e98673e..74ad651a 100644 --- a/languages/java/custom/test/qlpack.yml +++ b/languages/java/custom/test/qlpack.yml @@ -1,5 +1,7 @@ name: languages-java-custom-test version: 0.0.2 dependencies: + codeql/java-queries: "*" + languages-java-custom-models: ${workspace} languages-java-custom-src: ${workspace} extractor: java