Skip to content

Commit db91a25

Browse files
committed
Safe Asset Access:
- Added tests for checking invalid access: Issue1639
1 parent 89ec039 commit db91a25

4 files changed

Lines changed: 62 additions & 1 deletion

File tree

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- Remove Router.assets(String) to force user to say from where asset should read
44
- Add check to ClassPathAssetSource and reject root classpath access
5-
5+
- Added tests for checking invalid access: Issue1639
66

77
* MVC: QueryParam annotation vs PathParam try to figure it out them and make optional (update open api)
88
* MVC: introduce BodyParam

jooby/src/main/java/io/jooby/Router.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ interface Match {
598598
* - file-system if the source folder exists in the current user directory
599599
* - or fallback to classpath when file-system folder doesn't exist.
600600
*
601+
* NOTE: This method choose file-system or classpath, it doesn't merge them.
602+
*
601603
* @param pattern Path pattern.
602604
* @param source File-System folder when exists, or fallback to a classpath folder.
603605
* @return A route.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.jooby;
2+
3+
import io.jooby.junit.ServerTest;
4+
import io.jooby.junit.ServerTestRunner;
5+
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
public class Issue1639 {
12+
13+
@ServerTest
14+
public void shouldNotAccessToClassFromFileSystemAsset(ServerTestRunner runner) {
15+
runner.define(app -> {
16+
app.assets("/static/?*", userdir("src", "test", "resources", "static"));
17+
}).ready(client -> {
18+
client.get("/static/js/index.js", rsp -> {
19+
assertEquals("(function () { console.log('index.js');});", rsp.body().string().trim());
20+
});
21+
22+
client.get("/static/io/jooby/Issue1639.js.class", rsp -> {
23+
assertEquals(404, rsp.code());
24+
});
25+
26+
client.get("/static/io/jooby/Issue1639.class", rsp -> {
27+
assertEquals(404, rsp.code());
28+
});
29+
});
30+
}
31+
32+
@ServerTest
33+
public void shouldNotAccessToClassFromCpAssetSource(ServerTestRunner runner) {
34+
runner.define(app -> {
35+
app.assets("/static/?*", "/static");
36+
}).ready(client -> {
37+
client.get("/static/js/index.js", rsp -> {
38+
assertEquals("(function () { console.log('index.js');});", rsp.body().string().trim());
39+
});
40+
41+
client.get("/static/../io/jooby/Issue1639.class", rsp -> {
42+
assertEquals(404, rsp.code());
43+
});
44+
45+
client.get("/static/..%252fio/jooby/Issue1639.class", rsp -> {
46+
assertEquals(404, rsp.code());
47+
});
48+
});
49+
}
50+
51+
private static Path userdir(String... segments) {
52+
Path path = Paths.get(System.getProperty("user.dir"));
53+
for (String segment : segments) {
54+
path = path.resolve(segment);
55+
}
56+
return path;
57+
}
58+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(function () { console.log('index.js');});

0 commit comments

Comments
 (0)