Skip to content

Commit bc1f58d

Browse files
committed
Security: prevent Rhinos access to Java resources; e.g. call java methods
1 parent 4237700 commit bc1f58d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/changes/changes.xml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="2.37.0" date="xxxx, 2020" description="Bugfixes, CHROME 79, FF52 removed, FF68 added">
11+
<action type="fix" dev="rbri">
12+
Security: prevent Rhinos access to Java resources; e.g. call java methods.
13+
</action>
1114
<action type="update" dev="rbri">
1215
Upgrade Apache HttpComponents to 4.5.11.
1316
</action>

src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java

+50
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import static org.junit.Assert.fail;
1818

19+
import java.net.URL;
20+
1921
import org.junit.Test;
2022
import org.junit.runner.RunWith;
2123
import org.openqa.selenium.By;
@@ -891,4 +893,52 @@ public void ctorBooleanDocumentAll() throws Exception {
891893

892894
loadPageWithAlerts2(html);
893895
}
896+
897+
/**
898+
* @throws Exception if the test fails
899+
*/
900+
@Test
901+
@Alerts("exception")
902+
public void javaNotAccessable() throws Exception {
903+
final String html = "<html><head>\n"
904+
+ "<script>\n"
905+
+ "function test() {\n"
906+
+ " try {\n"
907+
+ " alert(java.lang.Math.PI);\n"
908+
+ " } catch (e) { alert('exception'); }\n"
909+
+ "}\n"
910+
+ "</script>\n"
911+
+ "</head>\n"
912+
+ "<body onload='test()'>\n"
913+
+ "</body></html>";
914+
915+
loadPageWithAlerts2(html);
916+
}
917+
918+
/**
919+
* @throws Exception if the test fails
920+
*/
921+
@Test
922+
@Alerts("Received: from worker - exception")
923+
public void javaNotAccessableFromWorker() throws Exception {
924+
final String html = "<html><body>\n"
925+
+ "<script async>\n"
926+
+ "try {\n"
927+
+ " var myWorker = new Worker('worker.js');\n"
928+
+ " myWorker.onmessage = function(e) {\n"
929+
+ " alert('Received: ' + e.data);\n"
930+
+ " };\n"
931+
+ "} catch(e) { alert('exception' + e); }\n"
932+
+ "</script></body></html>\n";
933+
934+
final String workerJs = "var pi = 'from worker';\n"
935+
+ "try {\n"
936+
+ " pi = pi + ' - ' + java.lang.Math.PI\n"
937+
+ "} catch (e) { pi = pi + ' - ' + 'exception'; }\n"
938+
+ "postMessage(pi);\n";
939+
940+
getMockWebConnection().setResponse(new URL(URL_FIRST, "worker.js"), workerJs);
941+
942+
loadPageWithAlerts2(html, 2000);
943+
}
894944
}

0 commit comments

Comments
 (0)