Skip to content

Commit 5a5ffe5

Browse files
committed
Fix transformers to avoid XSS
1 parent ab12a3e commit 5a5ffe5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/qiita/markdown/transformers/filter_iframe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def node
4242

4343
def host_of(url)
4444
if url
45-
port = URI.parse(url).port
46-
Addressable::URI.parse(url).host if [443, 80].include? port
45+
scheme = URI.parse(url).scheme
46+
Addressable::URI.parse(url).host if ["http", "https"].include? scheme
4747
end
4848
rescue Addressable::URI::InvalidURIError
4949
nil

lib/qiita/markdown/transformers/filter_script.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def node
4444

4545
def host_of(url)
4646
if url
47-
port = URI.parse(url).port
48-
Addressable::URI.parse(url).host if [443, 80].include? port
47+
scheme = URI.parse(url).scheme
48+
Addressable::URI.parse(url).host if ["http", "https"].include? scheme
4949
end
5050
rescue Addressable::URI::InvalidURIError
5151
nil

spec/qiita/markdown/processor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@
16161616
context "with embed iframe code with xss" do
16171617
let(:markdown) do
16181618
<<-MARKDOWN.strip_heredoc
1619-
<iframe src="javascript://docs.google.com/presentation/d/example/embed" frameborder="0" width="482" height="300" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
1619+
<iframe src="javascript://docs.google.com:80/%0d%0aalert(document.domain)" frameborder="0" width="482" height="300" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
16201620
MARKDOWN
16211621

16221622
it "forces width attribute on iframe" do

0 commit comments

Comments
 (0)