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

Symbolic link attack within coverage directory can overwrite files elsewhere #134

Open
h3xx opened this issue Apr 11, 2024 · 1 comment
Open

Comments

@h3xx
Copy link

h3xx commented Apr 11, 2024

If an existing symbolic link exists inside the coverage directory, it can overwrite arbitrary files elsewhere on the system.

This is also true for hard-linked files.

This library MUST remove the files in the coverage before attempting to overwrite them in order to fix this security issue.

Steps to repro:

echo "Don't delete me!" >~/super-important-file.txt

# Set up a rails project with SimpleCov coverage testing
rails new --skip-bootsnap temp
cd temp
bundle add simplecov
printf 'require "simplecov"\nSimpleCov.start "rails"\n' >>test/test_helper.rb

# Set up our symlink attack vector
mkdir -p coverage
ln -s ~/super-important-file.txt coverage/index.html

# Run the test -- this OVERWRITES ~/super-important-file.txt
bin/rails test
cat ~/super-important-file.txt
# Our file has been replaced with HTML :-(

This is only an example, but imagine if you were running tests as root.

Related issue: #133 -- when this one is fixed, that one will also likely be fixed.

@PragTob
Copy link
Collaborator

PragTob commented Apr 15, 2024

Hey, thanks for the report.

I'm not clear how this is an exploitable fault on SimpleCov's side. For this to be an exploitable vulnerability someone would already need to have enough access to your system to create a symlink in a directory. SimpleCov also isn't run in production, but in development or on a CI server.

If someone had write access to files on a computer where SimpleCov is running they could rewrite/append to any given ruby file and modify it to instead arbitrary code execution.

What am I missing?

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

No branches or pull requests

2 participants