mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Check and handle when a tainted variable is used
This commit is contained in:
@@ -54,5 +54,6 @@ module Liquid
|
|||||||
class StandardError < Error; end
|
class StandardError < Error; end
|
||||||
class SyntaxError < Error; end
|
class SyntaxError < Error; end
|
||||||
class StackLevelError < Error; end
|
class StackLevelError < Error; end
|
||||||
|
class TaintedError < Error; end
|
||||||
class MemoryError < Error; end
|
class MemoryError < Error; end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -60,6 +60,12 @@ module Liquid
|
|||||||
# :strict will enforce correct syntax.
|
# :strict will enforce correct syntax.
|
||||||
attr_writer :error_mode
|
attr_writer :error_mode
|
||||||
|
|
||||||
|
# Sets how strict the taint checker should be.
|
||||||
|
# :lax ignores the taint flag completely (like previous liquid versions)
|
||||||
|
# :warn adds a warning, but does not interrupt the rendering
|
||||||
|
# :error raises an error when tainted output is used
|
||||||
|
attr_writer :taint_mode
|
||||||
|
|
||||||
def file_system
|
def file_system
|
||||||
@@file_system
|
@@file_system
|
||||||
end
|
end
|
||||||
@@ -80,6 +86,10 @@ module Liquid
|
|||||||
@error_mode || :lax
|
@error_mode || :lax
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def taint_mode
|
||||||
|
@taint_mode || :lax
|
||||||
|
end
|
||||||
|
|
||||||
# Pass a module with filter methods which should be available
|
# Pass a module with filter methods which should be available
|
||||||
# to all liquid views. Good for registering the standard library
|
# to all liquid views. Good for registering the standard library
|
||||||
def register_filter(mod)
|
def register_filter(mod)
|
||||||
|
|||||||
@@ -94,6 +94,16 @@ module Liquid
|
|||||||
end
|
end
|
||||||
filterargs << keyword_args unless keyword_args.empty?
|
filterargs << keyword_args unless keyword_args.empty?
|
||||||
output = context.invoke(filter[0], output, *filterargs)
|
output = context.invoke(filter[0], output, *filterargs)
|
||||||
|
end.tap do |obj|
|
||||||
|
if obj.tainted?
|
||||||
|
case Template.taint_mode
|
||||||
|
when :warn
|
||||||
|
@warnings ||= []
|
||||||
|
@warnings << "variable '#{@name}' is tainted and was not escaped"
|
||||||
|
when :error
|
||||||
|
raise TaintedError, "Error - variable '#{@name}' is tainted and was not escaped"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user