Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Validate cookie name #278

Merged
merged 2 commits into from
Jul 19, 2016
Merged

Validate cookie name #278

merged 2 commits into from
Jul 19, 2016

Conversation

tanuck
Copy link
Contributor

@tanuck tanuck commented Jul 17, 2016

This fixes #264

(http.Cookie).String() will silently return an empty string when the cookie name contains a rune not in the following table https://github.com/golang/net/blob/master/lex/httplex/httplex.go#L17

With this patch I've added an additional validator to check the cookie name at boot. I've had to 'mock' a http.Cookie as the http package doesn't export the check function, here: https://github.com/golang/go/blob/master/src/net/http/cookie.go#L368

Regards,
James

@ploxiln
Copy link
Contributor

ploxiln commented Jul 18, 2016

Not a bad idea.

Unrelated quick tip: your links are broken. It's because you used the "Add a link" button in the github comment editor, and pasted the url into the title part (between []) and left the url part blank (between ()). Anyway, you can just paste the link in without anything special and it will do as you expect.

@tanuck
Copy link
Contributor Author

tanuck commented Jul 18, 2016

@ploxiln thanks for spotting that. Should have double checked...

func validateCookieName(o *Options, msgs []string) []string {
cookie := &http.Cookie{Name: o.CookieName}
if cookie.String() == "" {
return append(msgs, "invalid cookie name: "+o.CookieName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use fmt.Sprintf verb %q here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure... Should the usage me made a bit more consistent? I.e func parseSignatureKey uses concatenation, whereas others use fmt.Sprintf?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this PR scoped to this message.

concatenation is "OK" (it's not going to panic or anything) it's just that when the purpose of an error is to highlight unusual values (like a null byte, or a \r) %q can greatly clarify things vs %s.

@jehiah
Copy link
Member

jehiah commented Jul 19, 2016

@tanuck thanks for your contribution. I just had one small comment before we merge this

@jehiah jehiah merged commit c015075 into bitly:master Jul 19, 2016
@tanuck tanuck deleted the validate-cookie-name branch July 19, 2016 20:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

No errors logged when Set-cookie header is not sent in response due to an invalid cookie
3 participants