Skip to content

Commit 66df351

Browse files
authored
Merge commit from fork
Restrict property accessing to disallow fetching properties from restricted bases
2 parents 3c3ecc2 + c4c7331 commit 66df351

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/main/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public Class<?> getType(ELContext context, Object base, Object property) {
7979

8080
@Override
8181
public Object getValue(ELContext context, Object base, Object property) {
82+
if (isRestrictedClass(base)) {
83+
return null;
84+
}
8285
Object result = super.getValue(context, base, validatePropertyName(property));
8386
return result instanceof Class ? null : result;
8487
}

src/test/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolverTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.common.collect.ImmutableSet;
99
import com.hubspot.jinjava.JinjavaConfig;
1010
import com.hubspot.jinjava.el.JinjavaELContext;
11+
import com.hubspot.jinjava.interpret.AutoCloseableSupplier;
1112
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
1213
import javax.el.ELContext;
1314
import javax.el.MethodNotFoundException;
@@ -173,4 +174,16 @@ public void itThrowsExceptionWhenPropertyIsRestrictedFromConfig() {
173174
.hasMessageStartingWith("Could not find property");
174175
JinjavaInterpreter.popCurrent();
175176
}
177+
178+
@Test
179+
public void itDoesNotAllowAccessingPropertiesOfInterpreter() {
180+
try (
181+
AutoCloseableSupplier.AutoCloseableImpl<JinjavaInterpreter> c = JinjavaInterpreter
182+
.closeablePushCurrent(interpreter)
183+
.get()
184+
) {
185+
assertThat(jinjavaBeanELResolver.getValue(elContext, interpreter, "config"))
186+
.isNull();
187+
}
188+
}
176189
}

src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,10 @@ public void itOutputsUndefinedVariableError() {
600600
assertThat(outputtingErrorInterpreters.getErrors().get(0).getCategoryErrors())
601601
.isEqualTo(ImmutableMap.of("variable", "bar"));
602602
}
603+
604+
@Test
605+
public void itDoesNotAllowAccessingPropertiesOfInterpreter() {
606+
assertThat(jinjava.render("{{ ____int3rpr3t3r____.config }}", new HashMap<>()))
607+
.isEqualTo("");
608+
}
603609
}

0 commit comments

Comments
 (0)