From 3d5fe72c855019bc72bbd8c2f2bdef9809e8bc85 Mon Sep 17 00:00:00 2001 From: "OpenGenesis (MPL 2.0)" <153564363+opengenesislink@users.noreply.github.com> Date: Sat, 7 Nov 2026 20:06:15 +0100 Subject: [PATCH] fix(net10/security): disable unsafe BinaryFormatter opt-ins in prebuild and all shipped runtimes --- .../workflows/ogl-yengine-binaryformatter.yml | 9 +++++++++ .../Application/runtimeconfig.template.json | 2 +- OpenSim/Server/runtimeconfig.template.json | 2 +- Prebuild/src/Core/Targets/VSGenericTarget.cs | 2 +- bin/OpenSim.ConsoleClient.runtimeconfig.json | 2 +- ...OpenSim.Tools.Configger.runtimeconfig.json | 2 +- bin/OpenSim.runtimeconfig.json | 2 +- bin/Robust.runtimeconfig.json | 2 +- bin/pCampBot.runtimeconfig.json | 2 +- .../BINARYFORMATTER_RUNTIME_CLEANUP.md | 19 +++++++++++++++++++ .../verify_yengine_binaryformatter_safety.py | 19 ++++++++++++++++++- tools/gen11/retarget_net10.py | 19 +++++++++++++------ 12 files changed, 67 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ogl-yengine-binaryformatter.yml b/.github/workflows/ogl-yengine-binaryformatter.yml index e129e1c0..36209624 100644 --- a/.github/workflows/ogl-yengine-binaryformatter.yml +++ b/.github/workflows/ogl-yengine-binaryformatter.yml @@ -4,6 +4,11 @@ on: pull_request: paths: - '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/**' - 'tools/ci/YEngineBinaryFormatterRegression/**' - 'tools/ci/verify_yengine_binaryformatter_safety.py' @@ -30,6 +35,10 @@ jobs: run: | chmod +x 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 run: dotnet build OpenSim.sln -c Release - name: Test read-only YEngine state file audit diff --git a/OpenSim/Region/Application/runtimeconfig.template.json b/OpenSim/Region/Application/runtimeconfig.template.json index 772fa605..ffd93d75 100644 --- a/OpenSim/Region/Application/runtimeconfig.template.json +++ b/OpenSim/Region/Application/runtimeconfig.template.json @@ -5,7 +5,7 @@ "System.Drawing.EnableUnixSupport": true, "System.Globalization.UseNls": true, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.Runtime.TieredCompilation.QuickJit": false } } \ No newline at end of file diff --git a/OpenSim/Server/runtimeconfig.template.json b/OpenSim/Server/runtimeconfig.template.json index 6d427663..42608f94 100644 --- a/OpenSim/Server/runtimeconfig.template.json +++ b/OpenSim/Server/runtimeconfig.template.json @@ -5,7 +5,7 @@ "System.Drawing.EnableUnixSupport": true, "System.Globalization.UseNls": true, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.Runtime.TieredCompilation.QuickJit": false } } \ No newline at end of file diff --git a/Prebuild/src/Core/Targets/VSGenericTarget.cs b/Prebuild/src/Core/Targets/VSGenericTarget.cs index 4eb5125f..c4ed39ff 100644 --- a/Prebuild/src/Core/Targets/VSGenericTarget.cs +++ b/Prebuild/src/Core/Targets/VSGenericTarget.cs @@ -692,7 +692,7 @@ namespace Prebuild.Core.Targets //ps.WriteLine(" false"); ps.WriteLine(" false"); ps.WriteLine(" false"); - ps.WriteLine(" true"); + ps.WriteLine(" false"); if (listFiles) ps.WriteLine(" false"); ps.WriteLine(" "); diff --git a/bin/OpenSim.ConsoleClient.runtimeconfig.json b/bin/OpenSim.ConsoleClient.runtimeconfig.json index 8fa280c5..24fb372e 100644 --- a/bin/OpenSim.ConsoleClient.runtimeconfig.json +++ b/bin/OpenSim.ConsoleClient.runtimeconfig.json @@ -7,7 +7,7 @@ }, "configProperties": { "System.Reflection.Metadata.MetadataUpdater.IsSupported": false, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.Runtime.TieredCompilation.QuickJit": false } } diff --git a/bin/OpenSim.Tools.Configger.runtimeconfig.json b/bin/OpenSim.Tools.Configger.runtimeconfig.json index 8fa280c5..24fb372e 100644 --- a/bin/OpenSim.Tools.Configger.runtimeconfig.json +++ b/bin/OpenSim.Tools.Configger.runtimeconfig.json @@ -7,7 +7,7 @@ }, "configProperties": { "System.Reflection.Metadata.MetadataUpdater.IsSupported": false, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.Runtime.TieredCompilation.QuickJit": false } } diff --git a/bin/OpenSim.runtimeconfig.json b/bin/OpenSim.runtimeconfig.json index 532a1b38..929bfef8 100644 --- a/bin/OpenSim.runtimeconfig.json +++ b/bin/OpenSim.runtimeconfig.json @@ -11,7 +11,7 @@ "System.Drawing.EnableUnixSupport": true, "System.Globalization.UseNls": true, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.Runtime.TieredCompilation.QuickJit": false } } diff --git a/bin/Robust.runtimeconfig.json b/bin/Robust.runtimeconfig.json index 532a1b38..929bfef8 100644 --- a/bin/Robust.runtimeconfig.json +++ b/bin/Robust.runtimeconfig.json @@ -11,7 +11,7 @@ "System.Drawing.EnableUnixSupport": true, "System.Globalization.UseNls": true, "System.Reflection.Metadata.MetadataUpdater.IsSupported": false, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.Runtime.TieredCompilation.QuickJit": false } } diff --git a/bin/pCampBot.runtimeconfig.json b/bin/pCampBot.runtimeconfig.json index 8fa280c5..24fb372e 100644 --- a/bin/pCampBot.runtimeconfig.json +++ b/bin/pCampBot.runtimeconfig.json @@ -7,7 +7,7 @@ }, "configProperties": { "System.Reflection.Metadata.MetadataUpdater.IsSupported": false, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true, + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.Runtime.TieredCompilation.QuickJit": false } } diff --git a/doc/NexVerse/BINARYFORMATTER_RUNTIME_CLEANUP.md b/doc/NexVerse/BINARYFORMATTER_RUNTIME_CLEANUP.md index 10fa6cd2..4d92d012 100644 --- a/doc/NexVerse/BINARYFORMATTER_RUNTIME_CLEANUP.md +++ b/doc/NexVerse/BINARYFORMATTER_RUNTIME_CLEANUP.md @@ -62,3 +62,22 @@ full format. It marks valid snapshots `inspect-required`, not `legacy-detected`. The only valid compatibility verdict comes from a controlled, backed-up staging restore; **do not assume all snapshots are 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. diff --git a/tools/ci/verify_yengine_binaryformatter_safety.py b/tools/ci/verify_yengine_binaryformatter_safety.py index 6f75b107..abcfdb91 100644 --- a/tools/ci/verify_yengine_binaryformatter_safety.py +++ b/tools/ci/verify_yengine_binaryformatter_safety.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 """Ensure .NET 10 YEngine and generic helpers never activate BinaryFormatter.""" from pathlib import Path +import json ROOT = Path(__file__).resolve().parents[2] 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 "DtdProcessing = DtdProcessing.Prohibit" 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 'false' in generator +assert 'true' 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") diff --git a/tools/gen11/retarget_net10.py b/tools/gen11/retarget_net10.py index b68137d2..2fe131dd 100644 --- a/tools/gen11/retarget_net10.py +++ b/tools/gen11/retarget_net10.py @@ -15,6 +15,12 @@ ROOT = Path(__file__).resolve().parents[2] OLD = "net8.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 = "true" +UNSAFE_FALSE = "false" + def projects(): for project in sorted(ROOT.rglob("*.csproj")): @@ -26,7 +32,7 @@ def projects(): def main() -> int: parser = argparse.ArgumentParser() 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() changed: list[str] = [] stale: list[str] = [] @@ -34,21 +40,22 @@ def main() -> int: for project in projects(): scanned += 1 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 rel = str(project.relative_to(ROOT)) stale.append(rel) if not args.check: - project.write_text(source.replace(OLD, NEW), encoding="utf-8") + project.write_text(converted, encoding="utf-8") changed.append(rel) if args.check: if 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 - 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 - 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