Skip to content

webTool.get_system_proxy 用 lstrip 剥离代理协议前缀,主机名以 h/t/p/s 开头时被啃坏 #226

Open

Description

@SuellenQwQ

描述 bug

OlivOS/core/web/webTool.py 的 get_system_proxy() 用 lstrip 剥离代理地址的协议前缀,但 lstrip 的参数是字符集合,不是前缀:

res = urllib.request.getproxies()
for res_this in res:
    res[res_this] = res[res_this].lstrip('%s://' % res_this)

对 key 为 http 的条目,lstrip('http://') 会从左侧剥离 h、t、p、:、/ 中的任意字符。于是主机名以这些字母开头的代理会被啃坏。

复现(按原样逻辑,设置环境变量后调用):

环境变量:
  http_proxy  = http://proxy.example.com:8080
  https_proxy = https://tunnel.example.com:8443

getproxies() 原始值:
  http:  http://proxy.example.com:8080
  https: https://tunnel.example.com:8443

lstrip 后:
  http:  roxy.example.com:8080     <- 'proxy' 的 p 在字符集里,被剥掉
  https: unnel.example.com:8443    <- 'tunnel' 的 t 被剥掉

get_system_proxy() 的返回值在 10 处调用点被直接作为 proxies= 传给 requests(updateAPI.py 的更新检查、以及 discord / red / OPQBot / hackChat / dingtalk / onebotV12 等适配器),坏掉的主机名会导致这些出站请求连接失败。

顺带说明:127.0.0.1 这类 IP 形式的代理不受影响(1 不在剥离集合中),这也是多数用户没察觉的原因;受影响的是使用域名形式代理、且域名以 h/t/p/s 开头的部署(proxy.、tunnel.、server. 这类前缀很常见)。

另外 get_system_proxy_tuple() 对同一返回值再次 lstrip,问题同样存在。

修复建议

按前缀剥离(项目 requires-python >= 3.7,str.removeprefix 需要 3.9,建议用切片判断):

prefix = res_this + '://'
if res[res_this].startswith(prefix):
    res[res_this] = res[res_this][len(prefix):]

或直接用 urllib.parse.urlparse 取 netloc。

环境

  • OS: Windows 11
  • Version: main 分支最新代码(commit 至 2026-10-15)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions