Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Hide modding-related types from TypeHelper.FindType #67

Merged
merged 5 commits into from
Aug 29, 2022
Merged

Conversation

zkxs
Copy link
Collaborator

@zkxs zkxs commented Aug 22, 2022

This fixes #64.

The core idea in this PR is right as NML is spinning up, I record all currently loaded assemblies, which I call initialAssemblies. Harmony may or may not be loaded yet depending on if the user has it in nml_mods or not. So initialAssemblies - NML - Harmony is neosAssemblies. Any assembly not in neosAssemblies will be hidden from Neos's main string-to-Type conversion function, TypeHelper.FindType().

As an additional safety check, I calculate assemblies that belong to mods as well. If a type belongs to neither neosAssemblies or modAssemblies, that's an indication that a type was loaded very late (after NML) but it's being used in game. That's pretty weird, so I have a warn log for it.

@zkxs zkxs requested review from ljoonal, EIA485 and art0007i August 22, 2022 04:15
@EIA485
Copy link
Member

EIA485 commented Aug 22, 2022

there should be a nml config option to disable this feature, maybe "unsafe_types"

@zkxs
Copy link
Collaborator Author

zkxs commented Aug 22, 2022

there should be a nml config option to disable this feature, maybe "unsafe_types"

Implemented now as a hidemodtypes=true config.

@EIA485
Copy link
Member

EIA485 commented Aug 22, 2022

ideally this harmony patch would not run in LocalWorlds, namely userspace.
there is no risk of other users running logix on you in a local world and this patch could break some mods.
say a mod author defined a type config, then a user is using the userspace mod settings mod. the user can not set the type to one that is defined by a mod.

a potential way to implement this would be to check what thread the FindType() method is being called on and compare that to a list of whitelisted localworld threads

{
// an assembly was in neither neosAssemblies nor modAssemblies
// this implies someone late-loaded an assembly after NML, and it was later used in-game
// this is super weird, and probably shouldn't ever happen... but if it does, I want to know about it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont any plugin loaded after nml is loaded cause this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, plugins are loaded before NML starts executing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could add another config option to allow late loaded types thru our filter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's doable. I'm just not sure who'd be late loading types at all, hence the warning log.

private static HashSet<Assembly> GetNeosAssemblies(HashSet<Assembly> initialAssemblies)
{
initialAssemblies.Remove(Assembly.GetExecutingAssembly());
initialAssemblies.Remove(typeof(Harmony).Assembly);
Copy link
Member

@EIA485 EIA485 Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably add a comment here clarifying why a specific case is needed.
afak in theory, if nml is the only thing a user is using that loads harmony, and the user followed the install instructions of placing harmony in nml_libs, initialAssemblies shouldn't contain harmony.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added in f9c6f22. The install instructions weren't always to use nml_libs, and I don't want to punish users who followed the old steps.

@XDelta
Copy link
Member

XDelta commented Aug 22, 2022

Implemented now as a hidemodtypes=true config.

Offhand I think all the other config options have false as the default behavior of nml. I think the name should be adjusted to follow that for consistency as hiding types should be the default.

@zkxs
Copy link
Collaborator Author

zkxs commented Aug 22, 2022

ideally this harmony patch would not run in LocalWorlds, namely userspace. there is no risk of other users running logix in on you in a local world and this patch could break some mods. say a mod author defined a type config, then a user is using the mod settings mod. the user can not set the type to one that is not built into neos.

a potential way to implement this would be to check what thread the FindType() method is being called on and compare that to a list of whitelisted localworld threads

Do we know for a fact that threads aren't in a pool that handles multiple worlds?

@zkxs
Copy link
Collaborator Author

zkxs commented Aug 22, 2022

Implemented now as a hidemodtypes=true config.

Offhand I think all the other config options have false as the default behavior of nml. I think the name should be adjusted to follow that for consistency as hiding types should be the default.

There is another config that defaults to true. /doc/modloader_config.md

The reason I named this hidemodtypes is because I think showmodtypes would be misleading, as NML either hides or takes no action.

@XDelta
Copy link
Member

XDelta commented Aug 22, 2022

Implemented now as a hidemodtypes=true config.

Offhand I think all the other config options have false as the default behavior of nml. I think the name should be adjusted to follow that for consistency as hiding types should be the default.

There is another config that defaults to true. /doc/modloader_config.md

The reason I named this hidemodtypes is because I think showmodtypes would be misleading, as NML either hides or takes no action.

AllowUnsafeTypeCheck, AllowUnsafeModTypeChecks or similar could work but just figured I'd mention it.

Copy link
Member

@ljoonal ljoonal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this seems okay, it should be noted that fully hiding anything in Neos from remote clients is hard to do properly. Even with this, I'm pretty sure there is still at least a possibility of a theoretical timing based detection approach, given a dedicated enough attacker.

@zkxs zkxs merged commit 635592b into master Aug 29, 2022
@zkxs zkxs deleted the fix-type-tell branch August 29, 2022 00:25
zkxs added a commit that referenced this pull request Feb 25, 2023
It turns out #67 did not cover all cases.

In this PR, `WorkerManager.IsValidGenericType` and `WorkerManager.GetType` are now both handled. I've made the code a little more modular as well now that three distinct methods are being hooked in very similar ways.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NML "tell" via loaded types
4 participants