1
0
Fork 0
forked from gitea/nas

Add size limit for link preview URLs (#30854)

This commit is contained in:
KMY 2024-07-05 07:03:49 +09:00
parent e53f6a50d2
commit 0370a72dbd
3 changed files with 30 additions and 11 deletions

View file

@ -16,6 +16,9 @@ class FetchLinkCardService < BaseService
)
}iox
# URL size limit to safely store in PosgreSQL's unique indexes
BYTESIZE_LIMIT = 2692
def call(status)
@status = status
@original_url = parse_urls
@ -106,7 +109,7 @@ class FetchLinkCardService < BaseService
def bad_url?(uri)
# Avoid local instance URLs and invalid URLs
uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme) ||
uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme) || uri.to_s.bytesize > BYTESIZE_LIMIT ||
referenced_urls.include?(uri.to_s) || Setting.stop_link_preview_domains&.include?(uri.host)
end