You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When dial with CDN edge IP with Custom SNI, such as url: wss://${cdn_edgeIP}:443/path, CDN will report 403 forbidden error
That is because CDN will verify both TLS SNI name and Host in request header , but your below code will take IP as Host in request header when dial with CDN edge IP
build_host(wsuri.host, wsuri.port, wsuri.secure)
Hence we need to correct this bug.
The test code as below:
import ssl
from websockets.client import connect
import asyncio
async def WssHandshake():
server_host = '104.16.177.217'
server_port = 443
sni_hostname = 'testwebsocket.icanfly668.top'
ssl_context = ssl.create_default_context()
headers = {
'Host': sni_hostname,
"User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
}
uri = f"wss://{server_host}:{server_port}/ws"
async with connect(uri=uri, ssl=ssl_context,server_hostname=sni_hostname,
extra_headers=headers, subprotocols=["chat"]) as websocket:
await websocket.send("Hello, WebSocket with SNI!")
response = await websocket.recv()
print(response)
asyncio.run(WssHandshake())
Yes, it does work if take host parameter, but why?
I find below code seems relating to it.
# If host and port are given, override values from the URI.
host = kwargs.pop("host", host)
port = kwargs.pop("port", port)
create_connection = functools.partial(
loop.create_connection, factory, host, port, **kwargs
)
But I cannot find any clue why the given host can override values from the URI.
Could you explain it in details? Thx!
When dial with CDN edge IP with Custom SNI, such as url: wss://${cdn_edgeIP}:443/path, CDN will report 403 forbidden error
That is because CDN will verify both TLS SNI name and Host in request header , but your below code will take IP as Host in request header when dial with CDN edge IP
Hence we need to correct this bug.
The test code as below:
I hv submitted the PR to fix this problem.
#1553
The text was updated successfully, but these errors were encountered: