|
| 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 | +} |
0 commit comments