Skip to content

Commit ec8375d

Browse files
committed
Merge branch 'develop'
2 parents 0e8b25b + 60a9e47 commit ec8375d

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PKI Express package for Java
44

55
This package contains classes that encapsulate the calls to the PKI Express.
66

7-
The **PKI Express package** is distributed by [Maven](https://search.maven.org/artifact/com.lacunasoftware.pkiexpress/pki-express/1.22.1/jar).
7+
The **PKI Express package** is distributed by [Maven](https://search.maven.org/artifact/com.lacunasoftware.pkiexpress/pki-express/1.22.2/jar).
88

99
The recommended way to install it is with Gradle:
1010

@@ -13,7 +13,7 @@ The recommended way to install it is with Gradle:
1313
}
1414

1515
dependencies {
16-
implementation 'com.lacunasoftware.pkiexpress:pki-express:1.22.1'
16+
implementation 'com.lacunasoftware.pkiexpress:pki-express:1.22.2'
1717
...
1818
}
1919

@@ -22,7 +22,7 @@ Or with Maven:
2222
<dependency>
2323
<groupId>com.lacunasoftware.pkiexpress</groupId>
2424
<artifactId>pki-express</artifactId>
25-
<version>1.22.1/version>
25+
<version>1.22.2/version>
2626
<type>pom</type>
2727
</dependency>
2828

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ targetCompatibility = JavaVersion.VERSION_1_7
1111

1212
group = 'com.lacunasoftware.pkiexpress'
1313
archivesBaseName = 'pki-express'
14-
version = '1.22.1'
14+
version = '1.22.2'
1515

1616
repositories {
1717
mavenCentral()

src/main/java/com/lacunasoftware/pkiexpress/SignatureFinisher.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ public void setTransferFilePath(String path) {
115115
}
116116

117117
public void setTransferFileId(String transferFileId) {
118-
if (!Files.exists(config.getTransferDataFolder().resolve(transferFileId))) {
119-
throw new RuntimeException("The provided transfer file was not found");
120-
}
118+
Util.validateFile(transferFileId, config.getTransferDataFolder());
121119
this.transferFileId = transferFileId;
122120
}
123121
//endregion

src/main/java/com/lacunasoftware/pkiexpress/Util.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.io.ByteArrayOutputStream;
88
import java.io.IOException;
99
import java.io.InputStream;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
1012
import java.text.ParseException;
1113
import java.text.SimpleDateFormat;
1214
import java.util.Arrays;
@@ -80,4 +82,28 @@ static Date parseApiDate(String dateStr) {
8082

8183
return date;
8284
}
85+
86+
static void validateFile(String userFile, Path baseDir) {
87+
try {
88+
// get normalized path
89+
Path basePath = baseDir.toRealPath();
90+
Path userPath = basePath.resolve(userFile).normalize();
91+
92+
// checks if user file path is child of base dir
93+
if (!userPath.startsWith(basePath)) {
94+
throw new RuntimeException("The provided file path is not valid");
95+
}
96+
97+
// checks if file exists
98+
if (!Files.exists(userPath)) {
99+
throw new RuntimeException("The provided file was not found");
100+
}
101+
102+
} catch (RuntimeException ex) {
103+
throw ex;
104+
105+
} catch (Exception ex) {
106+
throw new RuntimeException("Error validating file path", ex);
107+
}
108+
}
83109
}

0 commit comments

Comments
 (0)