Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Code does not handle whitespace after cookie value before semicolon #22

Open
michaeltalyansky opened this issue Jul 5, 2017 · 1 comment

Comments

@michaeltalyansky
Copy link

michaeltalyansky commented Jul 5, 2017

This curl:

curl -b "name3=booboo; name2=hello_Hahabooboo ; username=foofoo" -o zoo1 -v "http://test.com/1.jpg"

breaks the code, the next cookie name starts with a semicolon.

Here is the proposed fix:

--- /usr/local/openresty/lualib/resty/cookie.lua.orig 2017-07-05 17:39:05.660555808 +0000
+++ /usr/local/openresty/lualib/resty/cookie.lua       2017-07-05 18:08:51.604555808 +0000
@@ -41,6 +41,7 @@
     local EXPECT_KEY    = 1
     local EXPECT_VALUE  = 2
     local EXPECT_SP     = 3
+    local EXPECT_SEMI   = 4
 
     local n = 0
     local len = #text_cookie
@@ -74,8 +75,12 @@
                 cookie_table[key] = value
 
                 key, value = nil, nil
-                state = EXPECT_SP
                 i = j + 1
+                              if byte(text_cookie, j) == SEMICOLON then
+                    state = EXPECT_SP
+                              else
+                                  state = EXPECT_SEMI
+                              end
             end
         elseif state == EXPECT_SP then
             if byte(text_cookie, j) ~= SPACE
@@ -85,6 +90,12 @@
                 i = j
                 j = j - 1
             end
+              elseif state == EXPECT_SEMI then
+                  if byte(text_cookie, j) ~= SEMICOLON then
+                  else
+                              state = EXPECT_SP
+                              i = j + 1
+                  end
         end
         j = j + 1
     end
@lua-study
Copy link

elseif state == EXPECT_VALUE then
if byte(text_cookie, j) == SEMICOLON
-- or byte(text_cookie, j) == SPACE
-- or byte(text_cookie, j) == HTAB
then
value = sub(text_cookie, i, j - 1)
cookie_table[key] = value

            key, value = nil, nil
            state = EXPECT_SP
            i = j + 1
        end

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

No branches or pull requests

2 participants