fix(security): deny Environment/GC and ADO.NET provider namespaces; close reflection-gateway list (GetTypes/EntryPoint/Declared*/DynamicInvoke)
Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
@@ -115,11 +115,21 @@ public static class ScriptTrustValidator
|
||||
if (extraReferences != null)
|
||||
references.AddRange(extraReferences);
|
||||
|
||||
// Apply the SAME default namespace imports the site runtime compiles the
|
||||
// real script with (ScriptTrustPolicy.DefaultImports — "using System;"
|
||||
// etc.). Without them the semantic pass under-resolves BARE identifiers
|
||||
// that the running script sees fully bound — e.g. `Environment.Exit(0)` or
|
||||
// `GC.Collect()`, whose `Environment`/`GC` resolve to the forbidden
|
||||
// System.Environment/System.GC types only when `using System;` is in
|
||||
// scope. Matching the runtime's import set closes that blind spot; it can
|
||||
// only make MORE identifiers resolve to their true (forbidden) namespace,
|
||||
// never produce a false allow.
|
||||
var compilation = CSharpCompilation.CreateScriptCompilation(
|
||||
"TrustValidation",
|
||||
tree,
|
||||
references,
|
||||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
|
||||
.WithUsings(ScriptTrustPolicy.DefaultImports));
|
||||
|
||||
var model = compilation.GetSemanticModel(tree);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user