walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.03k stars 2.25k forks source link

Incorrect parsing of connection headers #955

Closed VladimirMerk closed 9 months ago

VladimirMerk commented 9 months ago

If I send a custom header whose value contains colons, then on the server I receive an incomplete value. The value on the server is only up to the first colon.

Example: Sending Custom-Header: foo:bar:baz

Receive on server Custom-Header: foo

joanhey commented 9 months ago

After checking the code looks Ok. I'll add a test for it, and check it again.

Which Workerman version are you using ?

VladimirMerk commented 9 months ago

Version 4.1.13 I think there is a problem with the parseHttpHeader function in Websocket.php Explode splits the header line at colons with a limit of 2 elements. It turns out that if there is a colon in the header value, then everything after it is cut off. It seems that you need to split the header into a key-value only at the first colon, and save the value as is.

joanhey commented 9 months ago

Checked also Websocket.php, and it seems OK.

Code: https://github.com/walkor/workerman/blob/4.1/Protocols/Websocket.php#L534C13-L534C67

Example with the code and your header with colons. https://3v4l.org/WW2Xc

The code is correct and work OK.

VladimirMerk commented 9 months ago

Yes, indeed, everything is fine.

I looked at my code again and found an error on my part. Sorry for that.

Thank you for your time. Successful growth and development of your excellent project!