mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
SECURITY: Prevent Onebox cache overflow by limiting downloads and URL lengths
This commit is contained in:
committed by
Krzysztof Kotlarek
parent
3c5fb871c0
commit
95a82d608d
@@ -16,7 +16,7 @@ module Onebox
|
||||
DEFAULTS = {
|
||||
connect_timeout: 5,
|
||||
timeout: 10,
|
||||
max_download_kb: (10 * 1024), # 10MB
|
||||
max_download_kb: 2048, # 2MB
|
||||
load_paths: [File.join(Rails.root, "lib/onebox/templates")],
|
||||
allowed_ports: [80, 443],
|
||||
allowed_schemes: %w[http https],
|
||||
|
||||
@@ -98,7 +98,13 @@ module Onebox
|
||||
).first
|
||||
favicon = favicon.nil? ? nil : (favicon["href"].nil? ? nil : favicon["href"].strip)
|
||||
|
||||
Onebox::Helpers.get_absolute_image_url(favicon, url)
|
||||
return nil if favicon.blank?
|
||||
|
||||
absolute_url = Onebox::Helpers.get_absolute_image_url(favicon, url)
|
||||
|
||||
return nil if absolute_url.length > UrlHelper::MAX_URL_LENGTH
|
||||
|
||||
absolute_url
|
||||
end
|
||||
|
||||
def get_description
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UrlHelper
|
||||
MAX_URL_LENGTH = 100_000
|
||||
MAX_URL_LENGTH = 2_000
|
||||
|
||||
# At the moment this handles invalid URLs that browser address bar accepts
|
||||
# where second # is not encoded
|
||||
|
||||
Reference in New Issue
Block a user