Skip to content

Commit b076321

Browse files
author
James Zetlen
authored
switch from vulnerable VALID_DOMAIN regex to is-valid-domain lib (#79)
1 parent fecd645 commit b076321

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

package-lock.json

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
"eol": "^0.9.1",
4646
"get-port": "^3.2.0",
4747
"glob": "^7.1.2",
48+
"is-valid-domain": "^0.1.6",
4849
"lodash": "^4.17.4",
4950
"mkdirp": "^0.5.1",
5051
"password-prompt": "^1.0.4",
5152
"rimraf": "^2.6.2",
5253
"sudo-prompt": "^8.2.0",
5354
"tmp": "^0.0.33",
5455
"tslib": "^1.10.0"
55-
},
56-
"optionalDependencies": {}
56+
}
5757
}

src/constants.ts

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import applicationConfigPath = require('application-config-path');
66
import eol from 'eol';
77
import {mktmp, numericHash} from './utils';
88

9-
export const VALID_IP = /(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}/;
10-
export const VALID_DOMAIN = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.?)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/i;
11-
129
// Platform shortcuts
1310
export const isMac = process.platform === 'darwin';
1411
export const isLinux = process.platform === 'linux';

src/index.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ import {
1111
domainsDir,
1212
rootCAKeyPath,
1313
rootCACertPath,
14-
VALID_DOMAIN,
15-
VALID_IP
1614
} from './constants';
1715
import currentPlatform from './platforms';
1816
import installCertificateAuthority, { ensureCACertReadable, uninstall } from './certificate-authority';
1917
import generateDomainCertificate from './certificates';
2018
import UI, { UserInterface } from './user-interface';
19+
import isValidDomain from 'is-valid-domain';
2120
export { uninstall };
2221

2322
const debug = createDebug('devcert');
@@ -69,11 +68,8 @@ type IReturnData<O extends Options = {}> = (IDomainData) & (IReturnCa<O>) & (IRe
6968
*/
7069
export async function certificateFor<O extends Options>(requestedDomains: string | string[], options: O = {} as O): Promise<IReturnData<O>> {
7170
const domains = Array.isArray(requestedDomains) ? requestedDomains : [requestedDomains];
72-
if (domains.some((d) => VALID_IP.test(d))) {
73-
throw new Error('IP addresses are not supported currently');
74-
}
7571
domains.forEach((domain) => {
76-
if (!VALID_DOMAIN.test(domain)) {
72+
if (!isValidDomain(domain, { subdomain: false, wildcard: false, allowUnicode: true, topLevel: false })) {
7773
throw new Error(`"${domain}" is not a valid domain name.`);
7874
}
7975
});

0 commit comments

Comments
 (0)