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

HTTPCookie Constructor Fails to Handle Discard Attribute Properly #4664

Closed
secharvet opened this issue Sep 4, 2024 · 4 comments
Closed

HTTPCookie Constructor Fails to Handle Discard Attribute Properly #4664

secharvet opened this issue Sep 4, 2024 · 4 comments
Assignees

Comments

@secharvet
Copy link

Describe the bug
The HTTPCookie constructor in POCO fails to correctly handle the Discard attribute in HTTP Set-Cookie headers. Instead of recognizing Discard as an attribute, it incorrectly assigns it as the name of the cookie with an empty value, leading to the loss of the actual cookie data.

To Reproduce
You can reproduce this beahvior with a cookie formed like below (Discard token in cookie-av):
unitoken="{AES-256}/exampletoken="; Version=1; Path=/examplePath; Discard; HttpOnly

Expected behavior
Discard should be treated as an attribute of the cookie, not as the cookie name.

** Proposed Solution:**
Add a condition to handle Discard in the constructor similarly to how Secure and HttpOnly are handled.

** Environment:**

  • POCO version: head version
  • Operating System: Linux /Windows
@secharvet secharvet added the bug label Sep 4, 2024
@obiltschnig
Copy link
Member

I don't think Discard is a valid cookie attribute, according to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie

@secharvet
Copy link
Author

Thank you for your prompt response and for the clarification regarding the Discard attribute. I understand that it is not a standard attribute according to the official HTTP cookie specifications.

However, I recently encountered this attribute being sent by a backend Java Spring application, which caused the POCO-based C++ client to fail when parsing the Set-Cookie header. This unexpected behavior from the backend led to significant issues on the client side.

Given that non-standard attributes like Discard can sometimes appear in real-world scenarios, I would like to request if it would be possible to modify the POCO library to gracefully ignore such attributes instead of failing. This change could make POCO more robust and resilient in handling unexpected or non-standard input.

I appreciate your consideration of this request and your continued support for the POCO library.

Best regards,

@obiltschnig
Copy link
Member

Potential fix (to allow non-standard fields): set name and value only once (if _name is empty) in the HTTPCookie constructor accepting a NameValueCollection. The cookie name/value will be the first entry in the NameValueCollection anyway.

@obiltschnig obiltschnig self-assigned this Sep 4, 2024
@obiltschnig obiltschnig added this to the Release 1.13.4 milestone Sep 4, 2024
@secharvet
Copy link
Author

Thank you for your proposed fix. I appreciate the thoughtful approach in handling non-standard fields and ensuring the name/value is set appropriately. This will definitely help make the library more robust in handling real-world scenarios.

Looking forward to seeing this improvement in the next release!

Best regards,

@obiltschnig obiltschnig modified the milestones: Release 1.13.4, Release 1.14.0 Sep 26, 2024
@obiltschnig obiltschnig added this to 1.14 Sep 26, 2024
@obiltschnig obiltschnig moved this to Done in 1.14 Sep 26, 2024
@matejk matejk closed this as completed Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants