Files
sbox-public/engine/Sandbox.Compiling/Compiler/Blacklist/Rules.Methods.cs
Matt Stevens 3f11417817 Whitelist: explicit Unsafe/Span/Memory (#5077)
* Whitelist System.Memory and System.ReadOnlyMemory (without pinning)
* Be very explicit with System.Span and System.ReadOnlySpan whitelists, do not allow pinnables
* Be completely explicit with Unsafe IL whitelist, allow Unsafe.SizeOf<T>
* BlacklistCodeWalker can have an allow list
* Compiler blacklist explicitly bans CreateSpan, allows Unsafe.SizeOf<T>
* Whitelist System.IO.InvalidDataException
* Better InlineArray whitelisting for compiler generated code
* WhitelistGen: Creates explicit signatures from wildcard rules
* Claude skill for whitelisting, uses the WhitelistGen tool to be very explicit and makes a good effort to security review
2026-06-17 18:28:47 +01:00

21 lines
832 B
C#

namespace Sandbox;
static partial class CompilerRules
{
public static readonly List<string> Methods =
[
"System.Runtime.CompilerServices.Unsafe.*",
// SizeOf<T>() just returns a type's byte size - no memory access, no type punning. Safe to write.
// (Wildcard on the type arg because the symbol renders the constructed form, e.g. SizeOf<int>().)
"!System.Runtime.CompilerServices.Unsafe.SizeOf<*>()",
// Both of these create a span from a ref with an unchecked length -> out-of-bounds read/write.
"System.Runtime.InteropServices.MemoryMarshal.CreateReadOnlySpan*",
"System.Runtime.InteropServices.MemoryMarshal.CreateSpan*",
// Allowed at an IL level because it's compiler-generated, disaster if acccessible
"System.Span<*>.GetPinnableReference()",
"System.ReadOnlySpan<*>.GetPinnableReference()",
];
}