edicl / drakma

HTTP client written in Common Lisp
http://edicl.github.io/drakma/
249 stars 58 forks source link

Cookie parsing fails for admittelly bad cookies #95

Open ckonstanski opened 6 years ago

ckonstanski commented 6 years ago

I am writing against the Infoblox REST API. The moment I try to use a cookie-jar I get the following error:

end of file on #<FLEXI-STREAMS::LIST-INPUT-STREAM {1004BF43C3}> [Condition of type END-OF-FILE] Backtrace: 0: (READ-BYTE #<FLEXI-STREAMS::LIST-INPUT-STREAM {1004BF43C3}> T NIL) 1: (CHUNGA:READ-CHAR* #<FLEXI-STREAMS::LIST-INPUT-STREAM {1004BF43C3}> T NIL) 2: (CHUNGA::READ-QUOTED-STRING #<FLEXI-STREAMS::LIST-INPUT-STREAM {1004BF43C3}>) 3: (CHUNGA::READ-COOKIE-VALUE #<FLEXI-STREAMS::LIST-INPUT-STREAM {1004BF43C3}> :SEPARATORS ";") 4: (CHUNGA:READ-NAME-VALUE-PAIR #<FLEXI-STREAMS::LIST-INPUT-STREAM {1004BF43C3}> :VALUE-REQUIRED-P T :COOKIE-SYNTAX T) 5: (DRAKMA::PARSE-SET-COOKIE "ibapauth=\"client=API,group=VCP-Meter,ctime=1538755942,timeout=7200,mtime=1538755942,ip=10.134.10.30,auth=LOCAL,user=openbook,Rw+KK2u56eG1OP13xpSkhnQgaQteIjrVJIs\"; httponly.. 6: (DRAKMA::GET-COOKIES ((:DATE . "Fri, 05 Oct 2018 16:12:22 GMT") (:CACHE-CONTROL . "no-cache, no-store") (:PRAGMA . "no-cache") (:CONTENT-TYPE . "application/json") (:SET-COOKIE . "ibapauth=\"client=AP.. 7: ((LABELS DRAKMA::FINISH-REQUEST :IN DRAKMA:HTTP-REQUEST) NIL NIL) 8: (DRAKMA:HTTP-REQUEST #<PURI:URI https://cdsinfdnsgm.nnodns.com/wapi/v2.6/record:cname?_return_as_object=1> :COOKIE-JAR #<DRAKMA:COOKIE-JAR (with 0 cookies) {1004BE13F3}> :PROTOCOL :HTTP/1.1 :METHOD :G.. 9: (DNS-ADMIN::DRAKMA-REQUEST "https://cdsinfdnsgm.nnodns.com/wapi/v2.6/record:cname" #<DRAKMA:COOKIE-JAR (with 0 cookies) {1004BE13F3}> :PROTOCOL :HTTP/1.1 :METHOD :GET :CONTENT-TYPE "application/x-www

It breaks because of this cookie:

set-cookie: ibapauth="client=API,group=VCP-Meter,ctime=1538755825,timeout=7200,mtime=1538755825,ip=10.134.10.30,auth=LOCAL,user=openbook,xbGCCBttvLHdRCahtYaAZVsixnZHaY57zMM"; httponly; Path=/; secure

Here's the output stream which shows where the breakage occurs. It looks like the comma is the point of failure, but the real issue is that the cookie parser doesn't know how to treat a quoted string as a single atomic value.

<SB-IMPL::STRING-OUTPUT-STREAM {100831DC73}>


The object is a STRUCTURE-OBJECT of type SB-IMPL::STRING-OUTPUT-STREAM. IN-BUFFER: NIL CIN-BUFFER: NIL IN-INDEX: 512 IN: # BIN: # N-BIN: # OUT: # BOUT: # SOUT: # MISC: # INPUT-CHAR-POS: NIL BUFFER: "client=API\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" PREV: NIL NEXT: NIL POINTER: 10 INDEX: 10 INDEX-CACHE: 0 ELEMENT-TYPE: CHARACTER