Skip to content

Commit

Permalink
Cherry pick security fix (#274) to 2-6-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Weingarten committed Jan 10, 2014
1 parent 4420412 commit eb409ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
IMPORTANT: Liquid 2.6 is going to be the last version of Liquid which maintains explicit Ruby 1.8 compatability.
The following releases will only be tested against Ruby 1.9 and Ruby 2.0 and are likely to break on Ruby 1.8.

## 2.6.0 / 2013-11-25 / branch "2.6-stable"
## 2.6.1 / 2014-01-10 / branch "2-6-stable"

Security fix, cherry-picked from master (4e14a65):
* Don't call to_sym when creating conditions for security reasons, see #273 [Bouke van der Bijl, bouk]
* Prevent arbitrary method invocation on condition objects, see #274 [Dylan Thacker-Smith, dylanahsmith]

## 2.6.0 / 2013-11-25

* ...
* Bugfix for #106: fix example servlet [gnowoel]
Expand Down
6 changes: 3 additions & 3 deletions lib/liquid/tags/if.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class If < Block
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/o
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/o
BOOLEAN_OPERATORS = %w(and or)

def initialize(tag_name, markup, tokens)
@blocks = []
Expand Down Expand Up @@ -61,7 +62,8 @@ def push_block(tag, markup)
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax

new_condition = Condition.new($1, $2, $3)
new_condition.send(operator.to_sym, condition)
raise SyntaxError, "invalid boolean operator" unless BOOLEAN_OPERATORS.include?(operator)
new_condition.send(operator, condition)
condition = new_condition
end

Expand All @@ -71,8 +73,6 @@ def push_block(tag, markup)
@blocks.push(block)
@nodelist = block.attach(Array.new)
end


end

Template.register_tag('if', If)
Expand Down
6 changes: 6 additions & 0 deletions test/liquid/tags/if_else_tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,10 @@ def test_operators_are_ignored_unless_isolated
assert_template_result('yes',
%({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %}))
end

def test_operators_are_whitelisted
assert_raise(SyntaxError) do
assert_template_result('', %({% if 1 or throw or or 1 %}yes{% endif %}))
end
end
end # IfElseTest

0 comments on commit eb409ff

Please sign in to comment.