浏览代码

Fix malformed HTML causing uncaught error (#13042)

Fix OEmbed preview API leaking existence of private statuses (see #12930)
master^2
Eugen Rochko 4 年前
committed by GitHub
父节点
当前提交
a64973aecf
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 13 次插入5 次删除
  1. +11
    -5
      app/controllers/api/web/embeds_controller.rb
  2. +2
    -0
      app/lib/formatter.rb

+ 11
- 5
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 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

+ 2
- 0
app/lib/formatter.rb 查看文件

@@ -46,6 +46,8 @@ class Formatter

def reformat(html)
sanitize(html, Sanitize::Config::MASTODON_STRICT)
rescue ArgumentError
''
end

def plaintext(status)


正在加载...
取消
保存