Skip to content

Commit 1cb9f63

Browse files
smowtonam0o0
authored andcommitted
Use hasTaintFlow marker
1 parent 059a138 commit 1cb9f63

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

java/ql/test/experimental/query-tests/security/CWE-022/src/main/java/com/PathInjection/CommonsIOPathInjection.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ public String value() {
2020

2121
public class CommonsIOPathInjection {
2222
public void PathInjection(Path src, File srcF) throws IOException {
23-
AsynchronousFileChannel.open(src); // $ PathInjection
24-
AsynchronousFileChannel.open(src, LinkOption.NOFOLLOW_LINKS); // $ PathInjection
23+
AsynchronousFileChannel.open(src); // $ hasTaintFlow
24+
AsynchronousFileChannel.open(src, LinkOption.NOFOLLOW_LINKS); // $ hasTaintFlow
2525
AsynchronousFileChannel.open(
26-
src, LinkOption.NOFOLLOW_LINKS, LinkOption.NOFOLLOW_LINKS); // $ PathInjection
26+
src, LinkOption.NOFOLLOW_LINKS, LinkOption.NOFOLLOW_LINKS); // $ hasTaintFlow
2727
ExecutorService executor = Executors.newFixedThreadPool(10);
2828
AsynchronousFileChannel.open(
29-
src, Set.of(LinkOption.NOFOLLOW_LINKS), executor); // $ PathInjection
29+
src, Set.of(LinkOption.NOFOLLOW_LINKS), executor); // $ hasTaintFlow
3030
AsynchronousFileChannel.open(
31-
src, // $ PathInjection
31+
src, // $ hasTaintFlow
3232
Set.of(LinkOption.NOFOLLOW_LINKS),
3333
executor,
3434
new fileAttr());
3535

36-
FileSystems.getFileSystem(srcF.toURI()); // $ PathInjection
36+
FileSystems.getFileSystem(srcF.toURI()); // $ hasTaintFlow
3737
}
3838
}

java/ql/test/experimental/query-tests/security/CWE-022/src/main/java/com/PathInjection/S3PathInjection.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public String uploadFile(URI filePathURI) {
1919
UploadFileRequest.builder()
2020
.putObjectRequest(b -> b.bucket(this.bucketName).key(this.key))
2121
.addTransferListener(LoggingTransferListener.create())
22-
.source(Paths.get(filePathURI)) // $ PathInjection
22+
.source(Paths.get(filePathURI)) // $ hasTaintFlow
2323
.build();
2424

2525
FileUpload fileUpload = this.transferManager.uploadFile(uploadFileRequest);
@@ -33,18 +33,18 @@ public String uploadFileResumable(URI filePathURI) {
3333
UploadFileRequest.builder()
3434
.putObjectRequest(b -> b.bucket(this.bucketName).key(this.key))
3535
.addTransferListener(LoggingTransferListener.create())
36-
.source(Paths.get(filePathURI)) // $ PathInjection
36+
.source(Paths.get(filePathURI)) // $ hasTaintFlow
3737
.build();
3838

3939
// Initiate the transfer
4040
FileUpload upload = this.transferManager.uploadFile(uploadFileRequest);
4141
// Pause the upload
4242
ResumableFileUpload resumableFileUpload = upload.pause();
4343
// Optionally, persist the resumableFileUpload
44-
resumableFileUpload.serializeToFile(Paths.get(filePathURI)); // $ PathInjection
44+
resumableFileUpload.serializeToFile(Paths.get(filePathURI)); // $ hasTaintFlow
4545
// Retrieve the resumableFileUpload from the file
4646
ResumableFileUpload persistedResumableFileUpload =
47-
ResumableFileUpload.fromFile(Paths.get(filePathURI)); // $ PathInjection
47+
ResumableFileUpload.fromFile(Paths.get(filePathURI)); // $ hasTaintFlow
4848
// Resume the upload
4949
FileUpload resumedUpload = this.transferManager.resumeUploadFile(persistedResumableFileUpload);
5050
// Wait for the transfer to complete
@@ -59,18 +59,18 @@ public String downloadFileResumable(URI downloadedFileWithPath) {
5959
DownloadFileRequest.builder()
6060
.getObjectRequest(b -> b.bucket(this.bucketName).key(this.key))
6161
.addTransferListener(LoggingTransferListener.create())
62-
.destination(Paths.get(downloadedFileWithPath)) // $ PathInjection
62+
.destination(Paths.get(downloadedFileWithPath)) // $ hasTaintFlow
6363
.build();
6464

6565
// Initiate the transfer
6666
FileDownload download = this.transferManager.downloadFile(downloadFileRequest);
6767
// Pause the download
6868
ResumableFileDownload resumableFileDownload = download.pause();
6969
// Optionally, persist the resumableFileDownload
70-
resumableFileDownload.serializeToFile(Paths.get(downloadedFileWithPath)); // $ PathInjection
70+
resumableFileDownload.serializeToFile(Paths.get(downloadedFileWithPath)); // $ hasTaintFlow
7171
// Retrieve the resumableFileDownload from the file
7272
ResumableFileDownload persistedResumableFileDownload =
73-
ResumableFileDownload.fromFile(Paths.get(downloadedFileWithPath)); // $ PathInjection
73+
ResumableFileDownload.fromFile(Paths.get(downloadedFileWithPath)); // $ hasTaintFlow
7474
// Resume the download
7575
FileDownload resumedDownload =
7676
this.transferManager.resumeDownloadFile(persistedResumableFileDownload);
@@ -85,7 +85,7 @@ public Integer uploadDirectory(URI sourceDirectory) {
8585
DirectoryUpload directoryUpload =
8686
this.transferManager.uploadDirectory(
8787
UploadDirectoryRequest.builder()
88-
.source(Paths.get(sourceDirectory)) // $ PathInjection
88+
.source(Paths.get(sourceDirectory)) // $ hasTaintFlow
8989
.bucket(this.bucketName)
9090
.build());
9191

@@ -98,7 +98,7 @@ public Long downloadFile(String downloadedFileWithPath) {
9898
DownloadFileRequest.builder()
9999
.getObjectRequest(b -> b.bucket(this.bucketName).key(this.key))
100100
.addTransferListener(LoggingTransferListener.create())
101-
.destination(Paths.get(downloadedFileWithPath)) // $ PathInjection
101+
.destination(Paths.get(downloadedFileWithPath)) // $ hasTaintFlow
102102
.build();
103103

104104
FileDownload downloadFile = this.transferManager.downloadFile(downloadFileRequest);
@@ -111,7 +111,7 @@ public Integer downloadObjectsToDirectory(URI destinationPathURI) {
111111
DirectoryDownload directoryDownload =
112112
this.transferManager.downloadDirectory(
113113
DownloadDirectoryRequest.builder()
114-
.destination(Paths.get(destinationPathURI)) // $ PathInjection
114+
.destination(Paths.get(destinationPathURI)) // $ hasTaintFlow
115115
.bucket(this.bucketName)
116116
.build());
117117
CompletedDirectoryDownload completedDirectoryDownload =

java/ql/test/experimental/query-tests/security/CWE-022/src/main/java/com/PathInjection/SpringIoPathInjection.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ public void PathInjection(String path) throws IOException {
1818
Path filePath = fileStorageLocation.resolve(path).normalize();
1919
File pathFile = new File(path);
2020

21-
new UrlResource(filePath.toUri()); // $ PathInjection
22-
new UrlResource(filePath.toUri().toURL()); // $ PathInjection
23-
new UrlResource("file", path); // $ PathInjection
24-
new UrlResource("file", path, "#"); // $ PathInjection
25-
new UrlResource(path); // $ PathInjection
26-
27-
new PathResource(path); // $ PathInjection
28-
new PathResource(filePath); // $ PathInjection
29-
new PathResource(filePath.toUri()); // $ PathInjection
30-
31-
new FileUrlResource(filePath.toUri().toURL()); // $ PathInjection
32-
new FileUrlResource(path); // $ PathInjection
33-
34-
new FileSystemResource(pathFile); // $ PathInjection
35-
new FileSystemResource(path); // $ PathInjection
36-
new FileSystemResource(filePath); // $ PathInjection
21+
new UrlResource(filePath.toUri()); // $ hasTaintFlow
22+
new UrlResource(filePath.toUri().toURL()); // $ hasTaintFlow
23+
new UrlResource("file", path); // $ hasTaintFlow
24+
new UrlResource("file", path, "#"); // $ hasTaintFlow
25+
new UrlResource(path); // $ hasTaintFlow
26+
27+
new PathResource(path); // $ hasTaintFlow
28+
new PathResource(filePath); // $ hasTaintFlow
29+
new PathResource(filePath.toUri()); // $ hasTaintFlow
30+
31+
new FileUrlResource(filePath.toUri().toURL()); // $ hasTaintFlow
32+
new FileUrlResource(path); // $ hasTaintFlow
33+
34+
new FileSystemResource(pathFile); // $ hasTaintFlow
35+
new FileSystemResource(path); // $ hasTaintFlow
36+
new FileSystemResource(filePath); // $ hasTaintFlow
3737
new FileSystemResource(
38-
FileSystems.getFileSystem(URI.create("file:///")), path); // $ PathInjection
39-
40-
FileSystemUtils.copyRecursively(filePath, filePath.resolve("/newPath")); // $ PathInjection
41-
FileSystemUtils.copyRecursively(pathFile, pathFile); // $ PathInjection
42-
FileSystemUtils.deleteRecursively(pathFile); // $ PathInjection
43-
FileSystemUtils.deleteRecursively(filePath); // $ PathInjection
44-
FileCopyUtils.copy(pathFile, pathFile); // $ PathInjection
45-
FileCopyUtils.copyToByteArray(pathFile); // $ PathInjection
38+
FileSystems.getFileSystem(URI.create("file:///")), path); // $ hasTaintFlow
39+
40+
FileSystemUtils.copyRecursively(filePath, filePath.resolve("/newPath")); // $ hasTaintFlow
41+
FileSystemUtils.copyRecursively(pathFile, pathFile); // $ hasTaintFlow
42+
FileSystemUtils.deleteRecursively(pathFile); // $ hasTaintFlow
43+
FileSystemUtils.deleteRecursively(filePath); // $ hasTaintFlow
44+
FileCopyUtils.copy(pathFile, pathFile); // $ hasTaintFlow
45+
FileCopyUtils.copyToByteArray(pathFile); // $ hasTaintFlow
4646
}
4747
}

0 commit comments

Comments
 (0)