Skip to content

Commit 9a047b6

Browse files
committed
escape tags so it is safe from xss
1 parent edd7e44 commit 9a047b6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/fusioncharts/rails/chart.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def jsonUrl?
8484

8585
# Render the chart
8686
def render
87-
config = self.options.to_json
87+
config = json_escape JSON.generate(self.options)
8888
dataUrlFormat = self.jsonUrl? ? "json" : ( self.xmlUrl ? "xml" : nil )
8989
template = File.read(File.expand_path("../../../templates/chart.erb", __FILE__))
9090
renderer = ERB.new(template)
@@ -118,6 +118,11 @@ def parse_options
118118
parse_datasource_json
119119
end
120120

121+
# Escape tags in json, if avoided might be vulnerable to XSS
122+
def json_escape(str)
123+
str.to_s.gsub('/', '\/')
124+
end
125+
121126
end
122127

123128
end

0 commit comments

Comments
 (0)