Skip to content
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

Invalid HTTP request parsing in some network environments #1

Open
1 task
adelyte-chris opened this issue May 1, 2017 · 3 comments
Open
1 task

Invalid HTTP request parsing in some network environments #1

adelyte-chris opened this issue May 1, 2017 · 3 comments
Assignees
Labels

Comments

@adelyte-chris
Copy link
Member

This issue is reproducible across at least two processor types (DIN-AP3 and DMPS-300-C) but only on one enterprise-class network.

Issue

Error

PM|Fatal|System.FormatException: An invalid IP address was specified. ---> System.Net.Sockets.SocketException: An invalid argument was supplied
  at System.Net.IPAddress.Parse(String ipString)
  at Crestron.SimplSharp.IPAddress.Parse(String ipString)
  at Crestron.SimplSharp.CrestronSockets.CrestronServerSocket.get_LocalEndPoint()
  at WebSocketSharp.Net.HttpConnection.get_LocalEndPoint()
  at WebSocketSharp.Net.HttpListenerRequest.get_LocalEndPoint()
  at WebSocketSharp.Net.HttpListenerRequest.get_UserHostAddress()
  at Waveguide.WebServer.<>cDisplayClass1.<.ctor>b0(Object sender, HttpRequestEventArgs args)
  at WebSocketSharp.Server.HttpServer.processRequest(HttpListenerContext context)
  at WebSocketSharp.Server.HttpServer.<>cDisplayClass1.<receiveRequest>b0(Object state)
  at SSMono.Threading.ThreadPool.doIt(Object state)
  at Crestron.SimplSharp.UserThreadStartDelegateWrapper.a(Object A_0)
  at System.Threading.Timer.ring()

Analysis

The property WebSocketSharp.Net.HttpListenerRequest.UserHostAddress is only supposed to be accessed if the incoming HTTP connection is an HTTP 1.0 connection and a host header is not provided. Nevertheless, it is being accessed in response to an HTTP 1.1 request fro several different user agents. For example, the error occurs with curl:

curl -sv -o /dev/null http://$PROCESSOR_IP_ADDRESS:80/

Steps

@adelyte-chris adelyte-chris self-assigned this May 1, 2017
@adelyte-chris
Copy link
Member Author

I missed the braces in the logging line. The output is HttpConnection processInput() data: $0, which is not quite what I intended.

@taylorzane
Copy link
Member

taylorzane commented May 1, 2017

Fixed the formatting issue in 13d0931.

@adelyte-chris
Copy link
Member Author

With the HEAD version of this library, the bytes received for process input were:

bytes_received = "47-45-54-20-2F-20-48-54-54-50-2F-31-2E-31-0D-0A-48-6F-73-74-3A-20-#{omitted}-3A-35-30-30-38-30-0D-0A-43-6F-6E-6E-65-63-74-69-6F-6E-3A-20-6B-65-65-70-2D-61-6C-69-76-65-0D-0A-55-70-67-72-61-64-65-2D-49-6E-73-65-63-75-72-65-2D-52-65-71-75-65-73-74-73-3A-20-31-0D-0A-55-73-65-72-2D-41-67-65-6E-74-3A-20-4D-6F-7A-69-6C-6C-61-2F-35-2E-30-20-28-57-69-6E-64-6F-77-73-20-4E-54-20-31-30-2E-30-3B-20-57-69-6E-36-34-3B-20-78-36-34-29-20-41-70-70-6C-65-57-65-62-4B-69-74-2F-35-33-37-2E-33-36-20-28-4B-48-54-4D-4C-2C-20-6C-69-6B-65-20-47-65-63-6B-6F-29-20-43-68-72-6F-6D-65-2F-35-38-2E-30-2E-33-30-32-39-2E-38-31-20-53-61-66-61-72-69-2F-35-33-37-2E-33-36-0D-0A-41-63-63-65-70-74-3A-20-74-65-78-74-2F-68-74-6D-6C-2C-61-70-70-6C-69-63-61-74-69-6F-6E-2F-78-68-74-6D-6C-2B-78-6D-6C-2C-61-70-70-6C-69-63-61-74-69-6F-6E-2F-78-6D-6C-3B-71-3D-30-2E-39-2C-69-6D-61-67-65-2F-77-65-62-70-2C-2A-2F-2A-3B-71-3D-30-2E-38-0D-0A-41-63-63-65-70-74-2D-45-6E-63-6F-64-69-6E-67-3A-20-67-7A-69-70-2C-20-64-65-66-6C-61-74-65-2C-20-73-64-63-68-0D-0A-41-63-63-65-70-74-2D-4C-61-6E-67-75-61-67-65-3A-20-65-6E-2D-55-53-2C-65-6E-3B-71-3D-30-2E-38-0D-0A-0D-0A"
text = bytes_received.split('-').reduce("") { |text, hex| text << hex.to_i(16).chr } # =>
"GET / HTTP/1.1\r\nHost: #{omitted}:50080\r\nConnection: keep-alive\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-US,en;q=0.8\r\n\r\n"
GET / HTTP/1.1
Host: #{omitted}:50080
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-US,en;q=0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants