-
Notifications
You must be signed in to change notification settings - Fork 41
Feat on_websocket_receive #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
有什麽特別的用處嗎;可信是什麽意思;ws 需要在每個 packet 中每次都發驗證信息嗎? |
之前咖啡佬跟我讨论了,这个作用在于当用 aiocqhttp 作为一个公开 OneBot 服务端时,可能会有恶意用户发来过长、过分复杂(导致 |
|
please rebase commits into one; 'fxxking' is annoying |
e3b49b5 to
44d5e5b
Compare
44d5e5b to
3768b26
Compare
| self._add_wsr_api_client() | ||
| try: | ||
| while True: | ||
| payload = await websocket.receive() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
突然一下有点迷惑了,这里返回的是 str 还是 bytes,下面用的是 json.loads,但 _on_wsr_receive_func 的参数却是 bytes。
另外就是,_on_wsr_receive_func 如何表达“payload 不合法”呢?是不是 563 行调用的时候接个异常、或检查是否为 None 会比较好;或者干脆让 _on_wsr_receive_func 不能修改 payload,只需要返回 bool 就行了(为什么会需要修改 payload 呢)。
on_websocket_receive 注释里应该写 _on_wsr_receive_func 中判断到不合法 payload 报错的例子,毕竟这才是它真正的用处,而不是直接原样返回的例子。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对了,docs/changelog.md 也需要改下,小标题先用 master
现有的hook函数无法在ws收到消息时,对不可信的OneBot进行验证。
添加on_websocket_receive接口,在每次调用websocket.receice()后、其他处理前调用钩子函数,可用于实现安全认证。