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

GraalVM sandbox implementation #2018

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
975b73e
Fixed deb package
Jun 17, 2018
41ba39f
Fixed deb package
Jun 17, 2018
03affc4
Fixed deb package
Jun 17, 2018
750a9a1
- OSX: Build instruction
Nov 25, 2018
0f897b5
Merge
Nov 25, 2018
6eb000a
Fixed maven build
Nov 25, 2018
c4de66c
Fixed maven build
Nov 25, 2018
ab3010e
Fixed conflict
Nov 26, 2018
ddee090
Removed ressource
Nov 26, 2018
a3fd024
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Dec 2, 2018
0e43247
Travis: Build OSX packages
Dec 2, 2018
e579cab
Fix whitespace
Dec 2, 2018
e3ed43f
Fix conflict
Dec 2, 2018
8711631
Fixed merge issue
Dec 2, 2018
9b5df94
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Dec 2, 2018
c48aed2
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Dec 18, 2018
c9c78f3
Implemented a .lnk parser
Jan 2, 2019
6406b23
Implemented a .lnk parser
Jan 2, 2019
5f8bae5
Support the extraction of arguments
Jan 3, 2019
cf2b143
EOL
Jan 3, 2019
ebe89cc
Javadoc improvements
Jan 4, 2019
4236661
Lnk doc
Jan 4, 2019
f65e2a2
Abstract LnkFlagsParser
Jan 4, 2019
f12f38a
Fixed issue #791
Jan 13, 2019
489ee3f
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jan 13, 2019
2259a64
.tar.xz uncompression support
Jan 13, 2019
c3279ff
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jan 14, 2019
daeae36
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jan 15, 2019
a31a39f
.exe uncompression support
Jan 15, 2019
8b6985b
- Warkaround mimetype detection
Jan 15, 2019
ce98108
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jan 26, 2019
7b9f2c5
- ThreadPoolExecutorService: Debugger
Jan 26, 2019
330327e
- ThreadPoolExecutorService: Debugger
Jan 26, 2019
1f1e654
- ThreadPoolExecutorService: Debugger
Jan 26, 2019
bd13444
EOF
Jan 26, 2019
6a5a106
EOF
Jan 26, 2019
789a890
Jmimemagic: removed open document
Jan 26, 2019
6013ab3
Jmimemagic: removed open document
Jan 26, 2019
fbda424
Clean dependency + fix extractor
Jan 26, 2019
d335833
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jan 26, 2019
6ff763d
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jun 1, 2019
9906cdc
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jun 1, 2019
a7d6647
Fix bouncycastle conflict
Jun 9, 2019
9aed91b
Merged
Jun 10, 2019
77d0a6f
Free git ressource when pull is used
Jun 10, 2019
b69f6ee
Gitpod: add freetype
qparis Jun 10, 2019
f73ced4
Gitpod: add freetype
qparis Jun 10, 2019
61bf2fd
Fix
qparis Jun 10, 2019
a5d032e
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jun 10, 2019
d50f376
fix conflict
Jun 10, 2019
10de885
Thread pool factory: remove unused threads
Jun 10, 2019
1b17ae9
Merge remote-tracking branch 'origin/master'
Jun 22, 2019
01b0a4e
GraalVM sandbox implementation
Jun 23, 2019
b955432
GraalVM sandbox implementation
Jun 23, 2019
516a835
Merge branch 'master' of https://github.com/PhoenicisOrg/phoenicis
Jun 23, 2019
c2a4431
GraalVM sandbox implementation
Jun 23, 2019
c8d8850
GraalVM sandbox implementation
Jun 23, 2019
96f0977
GraalVM sandbox implementation
Jun 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.phoenicis.multithreading.MultithreadingConfiguration;
import org.phoenicis.repository.RepositoryConfiguration;
import org.phoenicis.scripts.engine.PhoenicisScriptEngineFactory;
import org.phoenicis.scripts.engine.implementation.PhoenicisSandbox;
import org.phoenicis.scripts.interpreter.PhoenicisScriptInterpreter;
import org.phoenicis.scripts.engine.ScriptEngineType;
import org.phoenicis.scripts.engine.injectors.*;
Expand Down Expand Up @@ -51,18 +52,27 @@ public class ScriptsConfiguration {
@Autowired
private MultithreadingConfiguration multithreadingConfiguration;

@Bean
public PhoenicisSandbox phoenicisSandbox() {
return new PhoenicisSandbox();
}

@Bean
public PhoenicisScriptEngineFactory graalScriptEngineFactory() {
return new PhoenicisScriptEngineFactory(ScriptEngineType.GRAAL, Arrays.asList(new ScriptUtilitiesInjector(),
new BeanInjector(applicationContext), new SetupWizardInjector(wizardConfiguration.setupWizardFactory()),
new IncludeInjector(scriptFetcher()), new LocalisationInjector()));
return new PhoenicisScriptEngineFactory(phoenicisSandbox(), ScriptEngineType.GRAAL,
Arrays.asList(new ScriptUtilitiesInjector(),
new BeanInjector(applicationContext),
new SetupWizardInjector(wizardConfiguration.setupWizardFactory()),
new IncludeInjector(scriptFetcher()), new LocalisationInjector()));
}

@Bean
public PhoenicisScriptEngineFactory nashornScriptEngineFactory() {
return new PhoenicisScriptEngineFactory(ScriptEngineType.NASHORN, Arrays.asList(new ScriptUtilitiesInjector(),
new BeanInjector(applicationContext), new SetupWizardInjector(wizardConfiguration.setupWizardFactory()),
new IncludeInjector(scriptFetcher()), new LocalisationInjector()));
return new PhoenicisScriptEngineFactory(phoenicisSandbox(), ScriptEngineType.NASHORN,
Arrays.asList(new ScriptUtilitiesInjector(),
new BeanInjector(applicationContext),
new SetupWizardInjector(wizardConfiguration.setupWizardFactory()),
new IncludeInjector(scriptFetcher()), new LocalisationInjector()));
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@

package org.phoenicis.scripts.engine;

import org.phoenicis.scripts.engine.implementation.PhoenicisSandbox;
import org.phoenicis.scripts.engine.injectors.EngineInjector;
import org.phoenicis.scripts.engine.implementation.PhoenicisScriptEngine;

import java.util.List;

public class PhoenicisScriptEngineFactory {
private final ScriptEngineType type;
private final PhoenicisSandbox phoenicisSandbox;
private final List<EngineInjector> engineInjectors;

public PhoenicisScriptEngineFactory(ScriptEngineType type, List<EngineInjector> engineInjectors) {
public PhoenicisScriptEngineFactory(PhoenicisSandbox phoenicisSandbox, ScriptEngineType type,
List<EngineInjector> engineInjectors) {
this.type = type;
this.engineInjectors = engineInjectors;
this.phoenicisSandbox = phoenicisSandbox;
}

public PhoenicisScriptEngine createEngine() {
final PhoenicisScriptEngine phoenicisScriptEngine = type.createScriptEngine();
final PhoenicisScriptEngine phoenicisScriptEngine = type.createScriptEngine(this.phoenicisSandbox);

engineInjectors.forEach(engineInjector -> engineInjector.injectInto(phoenicisScriptEngine));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.phoenicis.scripts.engine;

import org.phoenicis.scripts.engine.implementation.JSAScriptEngine;
import org.phoenicis.scripts.engine.implementation.PhoenicisSandbox;
import org.phoenicis.scripts.engine.implementation.PhoenicisScriptEngine;
import org.phoenicis.scripts.engine.implementation.PolyglotScriptEngine;

Expand All @@ -12,15 +13,15 @@
public enum ScriptEngineType {
NASHORN("nashorn") {
@Override
public PhoenicisScriptEngine createScriptEngine() {
public PhoenicisScriptEngine createScriptEngine(PhoenicisSandbox sandbox) {
return new JSAScriptEngine("nashorn");
}
},

GRAAL("graal.js") {
@Override
public PhoenicisScriptEngine createScriptEngine() {
return new PolyglotScriptEngine("js", Map.of("js.nashorn-compat", "true"));
public PhoenicisScriptEngine createScriptEngine(PhoenicisSandbox sandbox) {
return new PolyglotScriptEngine(sandbox, "js", Map.of("js.nashorn-compat", "true"));
}
};

Expand All @@ -43,7 +44,7 @@ public PhoenicisScriptEngine createScriptEngine() {
*
* @return The new instance of the {@link ScriptEngineType}
*/
public abstract PhoenicisScriptEngine createScriptEngine();
public abstract PhoenicisScriptEngine createScriptEngine(PhoenicisSandbox phoenicisSandbox);

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.phoenicis.scripts.engine.implementation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PhoenicisSandbox {
qparis marked this conversation as resolved.
Show resolved Hide resolved
private static final Logger LOGGER = LoggerFactory.getLogger(PhoenicisSandbox.class);

public boolean isSafe(String identifier) {
LOGGER.debug("Loading {} in javascript context", identifier);
if (identifier.startsWith("org.phoenicis")) {
return true;
}

if (identifier.startsWith("java.lang")) {
// FIXME: This should be more fine-tuned later
// Contains process builder
madoar marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

if (identifier.startsWith("java.util")) {
// FIXME: This should be more fine-tuned later
return true;
}

// Needed by GraalVM
if (identifier.startsWith("java.net.URLClassLoader")) {
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* A {@link PhoenicisScriptEngine} wrapping around a polyglot {@link Context} object defined by Graal
*/
public class PolyglotScriptEngine implements PhoenicisScriptEngine {
private final PhoenicisSandbox phoenicisSandbox;

/**
* A list of error handlers
*/
Expand All @@ -33,16 +35,19 @@ public class PolyglotScriptEngine implements PhoenicisScriptEngine {
/**
* Constructor
*
* @param phoenicisSandbox a Phoenicis Sandbox bean
* @param language The language name
* @param options A map of options for the Polyglot context
*/
public PolyglotScriptEngine(String language, Map<String, String> options) {
public PolyglotScriptEngine(PhoenicisSandbox phoenicisSandbox, String language, Map<String, String> options) {
super();
this.phoenicisSandbox = phoenicisSandbox;
madoar marked this conversation as resolved.
Show resolved Hide resolved

this.errorHandlers = new ArrayList<>();
this.language = language;
this.context = Context.newBuilder(language)
.allowExperimentalOptions(true)
.allowHostClassLookup(phoenicisSandbox::isSafe)
.options(options).allowHostAccess(true).build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.phoenicis.scripts.ui;

import org.phoenicis.configuration.security.Safe;

/**
* type of the installation
*/
@Safe
public enum InstallationType {
APPS("Apps"), ENGINES("Engines"), VERBS("Verbs");

Expand Down