-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
27 changed files
with
404 additions
and
47 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
coverage-report/src/test/java/org/jooby/ftl/Issue476FtlXss.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,29 @@ | ||
package org.jooby.ftl; | ||
|
||
import org.jooby.Results; | ||
import org.jooby.test.ServerFeature; | ||
import org.jooby.xss.XSS; | ||
import org.junit.Test; | ||
|
||
public class Issue476FtlXss extends ServerFeature { | ||
|
||
{ | ||
use(new XSS()); | ||
|
||
use(new Ftl()); | ||
|
||
get("/", req -> Results.html("org/jooby/ftl/xss").put("input", "<script>alert('xss');</script>")); | ||
} | ||
|
||
@Test | ||
public void xssFn() throws Exception { | ||
request() | ||
.get("/") | ||
.expect("<!DOCTYPE html>\n" + | ||
"<html>\n" + | ||
" <body><a href=\"javascript:hello('\u003Cscript\u003Ealert%28\u0027xss\u0027%29%3B\u003C\u002Fscript\u003E')\"></a>\n" + | ||
" </body>\n" + | ||
"</html>"); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
coverage-report/src/test/java/org/jooby/hbs/Issue476HbsXss.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.hbs; | ||
|
||
import org.jooby.Results; | ||
import org.jooby.test.ServerFeature; | ||
import org.jooby.xss.XSS; | ||
import org.junit.Test; | ||
|
||
public class Issue476HbsXss extends ServerFeature { | ||
|
||
{ | ||
use(new XSS()); | ||
|
||
use(new Hbs()); | ||
|
||
get("/", | ||
req -> Results.html("org/jooby/hbs/xss").put("input", "<script>alert('xss');</script>")); | ||
} | ||
|
||
@Test | ||
public void xssFn() throws Exception { | ||
request() | ||
.get("/") | ||
.expect("<!DOCTYPE html>\n" + | ||
"<html>\n" + | ||
" <body><a href=\"javascript:hello('\u003Cscript\u003Ealert%28\u0027xss\u0027%29%3B\u003C\u002Fscript\u003E')\"></a>\n" | ||
+ | ||
" </body>\n" + | ||
"</html>"); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
coverage-report/src/test/java/org/jooby/jade/Issue476JadeXss.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,29 @@ | ||
package org.jooby.jade; | ||
|
||
import org.jooby.Results; | ||
import org.jooby.test.ServerFeature; | ||
import org.jooby.xss.XSS; | ||
import org.junit.Test; | ||
|
||
public class Issue476JadeXss extends ServerFeature { | ||
|
||
{ | ||
use(new XSS()); | ||
|
||
use(new Jade(".html")); | ||
|
||
get("/", | ||
req -> Results.html("org/jooby/jade/xss").put("input", "<script>alert('xss');</script>")); | ||
} | ||
|
||
@Test | ||
public void xssFn() throws Exception { | ||
request() | ||
.get("/") | ||
.expect("<!DOCTYPE html>\n" + | ||
"<html>\n" + | ||
" <body><a href=\"javascript:hello('&#x5C;u003Cscript&#x5C;u003Ealert%28&#x5C;u0027xss&#x5C;u0027%29%3B&#x5C;u003C&#x5C;u002Fscript&#x5C;u003E')\"></a></body>\n" + | ||
"</html>"); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
coverage-report/src/test/java/org/jooby/pebble/Issue476PebbleXss.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,29 @@ | ||
package org.jooby.pebble; | ||
|
||
import org.jooby.Results; | ||
import org.jooby.test.ServerFeature; | ||
import org.jooby.xss.XSS; | ||
import org.junit.Test; | ||
|
||
public class Issue476PebbleXss extends ServerFeature { | ||
|
||
{ | ||
use(new XSS()); | ||
|
||
use(new Pebble()); | ||
|
||
get("/", req -> Results.html("org/jooby/pebble/xss").put("input", "<script>alert('xss');</script>")); | ||
} | ||
|
||
@Test | ||
public void xssFn() throws Exception { | ||
request() | ||
.get("/") | ||
.expect("<!DOCTYPE html>\n" + | ||
"<html>\n" + | ||
" <body><a href=\"javascript:hello('&#x5C;u003Cscript&#x5C;u003Ealert%28&#x5C;u0027xss&#x5C;u0027%29%3B&#x5C;u003C&#x5C;u002Fscript&#x5C;u003E')\"></a>\n" + | ||
" </body>\n" + | ||
"</html>"); | ||
} | ||
|
||
} |
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,5 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body><a href="javascript:hello('${xss(input, "js", "uri", "html")}')"></a> | ||
</body> | ||
</html> |
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,5 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body><a href="javascript:hello('{{xss input 'js' 'uri' 'html'}}')"></a> | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
coverage-report/src/test/resources/org/jooby/jade/xss.html.jade
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,4 @@ | ||
doctype html | ||
html | ||
body | ||
a(href= "javascript:hello('" + xss.apply(input, "js", "uri", "html") + "')") |
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,5 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body><a href="javascript:hello('{{xss (input, 'js', 'uri', 'html')}}')"></a> | ||
</body> | ||
</html> |
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
32 changes: 32 additions & 0 deletions
32
jooby-ftl/src/main/java/org/jooby/internal/ftl/XssDirective.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,32 @@ | ||
package org.jooby.internal.ftl; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jooby.Env; | ||
|
||
import freemarker.template.TemplateMethodModelEx; | ||
import freemarker.template.TemplateModelException; | ||
import freemarker.template.TemplateScalarModel; | ||
import javaslang.control.Try; | ||
|
||
public class XssDirective implements TemplateMethodModelEx { | ||
|
||
private Env env; | ||
|
||
public XssDirective(final Env env) { | ||
this.env = env; | ||
} | ||
|
||
@SuppressWarnings({"rawtypes", "unchecked" }) | ||
@Override | ||
public Object exec(final List arguments) throws TemplateModelException { | ||
List<String> args = (List<String>) arguments.stream() | ||
.map(it -> Try.of(() -> ((TemplateScalarModel) it).getAsString()).get()) | ||
.collect(Collectors.toList()); | ||
String[] xss = args.subList(1, args.size()) | ||
.toArray(new String[arguments.size() - 1]); | ||
return env.xss(xss).apply(args.get(0)); | ||
} | ||
|
||
} |
Oops, something went wrong.