Skip to content

🐛 BUG: Custom HTTPS certificate is considered expired if it's older than 30 days #5964

@trygveaa

Description

@trygveaa

Which Cloudflare product(s) does this pertain to?

Wrangler core

What version(s) of the tool(s) are you using?

3.58.0 [Wrangler]

What version of Node are you using?

22.2.0

What operating system and version are you using?

Arch Linux

Describe the Bug

Observed behavior

When trying to use a custom HTTPS certificate with wrangler dev, it fails with "Custom Certificate is invalid" if the certificate file is modified more than 30 days ago. This is because the hasCertificateExpired function just looks at the file modification time to determine if the certificate is expired. While this way of checking might make sense to determine if the generated certificate should be generated, it doesn't make sense to do a check like this for a certificate provided with the --https-cert-path option.

Expected behavior

Rather than checking the modification time of the file, it should parse the actual certificate and extract the expiration date. Alternatively just use the certificate without checking the expiry time, because it's up to the client to check that.

Steps to reproduce

# Generate a dummy certificate for this example
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"

# Set the modify time of the certificate and key in the past to simulate a certificate you have generated at an earlier time
touch -t 2401010000 cert.pem key.pem

# Set up wrangler
npm i wrangler
echo 'main = "index.js"' > wrangler.toml
touch index.js

# Start wrangler dev
./node_modules/.bin/wrangler dev --local-protocol https --https-cert-path cert.pem --https-key-path key.pem

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

Metadata

Metadata

Assignees

Labels

bugSomething that isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions