Danp2 / au3WebDriver

Web Driver UDF for AutoIt
MIT License
108 stars 23 forks source link

Creating cookies for use in au3webdriver #413

Closed demdante closed 1 year ago

demdante commented 1 year ago

Bug report

Hello, So, I have been looking into how to create cookies for use in au3Webdriver, but I wanted to ask about the _WD_JsonCookie function. Based on the function parameters, it looks like the parameters align with the values found in a cookie with standard Netscape cookie format. Well, almost. If you navigate to the page that I linked above, you can see that a cookie in netscape cookie format provides the following tab-separated properties (format: type example - property description):

  1. string example.com - the domain name
  2. boolean FALSE - include subdomains
  3. string /foobar/ - path
  4. boolean TRUE - send/receive over HTTPS only
  5. number 1462299217 - expires at - seconds since Jan 1st 1970, or 0
  6. string person - name of the cookie
  7. string daniel - value of the cookie

Again, these values almost perfectly align with the parameters that need to be supplied to _WD_JsonCookie, with one exception: item number 2 in the above list, a boolean value indicating whether or not to include subdirectories is not accounted for in _WD_JsonCookie. Instead, it looks like (at least according to the documentation for au3Webdriver) 2 of the parameters the _WD_JsonCookie function contains ($bSecure: defines whether the cookie is a secure cookie, and $bHTTPOnly: This defines whether the cookie is an HTTP only cookie) are related to property number 4 in the above list (send/receive over HTTPS only). With all due respect, I think the _WD_JsonCookie function was either incorrectly written, incorrectly documented, or both, as the two parameters that I mentioned previously provide the same information which can be used to determine the value for property number 4 of a cookie entry in netscape format, making the inclusion of both redundant (an entry would only be secure if it only communicated via HTTPS, meaning that any cookie in which $bSecure = True would require that $bHTTPOnly = False and vice versa, yes?). I think that the two aforementioned parameters for the _WD_JsonCookie function need to be modified to reflect property 2 (include subdomains) and property 4 (send/receive over HTTPS only) of the netscape cookie format. The fact that data types that both function parameters and both netscape cookie format properties accept are identical I believe to be further evidence in support of this. Not sure if this would help or not, but there is a very useful chrome extension that you can use to list all of the cookies that are active on a web page in netscape cookie format.

image

In fact, my plan was to dynamically create the cookies I needed in my script by reading in the contents of cookies file that that tool exports, which is when I encountered the problem that I now present to you. Would love to hear your thoughts on this.

Danp2 commented 1 year ago

@demdante Have you read the W3C Webdriver specs related to cookies, which can be found here?

Danp2 commented 1 year ago

It appears that the Webdriver specs are targeting a newer (still draft) version of the HTTP Cookie definitions. Here's the link if you want to investigate further -- https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis/