Commit 7826abb9adc2531bf33c5c25f2c713e543aa8b5f

Authored by Victor Costa
1 parent 170a723e

virtuoso: strip tags from rdf content

plugins/virtuoso/lib/ext/literal.rb
1 1 class RDF::Literal
2 2  
  3 + include ActionView::Helpers::SanitizeHelper
  4 +
3 5 def to_liquid
4   - value
  6 + strip_tags(value)
5 7 end
6 8  
7 9 end
... ...
plugins/virtuoso/test/unit/triples_template_test.rb
... ... @@ -38,4 +38,13 @@ class TriplesTemplateTest < ActiveSupport::TestCase
38 38 assert_match /<p style="color:red">World<\/p>/, content
39 39 end
40 40  
  41 + should 'do not allow js injection' do
  42 + article.stubs(:plugin).returns(mock)
  43 + article.plugin.expects(:virtuoso_client).at_least_once.returns(mock)
  44 + article.plugin.virtuoso_client.expects(:query).returns([{'var' => RDF::Literal.new('<script>alert("hello");</script>')}])
  45 + article.template = "{% for row in results %}{{row.var}}{% endfor %}"
  46 +
  47 + assert_no_match /<script>/, article.template_content
  48 + end
  49 +
41 50 end
... ...