crypto: don't allow null in generated cert subjects, matching SANs

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67781
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Tim Perry authored and Node.js GitHub Bot committed 2026-11-27 23:17:31 +00:00
1 parent 6ce2fae7f0
commit f966e9f015
4 files changed
+17 -5

No files matched your search

+2 -1
View File
@@ -5346,7 +5346,8 @@ OID or one of `commonName`/`CN`,
`countryName`/`C`, `localityName`/`L`, `stateOrProvinceName`/`ST`,
`organizationName`/`O`, `organizationalUnitName`/`OU`, `serialNumber`,
`streetAddress`, `postalCode`, `domainComponent`/`DC`, `userId`/`UID`,
`emailAddress`/`E`, `title`, `surname`/`SN`, or `givenName`/`GN`.
`emailAddress`/`E`, `title`, `surname`/`SN`, or `givenName`/`GN`. `value` must
not contain NUL characters.
```js
const subject = [
+4 -3
View File
@@ -58,6 +58,7 @@ const {
validateInteger,
validateObject,
validateString,
validateStringWithoutNullBytes,
} = require('internal/validators');
const {
@@ -170,8 +171,8 @@ function snapshotCertificateRequest(value) {
]);
}
function validateUnicode(value, name) {
validateString(value, name);
function validateUnicodeWithoutNul(value, name) {
validateStringWithoutNullBytes(value, name);
if (!StringPrototypeIsWellFormed(value)) {
throw new ERR_INVALID_ARG_VALUE(
name, value, 'contains an unpaired surrogate');
@@ -206,7 +207,7 @@ function normalizeNameAttribute(attribute, name) {
if (ObjectPrototypeHasOwnProperty(kNameAttributes, attributeName)) {
oid = kNameAttributes[attributeName];
}
validateUnicode(value, `${name}.value`);
validateUnicodeWithoutNul(value, `${name}.value`);
return [oid, value];
}
+2 -1
View File
@@ -298,7 +298,8 @@ X509NamePointer BuildName(Environment* env, Local<Array> spec) {
if (!oid) return {};
const std::string text = ReadString(env, content_value);
if (text.size() > static_cast<size_t>(std::numeric_limits<int>::max())) {
if (text.size() > static_cast<size_t>(std::numeric_limits<int>::max()) ||
text.find('\0') != std::string::npos) {
return {};
}
const auto* bytes = reinterpret_cast<const unsigned char*>(text.data());
@@ -615,6 +615,15 @@ const invalidOptions = [
names: [{ type: 'dns', value: 'nul\0.example' }],
}],
})],
['ERR_INVALID_ARG_VALUE', baseOptions(leafKeys, {
subject: [{ name: 'CN', value: 'example.com\0.example' }],
})],
['ERR_INVALID_ARG_VALUE', baseOptions(leafKeys, {
subject: [
{ name: 'CN', value: 'example.com' },
[{ name: 'O', value: 'Node.js' }, { name: '2.5.4.11', value: '\0' }],
],
})],
['ERR_INVALID_ARG_VALUE', baseOptions(leafKeys, {
extensions: [{
type: 'subjectAltName',