-
Notifications
You must be signed in to change notification settings - Fork 256
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
Questions about automatic "system gemrc" file creation #388
Comments
This is a security risk, since Rubygems reads this I had a discussion with @hsbt and @unak about this topic on hackerone in 2022. They concluded about not to change anything in Rubygems. So I went further and implemented this simple solution, that the very first call of The issue doesn't affect platforms other than Windows. |
We had an issue with fiddle in the past, that looks like this issue with etc loaded too soon: #251 . The way I solved it was to build a RubyInstaller specific Ruby C extension, which can call the Win32 API functions without fiddle. Now that etc is gemified, we have the same issue here. The etc gem loading is triggered by accessing the constant |
Thanks for the explanation, yeah, that's what I imagined. Are there paths on Windows that can be changed only by administrators ("root users")? I'd expect the system wide configuration to be writable only by administrators, and I'd say that's the main issue here. I wonder, for example, which path does Should we use an alternative secure path for this "system wide config"? Should we refuse to load it at all if it's parent directory is writable by the current user? In any case, I still don't fully understand the solution. If the file is hijacked before RubyGems is loaded, then the solution won't be effective, right? Shouldn't the file be unconditionally overwritten for the hack to be effective? How do we distinguish between a well intended system configuration vs a malicious attempt to hijack configuration?
That makes sense although it'd mean having duplication with the |
@larskanis I have one question.
This doesn't work. Why is there the default content Do we need to overwrite this file completely?
I am not familiar with Windows permissions, but is this safe? |
Sorry, this is YAML.
But I can't add key-value to this content because
It prevents us from adding a config. We need to overwrite this file to do it. Hmm, I see. We need |
I have confirmed that overwriting the file doesn't change the ACL. fluent/fluentd-docker-image#398 (comment)
|
hi @daipom and @deivid-rodriguez - what's the next step here? Is this OK or are you still looking for some other change? Accordingly, I will leave this open or recommend to close it. Thanks! |
I had some questions about this in #388 (comment), which I'd still be interested in, but I'm fine to close this since as of now, there's no specific action to be taken in RubyInstaller2. This issue was mainly a question to try understand things better. |
Closing this for now. Thanks! |
Thanks! Sorry for my late response. My question was resolved, so I'm OK with closing this. If there could be other users who are as troubled as I am, it might be a good idea to improve this comment. rubyinstaller2/resources/files/operating_system.rb Lines 56 to 74 in 3f896e7
|
The previous "{}" literal closed the root hash, so that appending text to the file doesn't work easily. But it's the only way to set an empty hash. As a solution, we set a single key now. This was raised in #388 (comment)
What problems are you experiencing?
No problems, but I was investigating an issue about the
etc
gem being activated too soon on Windows, and eventually run into some code in theoperating_system.rb
file shipped by RubyInstaller2 that automatically creates an empty "system gemrc" file if it does not exist already:rubyinstaller2/resources/files/operating_system.rb
Lines 56 to 74 in 3f896e7
I got curious about the potential security issue. Does it affect more platforms other than Windows? The way I see it, system configuration is precisely intended for sharing a configuration with all users, so it's intended that a user with permissions to write files in
Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
can setup RubyGems configurations for all users. Also, it seems that the current implementation will still respect this global file if it's already there.So I'm not fully clear about the security issue and I'm looking for a bit more insights.
Steps to reproduce
Create an empty Gemfile and observe that
ruby -rbundler/setup -e 'puts Gem.loaded_specs["etc"]'
activates theetc
gem on Windows.The text was updated successfully, but these errors were encountered: