drok / Harmony-CitiesSkylines

Harmony 2.x assembly provider mod for Cities: Skylines
Other
13 stars 3 forks source link

Exploiting Colossal Order resolver vulnerability #18

Open drok opened 2 years ago

drok commented 2 years ago

The game includes an assembly resolver that is poorly thought out, and it causes numerous TypeLoadException errors.

When looking to resolve a requested assembly, the game's resolver searches the AppDomain's list of loaded assemblies and looks for the the first assembly whose name matches the beginning of the requested assembly. It ignores version, culture and public key token. This behaviour violates Microsoft's primary advice in the What the event handler should not do section of the Resolver documentation.

This results in the following wrong matches:

There are some mods, like Network Multitool by @MacSergey which use this hack to publish the en localization as a default in an fake assembly named NetworkMultitool.resources, Version=1.2.0.3, Culture=en which does does not exist. The resources the mod wants are instead in the assembly NetworkMultitool, Version=1.2.0.3, Culture=neutral which does exist. The mod relies on the resolver behaviour that "any assembly, of any version, that is named 'N.dll' or 'Ne.dll' or 'Network.dll' is a match for a request for NetworkMultitool.resources of any version, and also for NetworkMultitool.real"

The Harmony mod will treat this class of bug in mods as "exploit of a vulnerability", but will allow it as deprecated behaviour until version 1.1 to allow affected mod authors to clean up their mods.