Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(general): tolerate ${HTTPS_PROXY} without a scheme #6235

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions checkov/common/bridgecrew/platform_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,21 @@ def setup_http_manager(self, ca_certificate: str | None = None, no_cert_verify:

if self.http:
return
# The `https_proxy` environment variable might be scheme-less. urllib3.ProxyManager expects a scheme, so set
# to a default of http:// if missing.
parsed_proxy_url = urllib3.util.parse_url(os.environ['https_proxy'])
if not parsed_proxy_url.scheme:
parsed_proxy_url = parsed_proxy_url._replace(scheme='http')
if ca_certificate:
os.environ['REQUESTS_CA_BUNDLE'] = ca_certificate
cert_reqs = 'CERT_NONE' if no_cert_verify else 'REQUIRED'
logging.debug(f'Using CA cert {ca_certificate} and cert_reqs {cert_reqs}')
try:
parsed_url = urllib3.util.parse_url(os.environ['https_proxy'])
self.http = urllib3.ProxyManager(
os.environ['https_proxy'],
parsed_proxy_url.url,
cert_reqs=cert_reqs,
ca_certs=ca_certificate,
proxy_headers=urllib3.make_headers(proxy_basic_auth=parsed_url.auth), # type:ignore[no-untyped-call]
proxy_headers=urllib3.make_headers(proxy_basic_auth=parsed_proxy_url.auth), # type:ignore[no-untyped-call]
timeout=self.http_timeout,
retries=self.http_retry,
)
Expand All @@ -348,11 +352,10 @@ def setup_http_manager(self, ca_certificate: str | None = None, no_cert_verify:
cert_reqs = 'CERT_NONE' if no_cert_verify else None
logging.debug(f'Using cert_reqs {cert_reqs}')
try:
parsed_url = urllib3.util.parse_url(os.environ['https_proxy'])
self.http = urllib3.ProxyManager(
os.environ['https_proxy'],
parsed_proxy_url.url,
cert_reqs=cert_reqs,
proxy_headers=urllib3.make_headers(proxy_basic_auth=parsed_url.auth), # type:ignore[no-untyped-call]
proxy_headers=urllib3.make_headers(proxy_basic_auth=parsed_proxy_url.auth), # type:ignore[no-untyped-call]
timeout=self.http_timeout,
retries=self.http_retry,
)
Expand Down
10 changes: 10 additions & 0 deletions tests/common/test_platform_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ def test_add_static_policy_filters(self):
self.assertListEqual(BcPlatformIntegration.add_static_policy_filters([('policy.label', 'xyz'), ('policy.enabled', 'true')]), [('policy.label', 'xyz'), ('policy.enabled', 'true'), ('policy.subtype', 'build')])
self.assertListEqual(BcPlatformIntegration.add_static_policy_filters([('policy.enabled', 'true'), ('policy.label', 'xyz'), ('policy.subtype', 'build')]), [('policy.enabled', 'true'), ('policy.label', 'xyz'), ('policy.subtype', 'build')])

def test_proxy_without_scheme(self):
current_proxy = os.environ['https_proxy']
try:
os.environ['https_proxy'] = "127.0.0.1"
instance = BcPlatformIntegration()
instance.api_url = 'https://www.bridgecrew.cloud/v1'
instance.setup_http_manager()
finally:
os.environ['https_proxy'] = current_proxy

def test_setup_on_prem(self):
instance = BcPlatformIntegration()

Expand Down
Loading