T09 · Insecure Skill Coding Practices
- Location
scripts/article_link.py:57- Finding
TLS Certificate and Hostname Verification Are Disabled
- Content
View full analysis
Vulnerability Details
File Location:
scripts/article_link.py:57-69
Vulnerability Type: Improper TLS certificate validation
Risk Level: HighVulnerable Code
python ctxs: List[ssl.SSLContext] = [] try: c1 = ssl.create_default_context() c1.check_hostname = False c1.verify_mode = ssl.CERT_NONE ctxs.append(c1) except Exception: pass try: c2 = ssl._create_unverified_context() # noqa: SLF001 ctxs.append(c2) except Exception: passThe unverified contexts are subsequently used for every HTTPS connection:
python opener = urllib_request.build_opener( urllib_request.ProxyHandler({}), urllib_request.HTTPSHandler(context=ctx), )Authenticated requests transmit the Import Token through the resulting connection:
python if effective_token: headers["X-Import-Token"] = effective_tokenTechnical Analysis
The client explicitly disables both certificate-chain validation and hostname verification. The first context changes
verify_modetossl.CERT_NONE, while the second is created through Python's private_create_unverified_context()function.There is no secure context attempted before these contexts. Therefore, this is not a narrowly scoped compatibility fallback: all HTTPS requests accept certificates issued by unknown authorities, self-signed certificates, expired certificates, and certificates issued for unrelated hostnames.
Although the traffic remains encrypted, the client does not authenticate the remote server. An attacker able to intercept or redirect network traffic can terminate TLS using an arbitrary certificate and impersonate the configured API.
Attack Path
- A user configures a valid Import Token and invokes an authenticated command such as
submit,quota,status,jobs, orarticle. - An attacker gains a network interception position, controls a gateway or DNS response, or otherwise redirects traffic intended for the API.
- The attacker presents a ...[truncated 958 chars]
- A user configures a valid Import Token and invokes an authenticated command such as
- Remediation
View remediation
Remediation Suggestions
Use a standard verified TLS context and remove all unverified fallback contexts:
python _SSL_CONTEXT = ssl.create_default_context()Create the HTTPS handler only with that verified context:
python opener = urllib_request.build_opener( urllib_request.ProxyHandler({}), urllib_request.HTTPSHandler(context=_SSL_CONTEXT), )Do not disable certificate validation in response to network, proxy, EOF, or compatibility errors. Certificate failures should terminate the request and produce a clear error.
Additional hardening should include:
- Require a supported Python and OpenSSL version rather than weakening TLS.
- Use the operating system's trusted certificate store or an explicitly configured CA bundle.
- Distinguish transient connection failures from certificate-validation failures.
- Never retry a certificate failure using a less secure SSL context.
- Consider certificate or public-key pinning if the API's operational model can safely support rotation.
- Add automated tests confirming that self-signed, expired, and hostname-mismatched certificates are rejected.
