Skip to content

cookie.parse ignores HttpOnly; Secure; #200

@gerhardcit

Description

@gerhardcit

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions