1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-20 10:13:43 +00:00

Remove tldjs, noop's and fallback logic

This commit is contained in:
Daniel James Smith
2021-12-06 20:01:49 +01:00
parent 21d6739a18
commit 016e978d1e
8 changed files with 15 additions and 195 deletions

View File

@@ -21,7 +21,6 @@
"@bitwarden/jslib-common": "file:../common",
"duo_web_sdk": "git+https://github.com/duosecurity/duo_web_sdk.git",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"zone.js": "0.11.4"
},
"devDependencies": {
@@ -31,6 +30,7 @@
}
},
"../common": {
"name": "@bitwarden/jslib-common",
"version": "0.0.0",
"license": "GPL-3.0",
"dependencies": {
@@ -42,7 +42,7 @@
"node-forge": "^0.10.0",
"papaparse": "^5.3.0",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"tldts": "5.7.52",
"zxcvbn": "^4.4.2"
},
"devDependencies": {
@@ -50,7 +50,6 @@
"@types/node": "^14.17.1",
"@types/node-forge": "^0.9.7",
"@types/papaparse": "^5.2.5",
"@types/tldjs": "^2.3.0",
"@types/zxcvbn": "^4.4.1",
"rimraf": "^3.0.2",
"typescript": "4.1.5"
@@ -289,11 +288,6 @@
"node": ">=0.10.0"
}
},
"node_modules/punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
},
"node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
@@ -325,18 +319,6 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-W/YVH/QczLUxVjnQhFC61Iq232NWu3TqDdO0S/MtXVz4xybejBov4ud+CIwN9aYqjOecEqIy0PscGkwpG9ZyTw==",
"hasInstallScript": true,
"dependencies": {
"punycode": "^1.4.1"
},
"engines": {
"node": ">= 4"
}
},
"node_modules/tslib": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
@@ -453,7 +435,6 @@
"@types/node": "^14.17.1",
"@types/node-forge": "^0.9.7",
"@types/papaparse": "^5.2.5",
"@types/tldjs": "^2.3.0",
"@types/zxcvbn": "^4.4.1",
"big-integer": "1.6.48",
"browser-hrtime": "^1.1.8",
@@ -462,7 +443,7 @@
"papaparse": "^5.3.0",
"rimraf": "^3.0.2",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"tldts": "5.7.52",
"typescript": "4.1.5",
"zxcvbn": "^4.4.2"
}
@@ -565,11 +546,6 @@
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
},
"punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
@@ -594,14 +570,6 @@
}
}
},
"tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-W/YVH/QczLUxVjnQhFC61Iq232NWu3TqDdO0S/MtXVz4xybejBov4ud+CIwN9aYqjOecEqIy0PscGkwpG9ZyTw==",
"requires": {
"punycode": "^1.4.1"
}
},
"tslib": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",

View File

@@ -37,7 +37,6 @@
"@bitwarden/jslib-common": "file:../common",
"duo_web_sdk": "git+https://github.com/duosecurity/duo_web_sdk.git",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"zone.js": "0.11.4"
}
}

View File

@@ -17,7 +17,6 @@
"node-forge": "^0.10.0",
"papaparse": "^5.3.0",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"tldts": "5.7.52",
"zxcvbn": "^4.4.2"
},
@@ -26,7 +25,6 @@
"@types/node": "^14.17.1",
"@types/node-forge": "^0.9.7",
"@types/papaparse": "^5.2.5",
"@types/tldjs": "^2.3.0",
"@types/zxcvbn": "^4.4.1",
"rimraf": "^3.0.2",
"typescript": "4.1.5"
@@ -83,12 +81,6 @@
"@types/node": "*"
}
},
"node_modules/@types/tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@types/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-BQR04zLE0ve2eNrqxXw/Qp/f6LxvNrj/4A8ZgdQi3SzbBqxFhleI7N4DS/mSjDnODrUaEGgoWg4grAZR1kVj8w==",
"dev": true
},
"node_modules/@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
@@ -327,11 +319,6 @@
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
},
"node_modules/punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
},
"node_modules/querystringify": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
@@ -419,18 +406,6 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"node_modules/tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-W/YVH/QczLUxVjnQhFC61Iq232NWu3TqDdO0S/MtXVz4xybejBov4ud+CIwN9aYqjOecEqIy0PscGkwpG9ZyTw==",
"hasInstallScript": true,
"dependencies": {
"punycode": "^1.4.1"
},
"engines": {
"node": ">= 4"
}
},
"node_modules/tldts": {
"version": "5.7.52",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-5.7.52.tgz",
@@ -590,12 +565,6 @@
"@types/node": "*"
}
},
"@types/tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@types/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-BQR04zLE0ve2eNrqxXw/Qp/f6LxvNrj/4A8ZgdQi3SzbBqxFhleI7N4DS/mSjDnODrUaEGgoWg4grAZR1kVj8w==",
"dev": true
},
"@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
@@ -804,11 +773,6 @@
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
},
"punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
},
"querystringify": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
@@ -877,14 +841,6 @@
}
}
},
"tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-W/YVH/QczLUxVjnQhFC61Iq232NWu3TqDdO0S/MtXVz4xybejBov4ud+CIwN9aYqjOecEqIy0PscGkwpG9ZyTw==",
"requires": {
"punycode": "^1.4.1"
}
},
"tldts": {
"version": "5.7.52",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-5.7.52.tgz",

View File

@@ -24,7 +24,6 @@
"@types/node": "^14.17.1",
"@types/node-forge": "^0.9.7",
"@types/papaparse": "^5.2.5",
"@types/tldjs": "^2.3.0",
"@types/zxcvbn": "^4.4.1",
"rimraf": "^3.0.2",
"typescript": "4.1.5"
@@ -38,7 +37,6 @@
"node-forge": "^0.10.0",
"papaparse": "^5.3.0",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"tldts": "5.7.52",
"zxcvbn": "^4.4.2"
}

View File

@@ -1,7 +0,0 @@
export function getDomain(host: string): string | null {
return null;
}
export function isValid(host: string): boolean {
return true;
}

View File

@@ -1,7 +0,0 @@
export function parse(url: string, options?: object): null {
return null;
}
export function getHostName(host: string, options?: object): null {
return null;
}

View File

@@ -1,4 +1,3 @@
import * as tldjs from 'tldjs';
import * as tldts from 'tldts';
import { I18nService } from '../abstractions/i18n.service';
@@ -197,26 +196,18 @@ export class Utils {
if (uriString === '') {
return null;
}
if (tldts.getHostname != null) {
// Does uriString contain invalid characters
// TODO Needs to possibly be extended, although '!' is a reserved character
if (uriString.indexOf('!') > 0) {
return null;
}
const hostname = tldts.getHostname(uriString, { validHosts: this.validHosts });
if (hostname != null) {
return hostname;
}
}
const url = Utils.getUrl(uriString);
try {
return url != null && url.hostname !== '' ? url.hostname : null;
} catch {
// Does uriString contain invalid characters
// TODO Needs to possibly be extended, although '!' is a reserved character
if (uriString.indexOf('!') > 0) {
return null;
}
const hostname = tldts.getHostname(uriString, { validHosts: this.validHosts });
if (hostname != null) {
return hostname;
}
return null;
}
static getHost(uriString: string): string {
@@ -249,7 +240,8 @@ export class Utils {
httpUrl = true;
}
const parseResult = tldts.parse != null ? tldts.parse(uriString, { validHosts: this.validHosts }) : null;
const parseResult = tldts.parse(uriString, { validHosts: this.validHosts });
if (parseResult != null && parseResult.hostname != null) {
if (parseResult.hostname === 'localhost' || parseResult.isIp) {
return parseResult.hostname;
@@ -261,35 +253,6 @@ export class Utils {
return null;
}
if (httpUrl) {
try {
const url = Utils.getUrlObject(uriString);
const validHostname = tldjs?.isValid != null ? tldjs.isValid(url.hostname) : true;
if (!validHostname) {
return null;
}
if (url.hostname === 'localhost' || Utils.validIpAddress(url.hostname)) {
return url.hostname;
}
const urlDomain = tldjs != null && tldjs.getDomain != null ? tldjs.getDomain(url.hostname) : null;
return urlDomain != null ? urlDomain : url.hostname;
} catch (e) {
// Invalid domain, try another approach below.
}
}
try {
const domain = tldjs != null && tldjs.getDomain != null ? tldjs.getDomain(uriString) : null;
if (domain != null) {
return domain;
}
} catch {
return null;
}
return null;
}

50
package-lock.json generated
View File

@@ -64,7 +64,6 @@
"@bitwarden/jslib-common": "file:../common",
"duo_web_sdk": "git+https://github.com/duosecurity/duo_web_sdk.git",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"zone.js": "0.11.4"
},
"devDependencies": {
@@ -86,7 +85,6 @@
"node-forge": "^0.10.0",
"papaparse": "^5.3.0",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"tldts": "5.7.52",
"zxcvbn": "^4.4.2"
},
@@ -95,7 +93,6 @@
"@types/node": "^14.17.1",
"@types/node-forge": "^0.9.7",
"@types/papaparse": "^5.2.5",
"@types/tldjs": "^2.3.0",
"@types/zxcvbn": "^4.4.1",
"rimraf": "^3.0.2",
"typescript": "4.1.5"
@@ -693,12 +690,6 @@
"@types/node": "*"
}
},
"node_modules/@types/tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@types/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-BQR04zLE0ve2eNrqxXw/Qp/f6LxvNrj/4A8ZgdQi3SzbBqxFhleI7N4DS/mSjDnODrUaEGgoWg4grAZR1kVj8w==",
"dev": true
},
"node_modules/@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
@@ -7625,23 +7616,6 @@
"node": ">=0.6.0"
}
},
"node_modules/tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-W/YVH/QczLUxVjnQhFC61Iq232NWu3TqDdO0S/MtXVz4xybejBov4ud+CIwN9aYqjOecEqIy0PscGkwpG9ZyTw==",
"hasInstallScript": true,
"dependencies": {
"punycode": "^1.4.1"
},
"engines": {
"node": ">= 4"
}
},
"node_modules/tldjs/node_modules/punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
},
"node_modules/tldts": {
"version": "5.7.52",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-5.7.52.tgz",
@@ -9818,7 +9792,6 @@
"duo_web_sdk": "git+https://github.com/duosecurity/duo_web_sdk.git",
"rimraf": "^3.0.2",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"typescript": "4.1.5",
"zone.js": "0.11.4"
}
@@ -9832,7 +9805,6 @@
"@types/node": "^14.17.1",
"@types/node-forge": "^0.9.7",
"@types/papaparse": "^5.2.5",
"@types/tldjs": "^2.3.0",
"@types/zxcvbn": "^4.4.1",
"big-integer": "1.6.48",
"browser-hrtime": "^1.1.8",
@@ -9841,7 +9813,6 @@
"papaparse": "^5.3.0",
"rimraf": "^3.0.2",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"tldts": "5.7.52",
"typescript": "4.1.5",
"zxcvbn": "^4.4.2"
@@ -10134,12 +10105,6 @@
"@types/node": "*"
}
},
"@types/tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@types/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-BQR04zLE0ve2eNrqxXw/Qp/f6LxvNrj/4A8ZgdQi3SzbBqxFhleI7N4DS/mSjDnODrUaEGgoWg4grAZR1kVj8w==",
"dev": true
},
"@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
@@ -15750,21 +15715,6 @@
"setimmediate": "^1.0.4"
}
},
"tldjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tldjs/-/tldjs-2.3.1.tgz",
"integrity": "sha512-W/YVH/QczLUxVjnQhFC61Iq232NWu3TqDdO0S/MtXVz4xybejBov4ud+CIwN9aYqjOecEqIy0PscGkwpG9ZyTw==",
"requires": {
"punycode": "^1.4.1"
},
"dependencies": {
"punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
}
}
},
"tldts": {
"version": "5.7.52",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-5.7.52.tgz",