Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from github-markdown to github-markup #3919

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ gem 'faraday-http-cache'
gem 'warden'
gem 'active_hash'
gem 'ansible'
gem 'github-markdown'
gem 'github-markup'
gem 'commonmarker'
gem 'coderay'
gem 'net-http-persistent'
gem 'concurrent-ruby'
Expand Down
9 changes: 7 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ GEM
thor (>= 0.18, < 2)
byebug (8.2.2)
coderay (1.1.1)
commonmarker (0.21.1)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.7)
connection_pool (2.2.1)
crack (0.4.3)
Expand Down Expand Up @@ -316,7 +318,7 @@ GEM
forking_test_runner (1.2.0)
parallel_tests (>= 1.3.7)
git_diff_parser (3.1.0)
github-markdown (0.6.9)
github-markup (3.0.5)
gitlab (4.10.0)
httparty (~> 0.14, >= 0.14.0)
terminal-table (~> 1.5, >= 1.5.1)
Expand Down Expand Up @@ -560,6 +562,8 @@ GEM
rubocop-rails (2.3.2)
rack (>= 1.1)
rubocop (>= 0.72.0)
ruby-enum (0.8.0)
i18n
ruby-progressbar (1.10.1)
ruby_parser (3.13.1)
sexp_processor (~> 4.9)
Expand Down Expand Up @@ -644,6 +648,7 @@ DEPENDENCIES
bundler
bundler-audit
coderay
commonmarker
concurrent-ruby
connection_pool
dalli
Expand All @@ -656,7 +661,7 @@ DEPENDENCIES
flay
forking_test_runner
gcloud_image_tagger!
github-markdown
github-markup
goldiloader
large_object_store
lograge
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'ansible'
require 'github/markdown'
require 'github/markup'

module ApplicationHelper
BOOTSTRAP_FLASH_MAPPINGS = {
Expand All @@ -27,7 +27,7 @@ def autolink(text)

# https://github.com/showdownjs/showdown/wiki/Markdown's-XSS-Vulnerability-(and-how-to-mitigate-it)
def markdown(str)
sanitize GitHub::Markdown.render_gfm(str)
sanitize GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, str)
end

def deploy_link(project, stage)
Expand Down
10 changes: 8 additions & 2 deletions test/helpers/application_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@
end

it "does not allow XSS" do
result = markdown("<script>alert(1)</script>")
result.must_equal "alert(1)\n"
result = markdown("foo <script>alert(1)</script> ")
result.must_equal "<p>foo alert(1)</p>\n"
assert result.html_safe?
end

it "does not allow XSS, strips entire tag" do
result = markdown("<script>alert(1)</script> ")
result.must_equal "\n"
assert result.html_safe?
end
end
Expand Down