Skip to content

Commit

Permalink
Merge pull request #13198 from bayandin/fix-headers-check
Browse files Browse the repository at this point in the history
utils/curl: fix headers check for protected urls
  • Loading branch information
MikeMcQuaid committed Apr 26, 2022
2 parents 5280a38 + c726385 commit 3c73ac4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,18 @@ def curl_output(*args, **options)
# Check if a URL is protected by CloudFlare (e.g. badlion.net and jaxx.io).
def url_protected_by_cloudflare?(details)
return false if details[:headers].blank?
return unless [403, 503].include?(details[:status].to_i)

[403, 503].include?(details[:status].to_i) &&
details[:headers].match?(/^Set-Cookie: (__cfduid|__cf_bm)=/i) &&
details[:headers].match?(/^Server: cloudflare/i)
details[:headers].fetch("set-cookie", nil)&.match?(/^(__cfduid|__cf_bm)=/i) &&
details[:headers].fetch("server", nil)&.match?(/^cloudflare/i)
end

# Check if a URL is protected by Incapsula (e.g. corsair.com).
def url_protected_by_incapsula?(details)
return false if details[:headers].blank?
return false if details[:status].to_i != 403

details[:status].to_i == 403 &&
details[:headers].match?(/^Set-Cookie: visid_incap_/i) &&
details[:headers].match?(/^Set-Cookie: incap_ses_/i)
details[:headers].fetch("set-cookie", nil)&.match?(/^(visid_incap|incap_ses)_/i)
end

def curl_check_http_content(url, url_type, specs: {}, user_agents: [:default],
Expand Down

0 comments on commit 3c73ac4

Please sign in to comment.