Skip to content

Commit 4b9296f

Browse files
author
Sam Pullara
committed
Object handlers should not give access to Object.class methods and fields
1 parent f1460ff commit 4b9296f

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

builder/src/test/java/com/sampullara/mustache/InterpreterTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ int taxed_value() {
5858
assertEquals(getContents(root, "simple.txt"), sw.toString());
5959
}
6060

61+
public void testSecurity() throws MustacheException, IOException, ExecutionException, InterruptedException {
62+
MustacheBuilder c = new MustacheBuilder(root);
63+
Mustache m = c.parseFile("security.html");
64+
StringWriter sw = new StringWriter();
65+
FutureWriter writer = new FutureWriter(sw);
66+
m.execute(writer, new Scope(new Object() {
67+
String name = "Chris";
68+
int value = 10000;
69+
70+
int taxed_value() {
71+
return (int) (this.value - (this.value * 0.4));
72+
}
73+
74+
boolean in_ca = true;
75+
}));
76+
writer.flush();
77+
assertEquals(getContents(root, "security.txt"), sw.toString());
78+
}
79+
6180
public void testXSS() throws MustacheException, IOException, ExecutionException, InterruptedException {
6281
MustacheBuilder c = new MustacheBuilder(root);
6382
Mustache m = c.parseFile("xss.html");

src/test/resources/security.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{class.name}}{{getClass.getName}}

src/test/resources/security.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)