Skip to content

Commit 357d42a

Browse files
authored
fix(miniflare): parse pem file with regex (#9089)
1 parent 6ae1583 commit 357d42a

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

.changeset/soft-wasps-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"miniflare": patch
3+
---
4+
5+
fix: skip comment lines when parsing `NODE_EXTRA_CA_CERTS`

packages/miniflare/src/plugins/core/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ if (process.env.NODE_EXTRA_CA_CERTS !== undefined) {
8484
const extra = readFileSync(process.env.NODE_EXTRA_CA_CERTS, "utf8");
8585
// Split bundle into individual certificates and add each individually:
8686
// https://github.com/cloudflare/miniflare/pull/587/files#r1271579671
87-
const pemBegin = "-----BEGIN";
88-
for (const cert of extra.split(pemBegin)) {
89-
if (cert.trim() !== "") trustedCertificates.push(pemBegin + cert);
87+
const certs = extra.match(
88+
/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/g
89+
);
90+
91+
if (certs !== null) {
92+
trustedCertificates.push(...certs);
9093
}
9194
} catch {}
9295
}

packages/miniflare/test/plugins/core/index.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ opensslTest("NODE_EXTRA_CA_CERTS: loads certificates", async (t) => {
4848
// (see https://github.com/cloudflare/miniflare/pull/587/files#r1271579671)
4949
const caCertsPath = path.join(tmp, "bundle.pem");
5050
const caCerts = [...tls.rootCertificates, cert];
51-
await fs.writeFile(caCertsPath, caCerts.join("\n"));
51+
await fs.writeFile(
52+
caCertsPath,
53+
["## This is a comment which should be ignored\n"].concat(
54+
caCerts.join("\n")
55+
)
56+
);
5257

5358
// Start Miniflare with NODE_EXTRA_CA_CERTS environment variable
5459
// (cannot use sync process methods here as that would block HTTPS server)

0 commit comments

Comments
 (0)