diff --git a/spec/common/misc/utils.spec.ts b/spec/common/misc/utils.spec.ts index a224cabfd5..5876415c0f 100644 --- a/spec/common/misc/utils.spec.ts +++ b/spec/common/misc/utils.spec.ts @@ -10,6 +10,10 @@ describe('Utils Service', () => { expect(Utils.getDomain('bitwarden')).toBeNull(); }); + it('should fail for data urls', () => { + expect(Utils.getDomain('data:image/jpeg;base64,AAA')).toBeNull(); + }); + it('should handle urls without protocol', () => { expect(Utils.getDomain('bitwarden.com')).toBe('bitwarden.com'); expect(Utils.getDomain('wrong://bitwarden.com')).toBe('bitwarden.com'); diff --git a/src/misc/utils.ts b/src/misc/utils.ts index 6c1764c205..6131fbd836 100644 --- a/src/misc/utils.ts +++ b/src/misc/utils.ts @@ -182,6 +182,10 @@ export class Utils { return null; } + if (uriString.startsWith('data:')) { + return null; + } + let httpUrl = uriString.startsWith('http://') || uriString.startsWith('https://'); if (!httpUrl && uriString.indexOf('://') < 0 && Utils.tldEndingRegex.test(uriString)) { uriString = 'http://' + uriString;