aiohttp:ValueError:在 HTTP 状态消息或标头中检测到换行符或回车符。这是一个潜在的安全问题

问题描述 投票:0回答:1

我正在使用

gql
针对 GraphQL API 运行查询。我收到此错误:

  File "<path to poetry venv>/lib/python3.10/site-packages/aiohttp/http_writer.py", line 129, in write_headers
    buf = _serialize_headers(status_line, headers)
  File "aiohttp/_http_writer.pyx", line 132, in aiohttp._http_writer._serialize_headers
  File "aiohttp/_http_writer.pyx", line 116, in aiohttp._http_writer._safe_header
ValueError: Newline or carriage return character detected in HTTP status message or header. This is a potential security issue.

通过查看这个SO答案这个GitHub问题,我大致了解了一般问题。

但是,我自己甚至没有设置任何标题,我只是运行类似的东西

from gql import Client as gql_client, gql

expr_ = '''mutation myMutation($var: Type) {
             nameOfMyGraphQLMutation(var: $var) {
              ... (fields to return) ...
             }
           }'''
expr = gql(expr_)
client = gql_client(...)
client.execute(expr, ...)

从外观上看,

gql
似乎在内部使用了
aiohttp

我尝试破解我的 venv 中的

aiohttp
python 代码以显示有问题的标头,以了解根本原因可能是什么,但是 AFAICT,那里有编译的代码(例如
_http_writer.cpython-310-darwin.so
之类的文件),所以本地更改不会被采纳。

此外,从 Google 来看,我似乎是唯一遇到此问题的开发人员(这通常表明我自己就是根本原因......)

有人知道如何解决这个问题吗?

python graphql aiohttp
1个回答
0
投票

还有另一种情况,只要你正确提出问题,答案就会变得显而易见。

aiohttp
python 代码确实看起来并不容易破解,但是
gql
代码是:
print
gql
之前的标头将它们传递给
aiohttp
- 事实上,API 密钥标头有一个尾随换行符(因为我从文件加载它并且不
strip()
换行)。

© www.soinside.com 2019 - 2024. All rights reserved.