Skip to content

[Security] Default empty API_KEY + Redis key injection via query parameter #228

@xtcon

Description

@xtcon

[Security] API默认无认证 + Redis key注入

项目

Python3WebSpider/ProxyPool (6.2k ⭐)

严重度

🟡 中危

描述

1. 默认无API认证

proxypool/setting.pyAPI_KEY 默认空字符串:

API_KEY = env.str('API_KEY', '')

proxypool/processors/server.py 中认证装饰器在 API_KEY="" 时直接放行:

if API_KEY == "":
    return func(*args, **kwargs)

部署到公网时,任何人都可以访问 /random/all/count 端点。

2. Redis key注入

/random?key=xxx 中的 key 参数直接作为Redis key名传入:

key = request.args.get('key')
conn = get_conn()
if key:
    return conn.random(key).string()

虽然限于 key 名选择,但攻击者可探测其他 Redis zset 中存储的数据。

代码位置

setting.py:

API_KEY = env.str('API_KEY', '')

server.py:

@app.route('/random')
@auth_required
def get_proxy():
    key = request.args.get('key')
    ...
    return conn.random(key).string()

建议修复

  1. 默认生成随机 API_KEY,而非空字符串
  2. key 参数做校验,只允许预期格式(字母数字)
  3. 在README中强调 API_KEY 必须设置

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions