-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cargo may potentially publish sensitive information to registries when --allow-dirty
is passed
#9398
Comments
…untracked files by default
I just pushed a commit to my own branch (landaire@546c069) which implements the solution I proposed. There are some issues with this right now such as failing tests and the documentation has not been updated, but it works as intended. Tests need to be added for subrepositories and a pass needs to be done to cleanup code. Is this a good enough direction to create a draft PR? |
@landaire We really appreciate you taking the time to recognize and report this. This does seem like something that could be missed, and the risk of unintentionally disclosing something seems high enough to motivate a little more care. I personally think a name with That said, I don't think we should split this into two options. I think we should have one option that allows and includes all non-checked-in files, including dirty versions of tracked files, because I don't think there are likely to be circumstances in which someone wants one but not the other. It's more that people should be aware of both. We'd be happy to accept a PR that changes the text of that warning message to make it clearer. We may also be willing to accept a PR that changes the name of the option and hides the old option, if there's a single clear option name we can use that makes the full behavior clear. |
Thank you @joshtriplett for taking the time to review this issue.
I see your point, but this is exactly the behavior I want today. I leave untracked files in my working directory and am prevented from publishing a new version of my crate until I resolve the issue or just let everything through. Resolution from cargo's perspective would either be tracking these files in my VCS and committing the change or explicitly ignoring them. As the maintainer this either doesn't make sense (temp files shouldn't be committed), is unnecessary (temp files shouldn't need to be in my On the contrary, the argument can be made that Cargo doesn't and shouldn't know what files are used by your application and it should assume everything not ignored by Git is used. I personally expect a package on crates.io to match some commit in the manifest's I would be happy to create a PR to just include a new CLI option with clearer language and update the error message text. I do think the behavior as it stands today of error-by-default for untracked files is a poor UX and should be re-evalulated. |
@landaire Can you clarify something? Are you saying you'd like to be able to have untracked and unignored files in your crate's working directory and have Cargo include them, or are you saying you'd like Cargo to silently ignore those files rather than warning, or is there some third behavior you want? I've personally been saved from publishing a broken crate several times by Cargo making sure I don't have any untracked files. I've added a new |
Exactly this. Sometimes I move files into my working directory so I can just type the name instead of a full filesystem path or pipe the output of multiple runs to a temp file in my working directory. These are used just by me for my analysis or testing. I would like Cargo to always ignore these files, but warn me when files that are tracked by my VCS are dirty (this is useful for me to make sure there's no test code left behind).
Perhaps this could be handled by doing smarter logic in With the above changes to |
I don't think changing the list of files would necessarily help; anything that would ignore a new file would potentially cause breakage. There might be a potential solution there, but I think it'd need some further design and evaluation of tradeoffs. For the moment, at least, I'd request that you start with a PR updating the help text, along with a proposal for what a combined option could be called. Separately from that, if you're interested in changing the behavior further, I'd suggest making a list of use cases, soliciting additional use cases from others, and then showing how proposed solutions would behave for each of those use cases. Such use cases could include, for instance, "adding a new source file and forgetting to |
I want to second this issue. I'm surprised that random files that happen to be in my working dir are included in the package. The What is the recommended way of publishing a package from a repository with additional files, like the fuzzing corpus or other local development files? I want to keep those files, so Ideally, I would like to only include the source files required to build the targets in the crate. |
There's the |
In my case, I would like to have an
|
`--allow-dirty` doesn't allow us to be as granular as we'd like; see rust-lang/cargo#9398 (comment). This isn't foolproof but it gets us closer to what we want. The new `mk/publish.sh` is a step towards more robust publishing with tagging, etc.
`--allow-dirty` doesn't allow us to be as granular as we'd like; see rust-lang/cargo#9398 (comment). This isn't foolproof but it gets us closer to what we want. The new `mk/publish.sh` is a step towards more robust publishing with tagging, etc.
Problem
Cargo may include sensitive information when publishing a crate in a git directory with dirty or untracked files when using
cargo publish --allow-dirty
.The way I tend to operate in my projects includes occasionally doing
cargo run > output.txt
or moving sample files into my project root and not including these temporary files in my.gitignore
. When publishing a crate to a registry Cargo will warn the user if the git working directory is dirty or contains untracked files. This looks something like:I've seen this error a few times and was under the assumption that it was more of a warning that the version I'm publishing to crates.io may be out of sync with the version I'm going to publish to my Git repository.
There's some key wording here that you really need to pay attention to and think about: and include the uncommitted changes.
For untracked files this wording seems safe, since the files aren't even tracked by my git repo. It turns out
cargo-publish
does not include files ignored by.gitignore
, but includes everything else -- including untracked files. Since Cargo operates similarly to git and respects the.gitignore
, I initially did not believe this to be the case until I did some testing. This is a pretty serious footgun that can result in private information being accidentally disclosed to the world.Steps
cargo new --lib test
(lib or bin doesn't matter)cargo publish
to see the below output.cargo publish --allow-dirty
then use a tool likecargo-download
to download this crate and examine its contents withtar -tvf crate.tar.gz
Possible Solution(s)
Cargo should explicitly ignore untracked files by default, but warn about dirty files. This flag should also be split and changed to
--include-dirty
and--include-untracked
to reflect that the dirty/untracked files will be included in the tarball submitted to the registryNotes
Output of
cargo version
:cargo 1.52.0-nightly (90691f2bf 2021-03-16)
Related discussion which introduced this option: #2063
The text was updated successfully, but these errors were encountered: