File tree Expand file tree Collapse file tree 4 files changed +31
-7
lines changed
src/main/java/com/lacunasoftware/pkiexpress Expand file tree Collapse file tree 4 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ PKI Express package for Java
44
55This 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
99The 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
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ targetCompatibility = JavaVersion.VERSION_1_7
1111
1212group = ' com.lacunasoftware.pkiexpress'
1313archivesBaseName = ' pki-express'
14- version = ' 1.22.1 '
14+ version = ' 1.22.2 '
1515
1616repositories {
1717 mavenCentral()
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 77import java .io .ByteArrayOutputStream ;
88import java .io .IOException ;
99import java .io .InputStream ;
10+ import java .nio .file .Files ;
11+ import java .nio .file .Path ;
1012import java .text .ParseException ;
1113import java .text .SimpleDateFormat ;
1214import 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}
You can’t perform that action at this time.
0 commit comments