Skip to content

Commit 444e836

Browse files
authored
resource-task: Use the shared IOUtils assertInPath method for resource lookups (#1204)
1 parent e29adb7 commit 444e836

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

plugins/tasks/resource/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
<artifactId>concord-runtime-sdk-v2</artifactId>
2626
<scope>provided</scope>
2727
</dependency>
28+
<dependency>
29+
<groupId>com.walmartlabs.concord</groupId>
30+
<artifactId>concord-common</artifactId>
31+
<scope>provided</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.commons</groupId>
35+
<artifactId>commons-compress</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
2838
<dependency>
2939
<groupId>javax.inject</groupId>
3040
<artifactId>javax.inject</artifactId>

plugins/tasks/resource/src/main/java/com/walmartlabs/concord/plugins/resource/ResourceTaskCommon.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
import java.io.OutputStream;
3434
import java.nio.file.Files;
3535
import java.nio.file.Path;
36-
import java.nio.file.Paths;
3736
import java.util.Arrays;
3837
import java.util.HashMap;
3938
import java.util.Map;
4039
import java.util.Properties;
4140

41+
import static com.walmartlabs.concord.common.IOUtils.assertInPath;
42+
4243
public class ResourceTaskCommon {
4344

4445
private static final String RESOURCE_PREFIX = "resource_";
@@ -233,25 +234,15 @@ public static String prettyPrintYaml(Object value, int indent) throws IOExceptio
233234
}
234235

235236
private Path normalizePath(String path) {
236-
Path p = Paths.get(path);
237-
if (p.isAbsolute()) {
238-
return p;
239-
}
240-
return workDir.resolve(path);
237+
return assertWorkDirPath(path);
241238
}
242239

243240
private Path assertWorkDirPath(String path) {
244-
if (path == null) {
245-
throw new IllegalArgumentException("Path cannot be null");
246-
}
247-
Path dst = Paths.get(path);
248-
if (!dst.isAbsolute()) {
249-
dst = workDir.resolve(path).normalize().toAbsolutePath();
250-
}
251-
if (!dst.startsWith(workDir)) {
252-
throw new IllegalArgumentException("Invalid path: " + path);
241+
try {
242+
return assertInPath(workDir,path);
243+
} catch (IOException ex) {
244+
throw new IllegalArgumentException("Not authorized to access file outside of working directory: " + path);
253245
}
254-
return dst;
255246
}
256247

257248
private static ObjectWriter createYamlWriter() {

0 commit comments

Comments
 (0)