Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
272 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jooby.internal; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public interface AssetSource { | ||
URL getResource(String name); | ||
|
||
static AssetSource fromClassPath(ClassLoader loader, String source) { | ||
if (Strings.isNullOrEmpty(source) || "/".equals(source.trim())) { | ||
throw new IllegalArgumentException( | ||
"For security reasons root classpath access is not allowed: " + source); | ||
} | ||
return path -> { | ||
URL resource = loader.getResource(path); | ||
if (resource == null) { | ||
return null; | ||
} | ||
String realPath = resource.getPath(); | ||
if (realPath.startsWith(source)) { | ||
return resource; | ||
} | ||
return null; | ||
}; | ||
} | ||
|
||
static AssetSource fromFileSystem(Path basedir) { | ||
return name -> { | ||
Path path = basedir.resolve(name).normalize(); | ||
if (Files.exists(path) && path.startsWith(basedir)) { | ||
try { | ||
return path.toUri().toURL(); | ||
} catch (MalformedURLException x) { | ||
// shh | ||
} | ||
} | ||
return null; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
modules/coverage-report/src/test/java/org/jooby/issues/Issue1639.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jooby.issues; | ||
|
||
import org.jooby.test.ServerFeature; | ||
import org.junit.Test; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class Issue1639 extends ServerFeature { | ||
|
||
{ | ||
Path dir = Paths.get(System.getProperty("user.dir"), "src", "test", "resources", "assets"); | ||
assertTrue(Files.exists(dir)); | ||
assets("/static/**", dir); | ||
} | ||
|
||
@Test | ||
public void shouldNotFallbackToArbitraryClasspathResources() throws Exception { | ||
request() | ||
.get("/static/WEB-INF/web2.xml") | ||
.expect(404); | ||
|
||
request() | ||
.get("/static/../WEB-INF/web2.xml") | ||
.expect(404); | ||
} | ||
|
||
} |
Oops, something went wrong.