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

Generate an error or warning when building under the downloads folder #45342

Open
dsplaisted opened this issue Dec 5, 2024 · 9 comments · May be fixed by dotnet/msbuild#11286
Open

Generate an error or warning when building under the downloads folder #45342

dsplaisted opened this issue Dec 5, 2024 · 9 comments · May be fixed by dotnet/msbuild#11286

Comments

@dsplaisted
Copy link
Member

Building a project under the downloads folder is not very safe. This is because of things like Directory.Build.props, which mean that you need to trust all of the parent folders of your source code up to the root. Most browsers will download files to the downloads folder with no additional confirmation when you click a link, so a malicious link could put a Directory.Build.props file in your downloads folder, and then execute code in your build when you subsequently built a project that had been downloaded (or extracted) under the downloads folder.

We should probably fail outright, or at least warn, when trying to build a project under the Downloads folder.

This probably makes sense to be an MSBuild feature. Possibly it should be a BuildCheck, but maybe it should just be built into MSBuild by default before it even tries to start the build.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Dec 5, 2024
@Forgind Forgind added needs team triage Requires a full team discussion and removed untriaged Request triage from a team member labels Dec 10, 2024
@Forgind
Copy link
Member

Forgind commented Dec 10, 2024

<security label>

@marcpopMSFT marcpopMSFT removed the needs team triage Requires a full team discussion label Dec 10, 2024
@marcpopMSFT marcpopMSFT added this to the 10.0.1xx milestone Dec 10, 2024
@marcpopMSFT
Copy link
Member

@dotnet/msbuild @dsplaisted we should have a discussion on this one of the best path forward. Should we block? Should we buildcheck/warn? Does this have to be done in msbuild land?

@marcpopMSFT marcpopMSFT added the needs team triage Requires a full team discussion label Dec 10, 2024
@YuliiaKovalova
Copy link
Member

@JanKrivanek has already developed a custom build check to track invalid location:
https://github.com/dotutils/BuildChecks/blob/main/src/UntrustedLocationCheck.cs

It's available in this nuget, you can give it a try right away
https://www.nuget.org/packages/DotUtils.BuildChecks/0.0.6-beta

@marcpopMSFT
Copy link
Member

Ooh, very cool. It's already there. Are there plans to add this to the built-in buildchecks?

@marcpopMSFT
Copy link
Member

@JanKrivanek thoughts on including this as a built-in eventually?

@JanKrivanek
Copy link
Member

Detecting Downloads folder is surprisingly complicated - so I'm not sure we want to have it as a default diagnostic, but a built-in buildcheck sounds fine.
Btw. just opening the project in IDE is same dangerous, however less obvious to users.

More general version of this check is "You are importing logic that is outside of the root of your solution/repository/..."

This is just one of many security footguns that MSBuild can bring - we have a due to openly document those (dotnet/msbuild#10739) - so that we can then start pointing users from such new diagnostics to more comprehensive overview, so that we prevent false sense of security by preventing just some of those (we cannot prevent everything that is dangerous as extensibility points are vital part of MSBuild. Over time I'm hoping to collect more tel around usage of various extensibility points and start flipping the more esoteric ones to explicit opt-in mode)

@marcpopMSFT
Copy link
Member

@JanKrivanek my understanding is that there is already a buildcheck for this. What are the plans to add that included in the built-in ones?

@JanKrivanek
Copy link
Member

This is not currently planned (other areas of investments are getting precedence in a near future).

But I'll try to find same spare time to copy it to built-in checks - stay tunned :-)

@JanKrivanek JanKrivanek self-assigned this Jan 14, 2025
@JanKrivanek JanKrivanek linked a pull request Jan 14, 2025 that will close this issue
@marcpopMSFT marcpopMSFT removed the needs team triage Requires a full team discussion label Jan 14, 2025
@marcpopMSFT
Copy link
Member

@JanKrivanek buildchecks run after the build has completed? Daniel points out that this would be too late if there were something malicious going on. Could msbuild startup code potentially block this entirely (unless an env is set) and is that something you'd want to consider?

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

Successfully merging a pull request may close this issue.

5 participants