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

Modify parse_cookies to split on first occurrence of '=' only #9

Closed
wants to merge 1 commit into from

Conversation

rpkyle
Copy link
Contributor

@rpkyle rpkyle commented Aug 26, 2019

The parse_cookies function in request.R attempts to split cookies on each occurrence of =; this appears to generate errors such as the following when multiple instances of = occur within a cookie:

ERROR: 'names' attribute [11] must be the same length as the vector [10]

This may be reproduced by using curl or a similar tool to pass a cookie string containing two or more =, e.g.

curl -v -H "Cookie: a=1=2" 127.0.0.1:8050

The original lines are here:

reqres/R/request.R

Lines 437 to 445 in c69c053

parse_cookies = function() {
if (is.null(self$headers$Cookie)) return(list())
cookies <- trimws(strsplit(self$headers$Cookie, ';')[[1]])
cookies <- unlist(strsplit(cookies, '='))
structure(
as.list(url_decode(cookies[c(FALSE, TRUE)])),
names = cookies[c(TRUE, FALSE)]
)
},

This pull request proposes to modify line 440:

cookies <- unlist(strsplit(sub("=", ";", cookies), ";"))

Since sub will only replace the first matching =, strsplit will split the line only once.

@alexcjohnson
Copy link

FWIW we encountered this issue in conjunction with google analytics, which creates cookies like:
__utmz=123456789.1234567890.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);

@thomasp85
Copy link
Owner

I've opted to use stringi instead of substituting = with ; before the split. The outcome is the same though

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

Successfully merging this pull request may close these issues.

None yet

3 participants