-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-3683] Remove ipcRenderer from electron-platform-utils (#6679)
* [PM-3683] Remove ipcRenderer from electron-platform-utils * FIx review comments * Formatting * Use isNullOrWhitespace
- Loading branch information
1 parent
a1729c9
commit c592bcb
Showing
9 changed files
with
112 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { SafeUrls } from "./safe-urls"; | ||
|
||
describe("SafeUrls service", () => { | ||
it("should allow valid URLs", () => { | ||
expect(SafeUrls.canLaunch("https://bitwarden.com")).toBe(true); | ||
expect(SafeUrls.canLaunch("http://bitwarden.com")).toBe(true); | ||
expect(SafeUrls.canLaunch("ssh://my-server")).toBe(true); | ||
}); | ||
|
||
it("should fail invalid URLs", () => { | ||
expect(SafeUrls.canLaunch("bitwarden.com")).toBe(false); | ||
expect(SafeUrls.canLaunch("")).toBe(false); | ||
expect(SafeUrls.canLaunch(null)).toBe(false); | ||
}); | ||
|
||
it("should fail URLs with disallowed protocols", () => { | ||
expect(SafeUrls.canLaunch("file:///etc/passwd")).toBe(false); | ||
expect(SafeUrls.canLaunch("\\\\network.share\\abc")).toBe(false); | ||
expect(SafeUrls.canLaunch("smb://smb.server")).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Utils } from "./utils"; | ||
|
||
const CanLaunchWhitelist = [ | ||
"https://", | ||
"http://", | ||
"ssh://", | ||
"ftp://", | ||
"sftp://", | ||
"irc://", | ||
"vnc://", | ||
// https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/remote-desktop-uri | ||
"rdp://", // Legacy RDP URI scheme | ||
"ms-rd:", // Preferred RDP URI scheme | ||
"chrome://", | ||
"iosapp://", | ||
"androidapp://", | ||
]; | ||
|
||
export class SafeUrls { | ||
static canLaunch(uri: string): boolean { | ||
if (Utils.isNullOrWhitespace(uri)) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < CanLaunchWhitelist.length; i++) { | ||
if (uri.indexOf(CanLaunchWhitelist[i]) === 0) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters