diff --git a/Explorer/Assets/DCL/Infrastructure/SceneRuntime/Tests/V8Tests.cs b/Explorer/Assets/DCL/Infrastructure/SceneRuntime/Tests/V8Tests.cs index 4acd2f4c7e4..a4d8f263ba4 100644 --- a/Explorer/Assets/DCL/Infrastructure/SceneRuntime/Tests/V8Tests.cs +++ b/Explorer/Assets/DCL/Infrastructure/SceneRuntime/Tests/V8Tests.cs @@ -2,14 +2,15 @@ using Microsoft.ClearScript; using Microsoft.ClearScript.V8; using NUnit.Framework; +using System; using UnityEngine; namespace SceneRuntime.Tests { public class V8Tests { - private V8EngineFactory engineFactory; - private V8ScriptEngine engine; + private V8EngineFactory engineFactory = null!; + private V8ScriptEngine engine = null!; [SetUp] public void SetUp() @@ -56,5 +57,37 @@ function func(data) { sceneScriptObject!.InvokeAsFunction(data); } + + [Test] + public void DisableReflectionOnCreatedEngine() + { + // Assert — the factory keeps AllowReflection disabled on the scene engine. + Assert.IsFalse(engine.AllowReflection); + } + + [Test] + public void BlockReflectionFromSceneScript() + { + // Arrange + engine.AddHostObject("host", new SampleHostObject()); + + // Act — ordinary host member access must still work. + object? value = engine.Evaluate("host.Value"); + + // Assert + Assert.AreEqual(42, value); + + // Act — reflection members are not available to scene scripts. + Exception reflectionException = Assert.Catch(() => engine.Evaluate("host.GetType()")); + + // Assert + Assert.That(reflectionException.ToString(), Does.Contain("reflection").IgnoreCase); + } + + public class SampleHostObject + { + // ReSharper disable once UnusedMember.Local + public int Value => 42; + } } } diff --git a/Explorer/Assets/DCL/Infrastructure/SceneRuntime/V8EngineFactory.cs b/Explorer/Assets/DCL/Infrastructure/SceneRuntime/V8EngineFactory.cs index a1ef019fea0..43edec5c0f3 100644 --- a/Explorer/Assets/DCL/Infrastructure/SceneRuntime/V8EngineFactory.cs +++ b/Explorer/Assets/DCL/Infrastructure/SceneRuntime/V8EngineFactory.cs @@ -17,7 +17,7 @@ public V8ScriptEngine Create(SceneShortInfo sceneInfo) // IL2CPP does not support dynamic bindings! engine.DisableDynamicBinding = true; engine.UseReflectionBindFallback = true; - engine.AllowReflection = true; + engine.AllowReflection = false; return engine; }