about summary refs log tree commit diff
path: root/app/controllers/api/web
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-02-07 15:24:22 +0100
committermultiple creatures <dev@multiple-creature.party>2020-02-20 23:08:01 -0600
commit14a5d249ad2ad78f00699bbab9062b3ea88ec93c (patch)
treebb30ad6ae119361c469539485d95fd83382e1fff /app/controllers/api/web
parent03953a045149853d3bada69bbb8e91c4c5e53d62 (diff)
port tootsuite/#13042 to monsterfork: Fix malformed HTML causing uncaught error
Fix OEmbed preview API leaking existence of private statuses (see #12930)
Diffstat (limited to 'app/controllers/api/web')
-rw-r--r--app/controllers/api/web/embeds_controller.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/app/controllers/api/web/embeds_controller.rb b/app/controllers/api/web/embeds_controller.rb
index 3e7919184..c05af4456 100644
--- a/app/controllers/api/web/embeds_controller.rb
+++ b/app/controllers/api/web/embeds_controller.rb
@@ -7,15 +7,21 @@ class Api::Web::EmbedsController < Api::Web::BaseController
 
   def create
     status = StatusFinder.new(params[:url]).status
+
+    return not_found unless status.distributable?
+
     render json: status, serializer: OEmbedSerializer, width: 400, monsterfork_api: monsterfork_api
   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