Skip to content

NPM is not parsing CN from custom certificate correctly #3862

@MarcoWel

Description

@MarcoWel

getCertificateInfoFromFile() function does not parse cert subject correctly.

const regex = /(?:subject=)?[^=]+=\s+(\S+)/gim;

It expects the CN as first item (by reading match[1]), which is not always the case.

Example:
openssl x509 -in cert.crt -subject -noout
Output: subject=C = DE, ST = State, L = City, O = MyOrg, OU = -, CN = *.example.com

When loading such a certificate in NPM it seems to work, but accessing the Proxy leads to a ERR_SSL_UNRECOGNIZED_NAME_ALERT error in the browser.

Fix: Make subject parsing regex more robust.
This one should be working:

const regex = /(?:subject=)?CN\s*=\s*(\S+)/gim;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions