Skip to content

Commit 934390f

Browse files
committed
disable java access to avoid execution of arbitrary (java) code
1 parent 0ffc3f7 commit 934390f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy;
3333

3434
import net.sourceforge.htmlunit.corejs.javascript.Callable;
35+
import net.sourceforge.htmlunit.corejs.javascript.ClassShutter;
3536
import net.sourceforge.htmlunit.corejs.javascript.Context;
3637
import net.sourceforge.htmlunit.corejs.javascript.ContextAction;
3738
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
@@ -274,6 +275,14 @@ protected Context makeContext() {
274275
final TimeoutContext cx = new TimeoutContext(this);
275276
cx.setLanguageVersion(Context.VERSION_ES6);
276277

278+
// make sure no java classes are usable from js
279+
cx.setClassShutter(new ClassShutter() {
280+
@Override
281+
public boolean visibleToScripts(final String fullClassName) {
282+
return false;
283+
}
284+
});
285+
277286
// Use pure interpreter mode to get observeInstructionCount() callbacks.
278287
cx.setOptimizationLevel(-1);
279288

src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ private void init(final WebWindow webWindow, final Context context) throws Excep
216216
}
217217

218218
// remove some objects, that Rhino defines in top scope but that we don't want
219-
deleteProperties(window, "java", "javax", "org", "com", "edu", "net",
220-
"JavaAdapter", "JavaImporter", "Continuation", "Packages", "getClass");
219+
deleteProperties(window, "Continuation");
221220
if (!browserVersion.hasFeature(JS_XML)) {
222221
deleteProperties(window, "XML", "XMLList", "Namespace", "QName");
223222
}

0 commit comments

Comments
 (0)