Skip to content

Commit

Permalink
Security: prevent Rhinos access to Java resources; e.g. call java met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
rbri committed Jan 27, 2020
1 parent 4237700 commit bc1f58d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

<body>
<release version="2.37.0" date="xxxx, 2020" description="Bugfixes, CHROME 79, FF52 removed, FF68 added">
<action type="fix" dev="rbri">
Security: prevent Rhinos access to Java resources; e.g. call java methods.
</action>
<action type="update" dev="rbri">
Upgrade Apache HttpComponents to 4.5.11.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import static org.junit.Assert.fail;

import java.net.URL;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -891,4 +893,52 @@ public void ctorBooleanDocumentAll() throws Exception {

loadPageWithAlerts2(html);
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts("exception")
public void javaNotAccessable() throws Exception {
final String html = "<html><head>\n"
+ "<script>\n"
+ "function test() {\n"
+ " try {\n"
+ " alert(java.lang.Math.PI);\n"
+ " } catch (e) { alert('exception'); }\n"
+ "}\n"
+ "</script>\n"
+ "</head>\n"
+ "<body onload='test()'>\n"
+ "</body></html>";

loadPageWithAlerts2(html);
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts("Received: from worker - exception")
public void javaNotAccessableFromWorker() throws Exception {
final String html = "<html><body>\n"
+ "<script async>\n"
+ "try {\n"
+ " var myWorker = new Worker('worker.js');\n"
+ " myWorker.onmessage = function(e) {\n"
+ " alert('Received: ' + e.data);\n"
+ " };\n"
+ "} catch(e) { alert('exception' + e); }\n"
+ "</script></body></html>\n";

final String workerJs = "var pi = 'from worker';\n"
+ "try {\n"
+ " pi = pi + ' - ' + java.lang.Math.PI\n"
+ "} catch (e) { pi = pi + ' - ' + 'exception'; }\n"
+ "postMessage(pi);\n";

getMockWebConnection().setResponse(new URL(URL_FIRST, "worker.js"), workerJs);

loadPageWithAlerts2(html, 2000);
}
}

0 comments on commit bc1f58d

Please sign in to comment.