Repository navigation
Redact credentials in gem sources and gem env output - #10139
Closed
sourya2704 wants to merge 1 commit into
Closed
sourya2704 wants to merge 1 commit into
sourya2704 wants to merge 1 commit into
Conversation
`gem sources`, `gem env` and `gem env remotesources` printed source URLs as they are stored, so a password or token in a private source URL, or in `http_proxy`, ended up in the terminal, CI logs and bug reports. Use Gem::Uri.redact wherever these commands print a source URL: the source list, the add/append/prepend/remove messages, the typo squatting and insecure rubygems.org prompts, the REMOTE SOURCES section and the :sources and :http_proxy values in GEM CONFIGURATION. The URLs saved in the configuration are unchanged. Fixes ruby#9831
Member
|
I decided in #9831 to keep printing source URLs as configured, so I'm closing this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was the end-user or developer problem that led to this PR?
Fixes #9831.
Private gem sources often have credentials in the URL, like
https://user:password@gems.example.com/orhttps://token@gems.example.com/.gem sourcesandgem envprint those URLs as they're stored, so the password ends up in the terminal, in CI logs and in pasted bug reports:RubyGems already redacts these URLs in some places, like
Error fetching ...ingem sources(#4564 did the same for verbose mode), but not in the normal output of these two commands.What is your fix for the problem, implemented in this PR?
Use
Gem::Uri.redacteverywhere these commands print a source URL. It replaces the password withREDACTED, or the user when it's a token:gem sourcesandgem sources --list--add,--append,--prependand--removemessageshttp://rubygems.orgpromptgem env remotesourcesgem env: theREMOTE SOURCESsection, and the:sourcesand:http_proxyvalues inGEM CONFIGURATION. Those values come straight from.gemrc, so they're redacted too.With this PR:
Only the output changes. The URLs stored in
.gemrcand used for fetching keep their credentials, andtest_execute_add_redacts_credentialschecks thatGem.sourcesstill has the full URL.One trade-off, discussed in #9831: you can't copy a URL from
gem sourcesintogem sources --removeanymore. The full URL is still in.gemrc, and I think not leaking it is worth more.environment_command.rbnow requires../uri. Without it, plaingem envraisedNameError: uninitialized constant Gem::Uribecause nothing had loaded it yet. The tests didn't catch that because the test helper loads it, so I also checked the real commands with a.gemrclike the one above.Make sure the following tasks are checked
Tests: 7 new tests in
test_gem_commands_sources_command.rbandtest_gem_commands_environment_command.rb. All 7 fail without the fix. All tests in both files pass, andbin/rubocopreports no offenses on the changed files.