mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 07:13:32 +00:00
getDomain moved to jslib
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 9fa99f3a6e...0d30a1a1c9
6
package-lock.json
generated
6
package-lock.json
generated
@@ -602,9 +602,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/tldjs": {
|
"@types/tldjs": {
|
||||||
"version": "1.7.1",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/tldjs/-/tldjs-1.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/tldjs/-/tldjs-2.3.0.tgz",
|
||||||
"integrity": "sha1-BdPvPLbgPPOt8eSgQ8FHDPIOF5k=",
|
"integrity": "sha512-+gqspH/N6YjpApp96/XzM2AZK4R0Bk2qb4e5o16indSvgblfFaAIxNV8BdJmbqfSAYUyZubLzvrmpvdVEmBq3A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/uglify-js": {
|
"@types/uglify-js": {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
"@types/safari-extension": "^0.0.27",
|
"@types/safari-extension": "^0.0.27",
|
||||||
"@types/safari-extension-content": "^0.0.14",
|
"@types/safari-extension-content": "^0.0.14",
|
||||||
"@types/source-map": "0.5.2",
|
"@types/source-map": "0.5.2",
|
||||||
"@types/tldjs": "^1.7.1",
|
"@types/tldjs": "^2.3.0",
|
||||||
"@types/webcrypto": "^0.0.28",
|
"@types/webcrypto": "^0.0.28",
|
||||||
"@types/webpack": "^4.4.11",
|
"@types/webpack": "^4.4.11",
|
||||||
"angular2-template-loader": "^0.6.2",
|
"angular2-template-loader": "^0.6.2",
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import { NotificationsService as NotificationsServiceAbstraction } from 'jslib/a
|
|||||||
import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service';
|
import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service';
|
||||||
|
|
||||||
import { Analytics } from 'jslib/misc';
|
import { Analytics } from 'jslib/misc';
|
||||||
|
import { Utils } from 'jslib/misc/utils';
|
||||||
|
|
||||||
import { BrowserApi } from '../browser/browserApi';
|
import { BrowserApi } from '../browser/browserApi';
|
||||||
|
|
||||||
@@ -134,8 +135,7 @@ export default class MainBackground {
|
|||||||
this.userService = new UserService(this.tokenService, this.storageService);
|
this.userService = new UserService(this.tokenService, this.storageService);
|
||||||
this.settingsService = new SettingsService(this.userService, this.storageService);
|
this.settingsService = new SettingsService(this.userService, this.storageService);
|
||||||
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
|
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
|
||||||
this.apiService, this.storageService, this.i18nService, this.platformUtilsService,
|
this.apiService, this.storageService, this.i18nService, () => this.searchService);
|
||||||
() => this.searchService);
|
|
||||||
this.folderService = new FolderService(this.cryptoService, this.userService, this.apiService,
|
this.folderService = new FolderService(this.cryptoService, this.userService, this.apiService,
|
||||||
this.storageService, this.i18nService, this.cipherService);
|
this.storageService, this.i18nService, this.cipherService);
|
||||||
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
|
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
|
||||||
@@ -156,7 +156,7 @@ export default class MainBackground {
|
|||||||
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
|
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
|
||||||
this.totpService = new TotpService(this.storageService, cryptoFunctionService);
|
this.totpService = new TotpService(this.storageService, cryptoFunctionService);
|
||||||
this.autofillService = new AutofillService(this.cipherService, this.userService, this.totpService);
|
this.autofillService = new AutofillService(this.cipherService, this.userService, this.totpService);
|
||||||
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
|
this.containerService = new ContainerService(this.cryptoService);
|
||||||
this.auditService = new AuditService(cryptoFunctionService, this.apiService);
|
this.auditService = new AuditService(cryptoFunctionService, this.apiService);
|
||||||
this.exportService = new ExportService(this.folderService, this.cipherService, this.apiService);
|
this.exportService = new ExportService(this.folderService, this.cipherService, this.apiService);
|
||||||
this.notificationsService = new NotificationsService(this.userService, this.syncService, this.appIdService,
|
this.notificationsService = new NotificationsService(this.userService, this.syncService, this.appIdService,
|
||||||
@@ -529,7 +529,7 @@ export default class MainBackground {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabDomain = this.platformUtilsService.getDomain(tab.url);
|
const tabDomain = Utils.getDomain(tab.url);
|
||||||
if (tabDomain == null) {
|
if (tabDomain == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ export default class RuntimeBackground {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabDomain = this.platformUtilsService.getDomain(tab.url);
|
const tabDomain = Utils.getDomain(tab.url);
|
||||||
if (tabDomain != null && tabDomain !== queueMessage.domain) {
|
if (tabDomain != null && tabDomain !== queueMessage.domain) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ export default class RuntimeBackground {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabDomain = this.platformUtilsService.getDomain(tab.url);
|
const tabDomain = Utils.getDomain(tab.url);
|
||||||
if (tabDomain != null && tabDomain !== queueMessage.domain) {
|
if (tabDomain != null && tabDomain !== queueMessage.domain) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ export default class RuntimeBackground {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabDomain = this.platformUtilsService.getDomain(tab.url);
|
const tabDomain = Utils.getDomain(tab.url);
|
||||||
if (tabDomain != null && tabDomain !== queueMessage.domain) {
|
if (tabDomain != null && tabDomain !== queueMessage.domain) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -278,7 +278,7 @@ export default class RuntimeBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async addLogin(loginInfo: any, tab: any) {
|
private async addLogin(loginInfo: any, tab: any) {
|
||||||
const loginDomain = this.platformUtilsService.getDomain(loginInfo.url);
|
const loginDomain = Utils.getDomain(loginInfo.url);
|
||||||
if (loginDomain == null) {
|
if (loginDomain == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ export default class RuntimeBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async changedPassword(changeData: any, tab: any) {
|
private async changedPassword(changeData: any, tab: any) {
|
||||||
const loginDomain = this.platformUtilsService.getDomain(changeData.url);
|
const loginDomain = Utils.getDomain(changeData.url);
|
||||||
if (loginDomain == null) {
|
if (loginDomain == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,35 +3,6 @@ import BrowserPlatformUtilsService from './browserPlatformUtils.service';
|
|||||||
import { DeviceType } from 'jslib/enums';
|
import { DeviceType } from 'jslib/enums';
|
||||||
|
|
||||||
describe('Browser Utils Service', () => {
|
describe('Browser Utils Service', () => {
|
||||||
describe('getDomain', () => {
|
|
||||||
it('should fail for invalid urls', () => {
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain(null)).toBeNull();
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain(undefined)).toBeNull();
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain(' ')).toBeNull();
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('https://bit!:"_&ward.com')).toBeNull();
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('bitwarden')).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle urls without protocol', () => {
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('bitwarden.com')).toBe('bitwarden.com');
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('wrong://bitwarden.com')).toBe('bitwarden.com');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle valid urls', () => {
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('https://bitwarden')).toBe('bitwarden');
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('https://bitwarden.com')).toBe('bitwarden.com');
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('http://bitwarden.com')).toBe('bitwarden.com');
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('http://vault.bitwarden.com')).toBe('bitwarden.com');
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')).toBe('bitwarden.com');
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('https://bitwarden.unknown')).toBe('bitwarden.unknown');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support localhost and IP', () => {
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('https://localhost')).toBe('localhost');
|
|
||||||
expect(BrowserPlatformUtilsService.getDomain('https://192.168.1.1')).toBe('192.168.1.1');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getBrowser', () => {
|
describe('getBrowser', () => {
|
||||||
const originalUserAgent = navigator.userAgent;
|
const originalUserAgent = navigator.userAgent;
|
||||||
const originalSafari = (window as any).safari;
|
const originalSafari = (window as any).safari;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import * as tldjs from 'tldjs';
|
|
||||||
|
|
||||||
import { BrowserApi } from '../browser/browserApi';
|
import { BrowserApi } from '../browser/browserApi';
|
||||||
|
|
||||||
import { DeviceType } from 'jslib/enums/deviceType';
|
import { DeviceType } from 'jslib/enums/deviceType';
|
||||||
@@ -12,43 +10,6 @@ import { AnalyticsIds } from 'jslib/misc/analytics';
|
|||||||
const DialogPromiseExpiration = 600000; // 10 minutes
|
const DialogPromiseExpiration = 600000; // 10 minutes
|
||||||
|
|
||||||
export default class BrowserPlatformUtilsService implements PlatformUtilsService {
|
export default class BrowserPlatformUtilsService implements PlatformUtilsService {
|
||||||
static getDomain(uriString: string): string {
|
|
||||||
if (uriString == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
uriString = uriString.trim();
|
|
||||||
if (uriString === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
|
|
||||||
try {
|
|
||||||
const url = new URL(uriString);
|
|
||||||
|
|
||||||
if (url.hostname === 'localhost' || BrowserPlatformUtilsService.validIpAddress(url.hostname)) {
|
|
||||||
return url.hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlDomain = tldjs.getDomain(url.hostname);
|
|
||||||
return urlDomain != null ? urlDomain : url.hostname;
|
|
||||||
} catch (e) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
const domain = tldjs.getDomain(uriString);
|
|
||||||
if (domain != null) {
|
|
||||||
return domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static validIpAddress(ipString: string): boolean {
|
|
||||||
// tslint:disable-next-line
|
|
||||||
const ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
||||||
return ipRegex.test(ipString);
|
|
||||||
}
|
|
||||||
|
|
||||||
identityClientId: string = 'browser';
|
identityClientId: string = 'browser';
|
||||||
|
|
||||||
private showDialogResolves = new Map<number, { resolve: (value: boolean) => void, date: Date }>();
|
private showDialogResolves = new Map<number, { resolve: (value: boolean) => void, date: Date }>();
|
||||||
@@ -127,10 +88,6 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
|||||||
return this.analyticsIdCache;
|
return this.analyticsIdCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDomain(uriString: string): string {
|
|
||||||
return BrowserPlatformUtilsService.getDomain(uriString);
|
|
||||||
}
|
|
||||||
|
|
||||||
isViewOpen(): boolean {
|
isViewOpen(): boolean {
|
||||||
if (BrowserApi.isPopupOpen()) {
|
if (BrowserApi.isPopupOpen()) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user