diff --git a/changelogs/unreleased/security-fix-project-existence-disclosure-master.yml b/changelogs/unreleased/security-fix-project-existence-disclosure-master.yml
new file mode 100644
index 0000000000000000000000000000000000000000..084439c71d94f3de3eb3794f7d0fd98041e625e7
--- /dev/null
+++ b/changelogs/unreleased/security-fix-project-existence-disclosure-master.yml
@@ -0,0 +1,5 @@
+---
+title: Fix url redaction for issue links
+merge_request:
+author:
+type: security
diff --git a/lib/banzai/redactor.rb b/lib/banzai/redactor.rb
index 7db5f5e1f7d3022e1adf118d897217f8a3b7f832..c2da7fec7cc299e68989ef174dd4ebd8486f37c2 100644
--- a/lib/banzai/redactor.rb
+++ b/lib/banzai/redactor.rb
@@ -70,8 +70,11 @@ module Banzai
# Build the raw tag just with a link as href and content if
# it's originally a link pattern. We shouldn't return a plain text href.
original_link =
- if link_reference == 'true' && href = original_content
- %(#{href})
+ if link_reference == 'true'
+ href = node.attr('href')
+ content = original_content
+
+ %(#{content})
end
# The reference should be replaced by the original link's content,
diff --git a/spec/lib/banzai/redactor_spec.rb b/spec/lib/banzai/redactor_spec.rb
index aaeec953e4b513eea4a2e45a8f369b015a12f4a4..718649e0e1019d76c0cb4d2b9fc4d8442423f921 100644
--- a/spec/lib/banzai/redactor_spec.rb
+++ b/spec/lib/banzai/redactor_spec.rb
@@ -13,10 +13,10 @@ describe Banzai::Redactor do
it 'redacts an array of documents' do
doc1 = Nokogiri::HTML
- .fragment('foo')
+ .fragment('foo')
doc2 = Nokogiri::HTML
- .fragment('bar')
+ .fragment('bar')
redacted_data = redactor.redact([doc1, doc2])
@@ -27,7 +27,7 @@ describe Banzai::Redactor do
end
it 'replaces redacted reference with inner HTML' do
- doc = Nokogiri::HTML.fragment("foo")
+ doc = Nokogiri::HTML.fragment("foo")
redactor.redact([doc])
expect(doc.to_html).to eq('foo')
end
@@ -35,20 +35,24 @@ describe Banzai::Redactor do
context 'when data-original attribute provided' do
let(:original_content) { 'foo' }
it 'replaces redacted reference with original content' do
- doc = Nokogiri::HTML.fragment("bar")
+ doc = Nokogiri::HTML.fragment("bar")
redactor.redact([doc])
expect(doc.to_html).to eq(original_content)
end
- end
-
- it 'returns tag with original href if it is originally a link reference' do
- href = 'http://localhost:3000'
- doc = Nokogiri::HTML
- .fragment("#{href}")
- redactor.redact([doc])
+ it 'does not replace redacted reference with original content if href is given' do
+ html = "Marge"
+ doc = Nokogiri::HTML.fragment(html)
+ redactor.redact([doc])
+ expect(doc.to_html).to eq('Marge')
+ end
- expect(doc.to_html).to eq('http://localhost:3000')
+ it 'uses the original content as the link content if given' do
+ html = "Marge"
+ doc = Nokogiri::HTML.fragment(html)
+ redactor.redact([doc])
+ expect(doc.to_html).to eq('Homer')
+ end
end
end
@@ -61,7 +65,7 @@ describe Banzai::Redactor do
end
it 'redacts an issue attached' do
- doc = Nokogiri::HTML.fragment("foo")
+ doc = Nokogiri::HTML.fragment("foo")
redactor.redact([doc])
@@ -69,7 +73,7 @@ describe Banzai::Redactor do
end
it 'redacts an external issue' do
- doc = Nokogiri::HTML.fragment("foo")
+ doc = Nokogiri::HTML.fragment("foo")
redactor.redact([doc])