Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Graal.js 19.0.0 via Scripting in platform/core.network #1092

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f1dd7e5
Using Scripting API in platform/core.network
Jan 21, 2019
1894e0c
Continue to specify class filter when using Nashorn engine
Jan 21, 2019
ef302df
Merge branch 'master' into CoreNetworkAndScriptingAPI
Jan 21, 2019
294cb63
Allow exit from the unit test
Jan 22, 2019
f2c5275
ConfigureProxy task to set proxy before downloading Gradle
Jan 25, 2019
6247e88
Merging with recent master
Apr 29, 2019
c9fdbfc
Updating to GraalVM RC16
Apr 29, 2019
a499252
Can't build web.core module in our corporate environment without havi…
Apr 29, 2019
a297bcf
Setting up proxy before building web.core module
Apr 29, 2019
8f60775
Merging with master and running with nashorn emulation
Apr 29, 2019
4592738
icu4j is needed for Graal JS I18N support
Apr 29, 2019
d9ef75c
Make the default value of proxyPort property a number
May 22, 2019
db69ef4
Using released version 19.0.0 of GraalVM libraries
May 22, 2019
fb47be0
Adjusting to API changes in GraalVM SDK, Truffle and Graal.js modules
May 22, 2019
1cb766d
Merge remote-tracking branch 'origin/master' into CoreNetworkAndScrip…
May 22, 2019
d2bb159
Adjusting to GraalVM 19.0.0
May 23, 2019
bfbe61d
Adjusting version to 19.0.0
May 24, 2019
a0ebbb9
Sharing the license between ide/html.parser/external/icu4j-4_4_2-lice…
May 24, 2019
c5365c1
Use 1.7 compilation level even on newer JDKs
May 24, 2019
d0525af
Always set the proxy host property - even to empty string
May 24, 2019
0b04f4d
Avoid configuration of the engines via global properties
May 24, 2019
6468401
Describing the security model of GraalVM languages and crosslinking t…
May 24, 2019
01a351e
Merge remote-tracking branch 'origin/master' into CoreNetworkAndScrip…
May 24, 2019
afc27a4
Keep the hintful comment
May 24, 2019
f47f36c
Secure all script engines by default
May 27, 2019
f21511c
Control access to Java.type via a property
May 28, 2019
c3b95e1
Replacing allowAllAccess property with a builder configuration method
May 28, 2019
5a0a6e7
Test the JavaScript engines in both 'all access' modes
May 28, 2019
7a90c43
ALLOWED_PAC_ENGINES branding API to allow applications to restrict th…
May 28, 2019
ae8dd1a
Only set the gradle.proxy.args if the resolved proxy is not empty
May 29, 2019
30626a3
Attributing non-localizable strings with NOI18N comment
May 29, 2019
abd99c9
Removing redundant null check
May 29, 2019
178b4c6
Tightening up security by removing access to common reflection entryp…
Jun 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,6 +18,8 @@
*/
package org.netbeans.core.network.proxy.pac.impl;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;
Expand Down Expand Up @@ -304,7 +306,41 @@ private PacScriptEngine getScriptEngine(String pacSource) throws PacParsingExcep
}
}

private boolean isNashornFactory(ScriptEngineFactory f) {
try {
Class<?> klass = Class.forName("jdk.nashorn.api.scripting.NashornScriptEngineFactory");
return klass.isInstance(f);
} catch (ClassNotFoundException ex) {
return false;
}
}

private ScriptEngine secureEngineEngine(ScriptEngine e) {
try {
ScriptEngineFactory f = e.getFactory();
final Class<? extends ScriptEngineFactory> factoryClass = f.getClass();
final ClassLoader factoryClassLoader = factoryClass.getClassLoader();
Class<?> filterClass = Class.forName("jdk.nashorn.api.scripting.ClassFilter", true, factoryClassLoader);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
Method createMethod = factoryClass.getMethod("getScriptEngine", filterClass);
Object filter = java.lang.reflect.Proxy.newProxyInstance(factoryClassLoader, new Class[] { filterClass }, (Object proxy, Method method, Object[] args) -> {
return false;
});
return (ScriptEngine) createMethod.invoke(f, filter);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
} catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
return e;
}
}

private ScriptEngine getGenericJSScriptEngine() {
ScriptEngine eng = newGenericJSScriptEngine();
if (isNashornFactory(eng.getFactory())) {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
return secureEngineEngine(eng);
}
return eng;
}

private ScriptEngine newGenericJSScriptEngine() {
ScriptEngineManager manager = Scripting.createManager();
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
ScriptEngine mimeBased = manager.getEngineByMimeType("text/javascript");
if (mimeBased != null) {
Expand Down
@@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/




//
// A PAC script which tries to break out of the sandbox and attempts
// to do something really nasty.
//

function FindProxyForURL(url, host)
{
alert("pac-test-getclass.js");

var clazz = "".getClass();
if (!clazz) {
return "DIRECT";
} else {
return "PROXY " + clazz.toString().substring(6) + ":80";
}
}
Expand Up @@ -71,6 +71,7 @@ public void testEngine() throws PacParsingException, IOException, URISyntaxExcep
testPacFile("pac-test2.js", factory, 3, true);
testPacFile("pac-test3.js", factory, 1, false);
testPacFileMalicious("pac-test-sandbox-breakout.js", factory);
testPacFileMalicious("pac-test-getclass.js", factory);

testPacFile2("pac-test4.js", factory);
}
Expand Down