Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoOpen in the empty namespace as malicious code vector #17137

Open
DalekBaldwin opened this issue May 11, 2024 · 1 comment
Open

AutoOpen in the empty namespace as malicious code vector #17137

DalekBaldwin opened this issue May 11, 2024 · 1 comment

Comments

@DalekBaldwin
Copy link

I noticed this while trying to excise unexpected uses of YoLo.fs in projects that depend (even if only transitively) on Http.Fs: haf/Http.fs#176 . While this particular case does not appear to be malicious, and merely makes it harder to remove the dependency, it is easy to see how it could be exploited in a malicious way.

Typically an AutoOpen attribute is declared on a module in a nonempty namespace, so that open-ing the namespace will implicitly open the module. Of course, consumers of external packages should always take care when using open declarations of external packages' namespaces and modules. However, in the empty namespace, this will happen unconditionally with no open usage at all, and, since there is currently no good standard way to disable transitive NuGet package references ( dotnet/sdk#11803 ), the AutoOpen will transitively infect all packages and projects that depend on the offending package.

While the F# style guide advises programmers to take care in using AutoOpen and RequireQualifiedAccess in their own code, there is nothing stopping a library author from abusing AutoOpen in this way to e.g. typo-squat a malicious definition onto a standard type or module and infecting even codebases that are very careful about managing their dependencies.

I propose that the compiler should not honor AutoOpen declarations on modules declared in the empty namespace.

@vzarytovskii
Copy link
Member

We allow auto-open on assembly too, so it's not something unexpected. Not entirely sure we can change the behaviour, since it will be breaking. We can consider it as an additional analyser (external or built-in) in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

3 participants