mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 02:40:41 -07:00
Fix code injection vulnerability in template name handling
Use .inspect for all template/partial names inserted into generated
code strings to prevent code injection via maliciously crafted
template names like: {% render "foo'); system('rm -rf /'); #" %}
This commit is contained in:
@@ -303,7 +303,7 @@ module Liquid
|
|||||||
compile_partial_source(source, code)
|
compile_partial_source(source, code)
|
||||||
rescue => e
|
rescue => e
|
||||||
code.line "# Error compiling partial: #{e.message.inspect}"
|
code.line "# Error compiling partial: #{e.message.inspect}"
|
||||||
code.line "__partial_output__ << '[PARTIAL ERROR: #{name}]'"
|
code.line "__partial_output__ << '[PARTIAL ERROR: ' + #{name.inspect} + ']'"
|
||||||
end
|
end
|
||||||
|
|
||||||
code.blank_line
|
code.blank_line
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ module Liquid
|
|||||||
|
|
||||||
if partial_source
|
if partial_source
|
||||||
if compiler.debug?
|
if compiler.debug?
|
||||||
code.line "# Inlined partial '#{template_name}' at compile time"
|
code.line "# Inlined partial #{template_name.inspect} at compile time"
|
||||||
code.line "$stderr.puts '* WARN: Liquid file system access - inlined partial \\\"#{template_name}\\\" at compile time' if $VERBOSE"
|
code.line "$stderr.puts '* WARN: Liquid file system access - inlined partial ' + #{template_name.inspect} + ' at compile time' if $VERBOSE"
|
||||||
end
|
end
|
||||||
# Generate a unique method name for this partial
|
# Generate a unique method name for this partial
|
||||||
method_name = compiler.register_partial(template_name, partial_source)
|
method_name = compiler.register_partial(template_name, partial_source)
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ module Liquid
|
|||||||
|
|
||||||
if partial_source
|
if partial_source
|
||||||
if compiler.debug?
|
if compiler.debug?
|
||||||
code.line "# Inlined partial '#{template_name}' at compile time"
|
code.line "# Inlined partial #{template_name.inspect} at compile time"
|
||||||
code.line "$stderr.puts '* WARN: Liquid file system access - inlined partial \\\"#{template_name}\\\" at compile time' if $VERBOSE"
|
code.line "$stderr.puts '* WARN: Liquid file system access - inlined partial ' + #{template_name.inspect} + ' at compile time' if $VERBOSE"
|
||||||
end
|
end
|
||||||
# Generate a unique method name for this partial
|
# Generate a unique method name for this partial
|
||||||
method_name = compiler.register_partial(template_name, partial_source)
|
method_name = compiler.register_partial(template_name, partial_source)
|
||||||
|
|||||||
Reference in New Issue
Block a user