]> cat aescling's git repositories - mastodon.git/commitdiff
Fix malformed HTML causing uncaught error (#13042)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 7 Feb 2020 14:24:22 +0000 (15:24 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Feb 2020 14:24:22 +0000 (15:24 +0100)
Fix OEmbed preview API leaking existence of private statuses (see #12930)

app/controllers/api/web/embeds_controller.rb
app/lib/formatter.rb

index 6231733b71aa101f395a7e8b80f7ea684d488b3c..4aa31695c701463714a9f936c85a304464520389 100644 (file)
@@ -7,15 +7,21 @@ class Api::Web::EmbedsController < Api::Web::BaseController
 
   def create
     status = StatusFinder.new(params[:url]).status
+
+    return not_found if status.hidden?
+
     render json: status, serializer: OEmbedSerializer, width: 400
   rescue ActiveRecord::RecordNotFound
     oembed = FetchOEmbedService.new.call(params[:url])
-    oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED) if oembed[:html].present?
 
-    if oembed
-      render json: oembed
-    else
-      render json: {}, status: :not_found
+    return not_found if oembed.nil?
+
+    begin
+      oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
+    rescue ArgumentError
+      return not_found
     end
+
+    render json: oembed
   end
 end
index 2c5674869365c828d7e5844098508259d598de75..e6f5d7a6327969a990f12bab33ff0e26dc79530d 100644 (file)
@@ -46,6 +46,8 @@ class Formatter
 
   def reformat(html)
     sanitize(html, Sanitize::Config::MASTODON_STRICT)
+  rescue ArgumentError
+    ''
   end
 
   def plaintext(status)