jshttp / cookie

HTTP server cookie parsing and serialization
MIT License
1.34k stars 156 forks source link

cookie.parse ignores HttpOnly; Secure; #200

Open gerhardcit opened 2 hours ago

gerhardcit commented 2 hours ago

It seems that the parses wants key=value pairs and ignores the HttpOnly; Secure; settings?

import cookie from 'cookie';
const cookieStr = "MY_COOKIE=somevalue; Path=/; Expires=Tue, 29 Oct 2024 06:06:46 GMT; HttpOnly; Secure; SameSite=None";
const parsedCookie = cookie.parse(cookieStr, { decode: String });
console.log("parsedCookie", parsedCookie);

Result: (missing the HttpOnly and Secure settings?

parsedCookie C <[Object: null prototype] {}> {
  MY_COOKIE: 'somevalue',
  Path: '/',
  Expires: 'Tue, 29 Oct 2024 06:06:46 GMT',
  SameSite: 'None'
}

Expected result:

parsedCookie C <[Object: null prototype] {}> {
  MY_COOKIE: 'somevalue',
  Path: '/',
  Expires: 'Tue, 29 Oct 2024 06:06:46 GMT',
  HttpOnly: 'true',
  Secure: 'true',
  SameSite: 'None'
}

if the cookie value is explicit: HttpOnly=true; Secure=true

const cookieStr = "MY_COOKIE=somevalue; Path=/; Expires=Tue, 29 Oct 2024 06:06:46 GMT; HttpOnly=true; Secure=true;

then is parses correctly.

I tried 0.7.2 and 1.0.1. Am I missing something?

gerhardcit commented 2 hours ago

164 seems to discuss this. Does not seem that there is a consensus about what to expect?