Why doesn't AllowClr function properly? Have I made any mistakes? #2927
Replies: 3 comments
|
I am attempting to implement a security boundary based on IModuleLoader by restricting the scripts that can be loaded. |
|
The problem was tested in a clean environment and under the expected conditions. Perhaps it's because I made a more subtle mistake. |
|
Short version: Why
Step 1 runs before your list, so any public Jint type ( Why the The key point: CLR interop is not a security sandbox. This is bigger than the allow-list. Once CLR access is enabled, assume a script can reach the host process. Even with a strictly-enforced allow-list, other paths remain: corelib types via What to do. To run untrusted scripts safely, don't enable CLR at all — leave |
Uh oh!
There was an error while loading. Please reload this page.
I am trying to integrate Jint into Unity.
The code is showed below:
using Jint.Runtime.Modules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityJavaScriptEngine.JavaScriptModuleLoaders;
using JavaScriptEngine = Jint.Engine;
namespace UnityJavaScriptEngine.JavaScriptComponents
{
public static class GlobalJavaScriptEngine
{
static JavaScriptEngine MJavaScriptEngine;
}
and:
using Jint;
using Jint.Runtime.Modules;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using JavaScriptEngine = Jint.Engine;
namespace UnityJavaScriptEngine.JavaScriptComponents
{
public static class JavaScriptEngineCreator
{
public static JavaScriptEngine Create(IModuleLoader moduleLoader)
{
Options options = new Options()
.Strict()
.AllowClrWrite()
.AllowOperatorOverloading()
.CatchClrExceptions()
.EnableModules(moduleLoader);
}
Why am I still able to access Jint.Engine in the script, and even call functions like Jint.Engine.Evaluate or Jint.Engine.Execute, which can execute potentially harmful scripts?
Although the CreateJavaScriptEngine method is modified as follows:
static JavaScriptEngine CreateJavaScriptEngine()
{
IModuleLoader moduleLoader = new AddressablesModuleLoader();
// IEnumerable assemblies = GetAssemblies();
return JavaScriptEngineCreator.Create(moduleLoader, typeof(int).Assembly);
}
My whole thing still works while scripts are invoking something not in the typeof(int).Assembly.
All reactions