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

Safer loading for translation repositories #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

renchap
Copy link
Contributor

@renchap renchap commented Aug 17, 2017

This fixes the two specs marked as pending on Ruby 2.x.

I am not 100% sure here about the relative path. Are there some wanted cases where the previous require will require another file when using the LOAD_PATH?

__dir__ and %i[] are only available in Ruby 2.x. I do not think this will be a problem.

- Do not use a relative path for require, as it fails with safe mode enabled.
- Check the repository type against a whitelist of existing repositories

This fixes the two specs marked as pending on Ruby 2.x
@renchap renchap changed the title Do not use a relative path for require, as it fails with safe mode enabled Safer loading for translation repositories Aug 17, 2017
class_name = type.to_s.split('_').map(&:capitalize).join
unless FastGettext::TranslationRepository.constants.map{|c|c.to_s}.include?(class_name)
require "fast_gettext/translation_repository/#{type}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just .untaint here ?

@grosser
Copy link
Owner

grosser commented Aug 17, 2017

being able to load any kind of backend was meant as a feature ...
how about doing backend =~ \A[a-z\d_]+\z`` to make sure nothing weird is going on and keeping the original with .untaint ?

@renchap
Copy link
Contributor Author

renchap commented Aug 17, 2017

A SecurityError is raised when using require "fast_gettext/translation_repository/#{type}".untaint.

I think this may be a bug in rubygems similar to rubygems/rubygems#1265
I need to investigate further why this is happening if relying on $LOAD_PATH is wanted.

@grosser
Copy link
Owner

grosser commented Aug 17, 2017 via email

@renchap
Copy link
Contributor Author

renchap commented Aug 17, 2017

Yes this one has been merged, but the problem still occurs with a recent Rubygem.

@grosser
Copy link
Owner

grosser commented Aug 17, 2017 via email

@renchap
Copy link
Contributor Author

renchap commented Aug 17, 2017

I will try to debug it and find out the real cause

@grosser grosser force-pushed the master branch 7 times, most recently from ddd5db9 to eb5d893 Compare August 27, 2021 05:22
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

Successfully merging this pull request may close these issues.

2 participants