Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
3.0.9 problem with $1, $2, etc. match vars not being set for safe text #1734
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
pplr
Jun 17, 2011
Rails 3.1.0.rc4 is also affected by this problem.
Here is a simple test case:
test "gsub" do
assert_equal("3", "--3--".html_safe.gsub(/--(\d+)--/){$1})
end
pplr
commented
Jun 17, 2011
Rails 3.1.0.rc4 is also affected by this problem. test "gsub" do
assert_equal("3", "--3--".html_safe.gsub(/--(\d+)--/){$1})
end |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
dmathieu
Jun 17, 2011
Contributor
The problem is $* variables are scoped to the enclosing method.
There's a discussion about this here : http://www.ruby-forum.com/topic/198458
Unfortunately, I'm afraid there's not much that can be done about it.
The problem is $* variables are scoped to the enclosing method. Unfortunately, I'm afraid there's not much that can be done about it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
jstraitiff-wk
Jun 17, 2011
Well, from my perspective, it worked in 3.0.6 and now doesn't in 3.0.9. It works with non-safe strings as I showed above. So it's the rails extensions breaking basic gsub() functionality that is very useful and used.....
So saying "there's not much that can be done" doesn't sit well...
jstraitiff-wk
commented
Jun 17, 2011
Well, from my perspective, it worked in 3.0.6 and now doesn't in 3.0.9. It works with non-safe strings as I showed above. So it's the rails extensions breaking basic gsub() functionality that is very useful and used..... So saying "there's not much that can be done" doesn't sit well... |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
dmathieu
Jun 17, 2011
Contributor
It's been changed between 3.0.7 and 3.0.8 because of a security issue.
http://weblog.rubyonrails.org/2011/6/8/potential-xss-vulnerability-in-ruby-on-rails-applications
html_safe objects are SafeBuffer objects.
This object overrides some unsafe methods, transforming them to strings as they transform the object and therefore, it becomes unsafe.
As gsub transforms the object, it has to be overriden.
Basically, the way of doing your gsub would be to work on unsafe strings. You can get one with to_str
string = "string".html_safe #=> Returns a SafeBuffer object
string.to_str #=> Returns a new string
It's been changed between 3.0.7 and 3.0.8 because of a security issue. html_safe objects are SafeBuffer objects. As gsub transforms the object, it has to be overriden.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
tardate
Jun 19, 2011
Contributor
NB: just cross-referencing, same issue as #1555
@dmathieu thanks for linking http://www.ruby-forum.com/topic/198458 - best explanation/discussion I've seen of why the magic matching variables break when you attempt to intercept gsub.
NB: just cross-referencing, same issue as #1555 |
Closing as a duplicate of #1555 |
jstraitiff-wk commentedJun 16, 2011
There seems to be a problem with regex $ variables and safe text:
So for html_escaped strings, the $ variables are not being set. The used to, i.e. the above code worked fine in 3.0.6
Here’s a gist of the problem:
https://gist.github.com/1030065
git://gist.github.com/1030065.git