Check and handle when a tainted variable is used

This commit is contained in:
Evan Huus
2014-09-16 17:23:26 +00:00
parent 638455ed92
commit e836024dd9
3 changed files with 21 additions and 0 deletions
+1
View File
@@ -54,5 +54,6 @@ module Liquid
class StandardError < Error; end
class SyntaxError < Error; end
class StackLevelError < Error; end
class TaintedError < Error; end
class MemoryError < Error; end
end
+10
View File
@@ -60,6 +60,12 @@ module Liquid
# :strict will enforce correct syntax.
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
@@file_system
end
@@ -80,6 +86,10 @@ module Liquid
@error_mode || :lax
end
def taint_mode
@taint_mode || :lax
end
# Pass a module with filter methods which should be available
# to all liquid views. Good for registering the standard library
def register_filter(mod)
+10
View File
@@ -94,6 +94,16 @@ module Liquid
end
filterargs << keyword_args unless keyword_args.empty?
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