mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
SECURITY: fix XSS
This commit is contained in:
parent
258c353307
commit
d65efe7304
@ -261,6 +261,7 @@ class DiscourseDiff
|
|||||||
end
|
end
|
||||||
|
|
||||||
def characters(string)
|
def characters(string)
|
||||||
|
string = CGI::escapeHTML(string)
|
||||||
@tokens.concat string.scan(/(\W|\w+[ \t]*)/).flatten
|
@tokens.concat string.scan(/(\W|\w+[ \t]*)/).flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,6 +5,17 @@ describe DiscourseDiff do
|
|||||||
|
|
||||||
describe "inline_html" do
|
describe "inline_html" do
|
||||||
|
|
||||||
|
it "doest not lead to XSS" do
|
||||||
|
a = "<test>start</test>"
|
||||||
|
b = "<test>end</test>"
|
||||||
|
prev = "<div>#{CGI::escapeHTML(a)}</div>"
|
||||||
|
cur = "<div>#{CGI::escapeHTML(b)}</div>"
|
||||||
|
|
||||||
|
diff = DiscourseDiff.new(prev,cur)
|
||||||
|
diff.inline_html.should_not =~ /<\/?test>/
|
||||||
|
diff.side_by_side_html.should_not =~ /<\/?test>/
|
||||||
|
end
|
||||||
|
|
||||||
it "returns an empty div when no content is diffed" do
|
it "returns an empty div when no content is diffed" do
|
||||||
DiscourseDiff.new("", "").inline_html.should == "<div class=\"inline-diff\"></div>"
|
DiscourseDiff.new("", "").inline_html.should == "<div class=\"inline-diff\"></div>"
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user