mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 08:18:20 -04:00
* 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
21 lines
832 B
C#
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()",
|
|
];
|
|
}
|