fix(net10/security): disable unsafe BinaryFormatter opt-ins in prebuild and all shipped runtimes

This commit is contained in:
OpenGenesis (MPL 2.0) committed 2026-11-07 20:06:15 +01:00
1 parent 43e101f737
commit 3d5fe72c85
12 files changed
+67 -15

No files matched your search

@@ -4,6 +4,11 @@ on:
pull_request: pull_request:
paths: paths:
- 'OpenSim/Framework/Util.cs' - 'OpenSim/Framework/Util.cs'
- 'OpenSim/Server/runtimeconfig.template.json'
- 'OpenSim/Region/Application/runtimeconfig.template.json'
- 'Prebuild/src/Core/Targets/VSGenericTarget.cs'
- 'tools/gen11/retarget_net10.py'
- 'bin/*.runtimeconfig.json'
- 'OpenSim/Region/ScriptEngine/YEngine/**' - 'OpenSim/Region/ScriptEngine/YEngine/**'
- 'tools/ci/YEngineBinaryFormatterRegression/**' - 'tools/ci/YEngineBinaryFormatterRegression/**'
- 'tools/ci/verify_yengine_binaryformatter_safety.py' - 'tools/ci/verify_yengine_binaryformatter_safety.py'
@@ -30,6 +35,10 @@ jobs:
run: | run: |
chmod +x runprebuild.sh chmod +x runprebuild.sh
./runprebuild.sh ./runprebuild.sh
- name: Recheck generated projects and runtime safety configuration
run: |
python3 tools/gen11/retarget_net10.py --check
python3 tools/ci/verify_yengine_binaryformatter_safety.py
- name: Build full OpenGenesisLINK G1 .NET 10 solution - name: Build full OpenGenesisLINK G1 .NET 10 solution
run: dotnet build OpenSim.sln -c Release run: dotnet build OpenSim.sln -c Release
- name: Test read-only YEngine state file audit - name: Test read-only YEngine state file audit
@@ -5,7 +5,7 @@
"System.Drawing.EnableUnixSupport": true, "System.Drawing.EnableUnixSupport": true,
"System.Globalization.UseNls": true, "System.Globalization.UseNls": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Runtime.TieredCompilation.QuickJit": false "System.Runtime.TieredCompilation.QuickJit": false
} }
} }
+1 -1
View File
@@ -5,7 +5,7 @@
"System.Drawing.EnableUnixSupport": true, "System.Drawing.EnableUnixSupport": true,
"System.Globalization.UseNls": true, "System.Globalization.UseNls": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Runtime.TieredCompilation.QuickJit": false "System.Runtime.TieredCompilation.QuickJit": false
} }
} }
+1 -1
View File
@@ -692,7 +692,7 @@ namespace Prebuild.Core.Targets
//ps.WriteLine(" <EnableDefaultCompileItems>false</EnableDefaultCompileItems>"); //ps.WriteLine(" <EnableDefaultCompileItems>false</EnableDefaultCompileItems>");
ps.WriteLine(" <ProduceReferenceAssembly>false</ProduceReferenceAssembly>"); ps.WriteLine(" <ProduceReferenceAssembly>false</ProduceReferenceAssembly>");
ps.WriteLine(" <GenerateDependencyFile>false</GenerateDependencyFile>"); ps.WriteLine(" <GenerateDependencyFile>false</GenerateDependencyFile>");
ps.WriteLine(" <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>"); ps.WriteLine(" <EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>");
if (listFiles) if (listFiles)
ps.WriteLine(" <EnableDefaultItems>false</EnableDefaultItems>"); ps.WriteLine(" <EnableDefaultItems>false</EnableDefaultItems>");
ps.WriteLine(" </PropertyGroup>"); ps.WriteLine(" </PropertyGroup>");
+1 -1
View File
@@ -7,7 +7,7 @@
}, },
"configProperties": { "configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Runtime.TieredCompilation.QuickJit": false "System.Runtime.TieredCompilation.QuickJit": false
} }
} }
@@ -7,7 +7,7 @@
}, },
"configProperties": { "configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Runtime.TieredCompilation.QuickJit": false "System.Runtime.TieredCompilation.QuickJit": false
} }
} }
+1 -1
View File
@@ -11,7 +11,7 @@
"System.Drawing.EnableUnixSupport": true, "System.Drawing.EnableUnixSupport": true,
"System.Globalization.UseNls": true, "System.Globalization.UseNls": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Runtime.TieredCompilation.QuickJit": false "System.Runtime.TieredCompilation.QuickJit": false
} }
} }
+1 -1
View File
@@ -11,7 +11,7 @@
"System.Drawing.EnableUnixSupport": true, "System.Drawing.EnableUnixSupport": true,
"System.Globalization.UseNls": true, "System.Globalization.UseNls": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Runtime.TieredCompilation.QuickJit": false "System.Runtime.TieredCompilation.QuickJit": false
} }
} }
+1 -1
View File
@@ -7,7 +7,7 @@
}, },
"configProperties": { "configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Runtime.TieredCompilation.QuickJit": false "System.Runtime.TieredCompilation.QuickJit": false
} }
} }
@@ -62,3 +62,22 @@ full format. It marks valid snapshots `inspect-required`, not
`legacy-detected`. The only valid compatibility verdict comes from a `legacy-detected`. The only valid compatibility verdict comes from a
controlled, backed-up staging restore; **do not assume all snapshots are controlled, backed-up staging restore; **do not assume all snapshots are
upgrade-safe because the audit succeeded.** upgrade-safe because the audit succeeded.**
## Runtime and build-time unsafe opt-in removed
The historic Prebuild generator had an unconditional
`EnableUnsafeBinaryFormatterSerialization=true` setting in generated
projects. The checked-in `prebuild.dll` is older than the generator
source; it still emits the switch when `runprebuild.sh` runs.
The Generation 1.1 retarget step now **always replaces that generated
opt-in with false** before project restore/build, and `--check` rejects
an unsafe regenerated project. The generator source is also corrected
for future rebuilds. Runtime config templates for ROBUST and OpenSim and
the five checked-in application runtime configs explicitly disable unsafe
BinaryFormatter deserialization. All of this is checked by CI, including
a second check immediately *after* regeneration.
The intentionally isolated .NET 8 fixture for legacy KeyframeMotion
migration in PR #396 lives outside the generated project tree; its
compatibility setting is not enabled in any .NET 10 production process.
@@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Ensure .NET 10 YEngine and generic helpers never activate BinaryFormatter.""" """Ensure .NET 10 YEngine and generic helpers never activate BinaryFormatter."""
from pathlib import Path from pathlib import Path
import json
ROOT = Path(__file__).resolve().parents[2] ROOT = Path(__file__).resolve().parents[2]
y = (ROOT / "OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs").read_text() y = (ROOT / "OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs").read_text()
@@ -27,4 +28,20 @@ assert "ReadPersistedStateXmlFile(m_StateFileName)" in ctor
assert "WriteStateFileAtomically(m_StateFileName, scriptStateN.OuterXml)" in capture assert "WriteStateFileAtomically(m_StateFileName, scriptStateN.OuterXml)" in capture
assert "DtdProcessing = DtdProcessing.Prohibit" in capture assert "DtdProcessing = DtdProcessing.Prohibit" in capture
assert "File.Move(temporary, statePath, overwrite: true)" in capture assert "File.Move(temporary, statePath, overwrite: true)" in capture
print("PASS: no BinaryFormatter activation in YEngine or Util, legacy state preserved") generator = (ROOT / "Prebuild/src/Core/Targets/VSGenericTarget.cs").read_text()
assert '<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>' in generator
assert '<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>' not in generator
retarget = (ROOT / "tools/gen11/retarget_net10.py").read_text()
assert "UNSAFE_TRUE" in retarget and "UNSAFE_FALSE" in retarget
assert 'converted = source.replace(OLD, NEW).replace(UNSAFE_TRUE, UNSAFE_FALSE)' in retarget
runtime_paths = [
ROOT / "OpenSim/Server/runtimeconfig.template.json",
ROOT / "OpenSim/Region/Application/runtimeconfig.template.json",
*sorted((ROOT / "bin").glob("*.runtimeconfig.json")),
]
for runtime_path in runtime_paths:
config = json.loads(runtime_path.read_text())
enabled = config["runtimeOptions"].get("configProperties", {}).get(
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", False)
assert enabled is not True, f"Unsafe BinaryFormatter runtime opt-in: {runtime_path}"
print("PASS: no BinaryFormatter activation, unsafe build opt-ins or runtime opt-ins; state preserved")
+13 -6
View File
@@ -15,6 +15,12 @@ ROOT = Path(__file__).resolve().parents[2]
OLD = "net8.0" OLD = "net8.0"
NEW = "net10.0" NEW = "net10.0"
# The bundled prebuild.dll still generates an obsolete unsafe opt-in for
# every project. Force it OFF on each build; this is not a blanket
# BinaryFormatter compatibility switch for application data.
UNSAFE_TRUE = "<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>"
UNSAFE_FALSE = "<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>"
def projects(): def projects():
for project in sorted(ROOT.rglob("*.csproj")): for project in sorted(ROOT.rglob("*.csproj")):
@@ -26,7 +32,7 @@ def projects():
def main() -> int: def main() -> int:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--check", action="store_true", parser.add_argument("--check", action="store_true",
help="fail when a project still targets net8.0") help="fail on net8.0 projects or enabled unsafe BinaryFormatter")
args = parser.parse_args() args = parser.parse_args()
changed: list[str] = [] changed: list[str] = []
stale: list[str] = [] stale: list[str] = []
@@ -34,21 +40,22 @@ def main() -> int:
for project in projects(): for project in projects():
scanned += 1 scanned += 1
source = project.read_text(encoding="utf-8-sig") source = project.read_text(encoding="utf-8-sig")
if OLD not in source: converted = source.replace(OLD, NEW).replace(UNSAFE_TRUE, UNSAFE_FALSE)
if converted == source:
continue continue
rel = str(project.relative_to(ROOT)) rel = str(project.relative_to(ROOT))
stale.append(rel) stale.append(rel)
if not args.check: if not args.check:
project.write_text(source.replace(OLD, NEW), encoding="utf-8") project.write_text(converted, encoding="utf-8")
changed.append(rel) changed.append(rel)
if args.check: if args.check:
if stale: if stale:
for path in stale: for path in stale:
print(f"ERROR: net8.0 project still present: {path}") print(f"ERROR: net8.0 target or unsafe BinaryFormatter opt-in: {path}")
return 1 return 1
print(f"G1.1 .NET 10: {scanned} project files checked, no net8.0 targets") print(f"G1.1 .NET 10: {scanned} projects checked, no net8.0 or unsafe BinaryFormatter opt-in")
return 0 return 0
print(f"G1.1 .NET 10: retargeted {len(changed)} of {scanned} project files") print(f"G1.1 .NET 10: retargeted or secured {len(changed)} of {scanned} project files")
return 0 return 0