ruby / ruby/rubygems

Gemfile require option allows you to require any file

Open
#6,453 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bundler
Dominant language
Ruby
Stars
4k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
81

Description

Describe the problem as clearly as you can

Within the Gemfile, you can do:

gem 'foo', require: ["foo", "foo/some/other/file/in/gem"]

This is useful if you want to automatically require some other entrypoint for the gem.

Today, I just realized that this simply passes the value to Kernel.require, which means you can require any file in the filesystem.

gem 'foo', require: ["/some/ruby/file/in/fs", "../../../some/other/file/relative/to/path"]

It seems intuitive if the files that you require in the gem directive are scoped to that gem. I'm not sure if this is a vulnerability since it's code that you own/written, but I think a little lockdown here would be good. Ideally, whatever is passed through to require: [...] is validated and appended to the gem's path. The validation would simply not allow a final (computed) path in require that is outside the gem's path.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Gemfile gem directive and trace how its require option reaches Kernel.require. Determine how the requested path should be validated against the gem's path, including absolute and relative paths; done means out-of-scope files are rejected while valid gem entrypoints still load.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.