Skip to content

Commit 45cb427

Browse files
diametriclukespragg
authored andcommitted
Add oxide.disable-sandbox handling
Can now disable the sandbox with a special file in the extension folder named oxide.disable-sandbox. Allows PInvoke and any blacklisted namespaces when that file is present. Requires restart to take effect.
1 parent 94dcb52 commit 45cb427

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/CSharpExtension.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Oxide.Core;
1+
using Oxide.Core;
22
using Oxide.Core.Extensions;
33
using Oxide.Core.Plugins.Watchers;
44
using System;
@@ -43,6 +43,9 @@ public class CSharpExtension : Extension
4343
// The .cs plugin loader
4444
private CSharpPluginLoader loader;
4545

46+
// Is the sandbox enabled? (always default to true)
47+
public static bool SandboxEnabled { get; private set; } = true;
48+
4649
/// <summary>
4750
/// Initializes a new instance of the CSharpExtension class
4851
/// </summary>
@@ -72,6 +75,12 @@ public override void Load()
7275

7376
// Register engine frame callback
7477
Interface.Oxide.OnFrame(OnFrame);
78+
79+
if (File.Exists(Path.Combine(Interface.Oxide.ExtensionDirectory, "oxide.disable-sandbox")))
80+
{
81+
Interface.Oxide.LogWarning($"{Path.Combine(Interface.Oxide.ExtensionDirectory, "oxide.disable-sandbox")} found, disabling security sandbox. Potentially dangerous APIs and methods are now allowed inside plugins.");
82+
CSharpExtension.SandboxEnabled = false;
83+
}
7584
}
7685

7786
/// <summary>

src/CompiledAssembly.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private void PatchAssembly(Action<byte[]> callback)
131131

132132
if (method.Body == null)
133133
{
134-
if (method.HasPInvokeInfo)
134+
if (method.HasPInvokeInfo && CSharpExtension.SandboxEnabled)
135135
{
136136
method.Attributes &= ~MethodAttributes.PInvokeImpl;
137137
MethodBody body = new MethodBody(method);
@@ -340,6 +340,11 @@ private void PatchAssembly(Action<byte[]> callback)
340340

341341
private static bool IsNamespaceBlacklisted(string fullNamespace)
342342
{
343+
if (!CSharpExtension.SandboxEnabled)
344+
{
345+
return false;
346+
}
347+
343348
foreach (string namespaceName in BlacklistedNamespaces)
344349
{
345350
if (!fullNamespace.StartsWith(namespaceName))

0 commit comments

Comments
 (0)