SECURITY: Prevent Onebox cache overflow by limiting downloads and URL lengths

This commit is contained in:
Ted Johansson
2023-10-18 10:29:36 +08:00
committed by Krzysztof Kotlarek
parent 3c5fb871c0
commit 95a82d608d
5 changed files with 42 additions and 8 deletions

View File

@@ -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],

View File

@@ -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

View File

@@ -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