MCPcopy Create free account
hub / github.com/authlib/authlib / is_secure_transport

Function is_secure_transport

authlib/common/security.py:15–48  ·  view source on GitHub ↗

Check if the uri is over ssl.

(uri)

Source from the content-addressed store, hash-verified

13
14
15def is_secure_transport(uri):
16 """Check if the uri is over ssl."""
17 if os.getenv("AUTHLIB_INSECURE_TRANSPORT"):
18 return True
19
20 try:
21 parts = urlsplit(uri)
22 except ValueError:
23 return False
24
25 if not parts.hostname:
26 return False
27
28 if parts.scheme == "https":
29 return True
30
31 if parts.scheme != "http":
32 return False
33
34 # rfc8252 §7.3: native apps may use http for loopback redirection URIs.
35 if parts.hostname == "localhost":
36 return True
37
38 try:
39 address = ipaddress.ip_address(parts.hostname)
40 except ValueError:
41 return False
42
43 # IPv6Address.is_loopback only accounts for the mapped IPv4 address since
44 # CPython 3.10.16, 3.11.11 and 3.12.4.
45 if isinstance(address, ipaddress.IPv6Address) and address.ipv4_mapped:
46 address = address.ipv4_mapped
47
48 return address.is_loopback

Callers 15

checkMethod · 0.90
validate_issuerMethod · 0.90
validate_jwks_uriMethod · 0.90
checkMethod · 0.90
test_secure_transportFunction · 0.90

Calls

no outgoing calls