diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index 1b8bb46d25ed29bcc644e996b64309dff14ff3ec..658134821202f227b264514bbb58161128949021 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -59,7 +59,7 @@ module GitlabMarkdownHelper
     user = current_user if defined?(current_user)
 
     html = Gitlab::Markdown.render(text, context)
-    Gitlab::Markdown.post_process(html, pipeline: context[:pipeline], user: user)
+    Gitlab::Markdown.post_process(html, pipeline: context[:pipeline], project: @project, user: user)
   end
 
   # TODO (rspeicher): Remove all usages of this helper and just call `markdown`
@@ -78,7 +78,7 @@ module GitlabMarkdownHelper
     user = current_user if defined?(current_user)
 
     html = Gitlab::Markdown.gfm(text, options)
-    Gitlab::Markdown.post_process(html, pipeline: options[:pipeline], user: user)
+    Gitlab::Markdown.post_process(html, pipeline: options[:pipeline], project: @project, user: user)
   end
 
   def asciidoc(text)
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb
index f389d0a80dd4e2a2d17cec1de8688c185545ac39..d5b0060dd56806695e31b913a73c05bbb888d3f4 100644
--- a/lib/gitlab/markdown.rb
+++ b/lib/gitlab/markdown.rb
@@ -47,12 +47,17 @@ module Gitlab
     #
     # html     - String to process
     # options  - Hash of options to customize output
-    #            :pipeline - Symbol pipeline type
-    #            :user     - User object
+    #            :pipeline  - Symbol pipeline type
+    #            :project   - Project
+    #            :user      - User object
     #
     # Returns an HTML-safe String
     def self.post_process(html, options)
-      doc = post_processor.to_document(html, current_user: options[:user])
+      context = {
+        project:      options[:project],
+        current_user: options[:user]
+      }
+      doc = post_processor.to_document(html, context)
 
       if options[:pipeline] == :atom
         doc.to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_XHTML)
diff --git a/lib/gitlab/markdown/reference_filter.rb b/lib/gitlab/markdown/reference_filter.rb
index c7d4b15d4580909cbdce6ba90c6e8ba285e2a9db..0ea966c744bf0563d8abd203ce2c329363e99fad 100644
--- a/lib/gitlab/markdown/reference_filter.rb
+++ b/lib/gitlab/markdown/reference_filter.rb
@@ -15,7 +15,7 @@ module Gitlab
       def self.user_can_reference?(user, node, context)
         if node.has_attribute?('data-project')
           project_id = node.attr('data-project').to_i
-          return true if project_id == context[:project].id
+          return true if project_id == context[:project].try(:id)
 
           project = Project.find(project_id) rescue nil
           Ability.abilities.allowed?(user, :read_project, project)