uri processing reject paths not starting with slash
authorAndy Green <andy@warmcat.com>
Fri, 1 Apr 2016 23:36:17 +0000 (07:36 +0800)
committerAndy Green <andy@warmcat.com>
Mon, 4 Apr 2016 22:58:04 +0000 (06:58 +0800)
https://github.com/warmcat/libwebsockets/issues/481

Return 403 Forbidden if we don't end up with a uri path starting with /

Signed-off-by: Andy Green <andy@warmcat.com>
lib/server.c
test-server/attack.sh

index 4b7078a..51dd427 100644 (file)
@@ -291,6 +291,14 @@ lws_http_action(struct lws *wsi)
                        break;
                }
 
+       /* we insist on absolute paths */
+
+       if (uri_ptr[0] != '/') {
+               lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL);
+
+               goto bail_nuke_ah;
+       }
+
        /* HTTP header had a content length? */
 
        wsi->u.http.content_length = 0;
index bd16000..f1a4e1b 100755 (executable)
@@ -218,11 +218,18 @@ check
 echo
 echo "---- nonexistant file"
 rm -f /tmp/lwscap
-echo -e "GET nope HTTP/1.1\x0d\x0a\x0d\x0a" | nc $SERVER $PORT | sed '1,/^\r$/d'> /tmp/lwscap
+echo -e "GET /nope HTTP/1.1\x0d\x0a\x0d\x0a" | nc $SERVER $PORT | sed '1,/^\r$/d'> /tmp/lwscap
 check media
 check
 
 echo
+echo "---- relative uri path"
+rm -f /tmp/lwscap
+echo -e "GET nope HTTP/1.1\x0d\x0a\x0d\x0a" | nc $SERVER $PORT | sed '1,/^\r$/d'> /tmp/lwscap
+check forbidden
+check
+
+echo
 echo "---- directory attack 1 (/../../../../etc/passwd should be /etc/passswd)"
 rm -f /tmp/lwscap
 echo -e "GET /../../../../etc/passwd HTTP/1.1\x0d\x0a\x0d\x0a" | nc $SERVER $PORT | sed '1,/^\r$/d'> /tmp/lwscap