SDK does not respect SSL_CERT_FILE or REQUESTS_CA_BUNDLE environment variables

未关闭
#998 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
api, security

调研方向

从 RESTClient 的构造以及 get_aggs 使用的 urllib3 HTTP 客户端路径开始;检查其 CA bundle 是如何选择的。设置 SSL_CERT_FILE 或 REQUESTS_CA_BUNDLE 后复现该请求,然后验证 get_aggs 能够通过自定义证书链成功执行,同时不禁用验证。

由索引模型根据 Issue 内容生成。

描述

Problem

The Polygon Python SDK fails with SSL certificate verification errors when used behind corporate firewalls that perform SSL/TLS inspection. The SDK does not respect standard SSL certificate environment variables (SSL_CERT_FILE, REQUESTS_CA_BUNDLE) that specify custom CA bundles.

Steps to Reproduce

import os
from polygon import RESTClient

# Set custom CA bundle (common in enterprise environments)
os.environ["SSL_CERT_FILE"] = "/path/to/corporate-ca-bundle.pem"

# This fails with SSL error
client = RESTClient(os.getenv("POLYGON_API_KEY"))
aggs = client.get_aggs(ticker="AAPL", multiplier=1, timespan="day",
                       from_="2026-02-01", to="2026-02-10")
list(aggs)  # SSLError: certificate verify failed

Expected Behaviour

SDK should respect SSL environment variables like other Python HTTP libraries (requests, httpx, urllib3).

Actual Behaviour

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
self-signed certificate in certificate chain

SDK ignores environment variables and uses bundled certifi CA bundle only.

Evidence

Raw Python SSL (works):

import ssl, socket
context = ssl.create_default_context()
with socket.create_connection(("api.polygon.io", 443)) as sock:
    with context.wrap_socket(sock, server_hostname="api.polygon.io") as s:
        print(s.version())  # ✅ TLSv1.3 - Success!

Polygon SDK (fails):
Uses bundled certs, ignores SSL_CERT_FILE → certificate verification fails.

Root Cause

The SDK uses urllib3 but doesn't configure it to check standard SSL environment variables. While urllib3 supports custom CA bundles, the Polygon SDK never provides them.

Comparison: Alpaca SDK (Works Correctly)

# Alpaca SDK respects SSL_CERT_FILE and works behind corporate firewalls
from alpaca.data.historical import StockHistoricalDataClient
client = StockHistoricalDataClient(api_key, secret_key)
bars = client.get_stock_bars(...)  # ✅ Works!

Suggested Fix

Check environment variables when creating HTTP client:

import os
import certifi

def get_ca_bundle():
    """Get CA bundle from environment or default."""
    return (os.getenv("SSL_CERT_FILE") or
            os.getenv("REQUESTS_CA_BUNDLE") or
            certifi.where())

# Use in RESTClient
http = urllib3.PoolManager(cert_reqs="CERT_REQUIRED",
                           ca_certs=get_ca_bundle())

Impact

Affects: Enterprise users behind corporate firewalls with SSL inspection (finance, healthcare, government sectors)

Current workarounds: All unacceptable for production:

  • ❌ Disable SSL verification (insecure)
  • ❌ Switch to different provider
  • ❌ Maintain local SDK patches

Environment

  • Python: 3.10+
  • OS: macOS/Linux
  • Network: Corporate firewall with SSL inspection (Zscaler, etc.)
  • polygon-api-client: Latest

References

Happy to submit a PR if maintainers are open to this fix.
This issue generated with AI/Claude 4.6

主要语言
Python
星标
1.5k
派生
362
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

massive-com/client-python 的其他 Issue

查看 massive-com/client-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。