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

fix(docs): add disclaimer about parsing set-cookie #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wesleytodd
Copy link
Member

@wesleytodd wesleytodd commented Nov 19, 2024

This is a common ask. Maybe this type of disclaimer might help?

@wesleytodd wesleytodd changed the title fix(docs): add disclaimer about common report of being unable to pars… fix(docs): add disclaimer about parsing set-cookei Nov 19, 2024
@wesleytodd wesleytodd changed the title fix(docs): add disclaimer about parsing set-cookei fix(docs): add disclaimer about parsing set-cookie Nov 19, 2024
@@ -26,6 +26,8 @@ Parse a HTTP `Cookie` header string and returning an object of all cookie name-v
The `str` argument is the string representing a `Cookie` header value and `options` is an
optional object containing additional parsing options.

**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`.
**Note:** This method does not parse the `Set-Cookie` header.

It already says it parses the Cookie header twice in the above paragraph, would prefer to keep the note shorter so someone skimming actually reads it.

Copy link
Member

Choose a reason for hiding this comment

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

lmao I went in the opposite direction with my suggestion.

Copy link
Member

@jonchurch jonchurch Nov 20, 2024

Choose a reason for hiding this comment

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

I'd split the difference

⚠️ Note: This method does not parse the Set-Cookie header.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am personally in favor of a more detailed description. Honestly I would prefer to talk about the difference and even show a detailed example (on top of what your suggestion is below). The larger we make the block warning for this the more likely someone is to see it IMO. Replying here since this is the one with the discussion, but I lean toward @jonchurch's direction below.

@@ -26,6 +26,8 @@ Parse a HTTP `Cookie` header string and returning an object of all cookie name-v
The `str` argument is the string representing a `Cookie` header value and `options` is an
optional object containing additional parsing options.

**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`.
Copy link
Member

@jonchurch jonchurch Nov 20, 2024

Choose a reason for hiding this comment

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

The example can be improved, as that code works fine.

serialize w/ no options essentially makes a valid Cookie string as it just sets the cookie name and value.
The real trouble is when folks use the options. Specifically the flag options like HttpOnly, Secure, Partitioned which aren't key value pairs like a cookie header.

I think we should give folks a little more info so they understand the failure state and risk.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`.
> ⚠️ **NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot safely parse a `set-cookie` header, or the output of `serialize`.
>
> E.g. `cookie.parse(cookie.serialize('name', 'value', { httpOnly: true, secure: true, partitioned: true }))` will drop the `httpOnly, secure, partitioned` values entirely. Parsing `set-cookie` header values will result in unexpected results!

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.

4 participants