Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opening links in desktop IDE #6507

Merged
merged 3 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions app/ide-desktop/lib/client/src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import * as electron from 'electron'
/** The list of hosts that the app can access. They are required for user authentication to work. */
const TRUSTED_HOSTS = ['accounts.google.com', 'accounts.youtube.com', 'github.com']

/** The list of hosts that the app can open external links to. */
const TRUSTED_EXTERNAL_HOSTS = ['discord.gg']

/** The list of URLs a new WebView can be pointed to. */
const WEBVIEW_URL_WHITELIST: string[] = []

Expand Down Expand Up @@ -79,7 +82,12 @@ function preventNavigation() {
electron.app.on('web-contents-created', (_event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
const parsedUrl = new URL(navigationUrl)
if (parsedUrl.origin !== origin && !TRUSTED_HOSTS.includes(parsedUrl.host)) {
const currentWindowUrl = electron.BrowserWindow.getFocusedWindow()?.webContents.getURL()
const parsedCurrentWindowUrl = currentWindowUrl ? new URL(currentWindowUrl) : null
if (
parsedUrl.origin !== parsedCurrentWindowUrl?.origin &&
!TRUSTED_HOSTS.includes(parsedUrl.host)
) {
event.preventDefault()
console.error(`Prevented navigation to '${navigationUrl}'.`)
}
Expand All @@ -95,8 +103,14 @@ function preventNavigation() {
function disableNewWindowsCreation() {
electron.app.on('web-contents-created', (_event, contents) => {
contents.setWindowOpenHandler(({ url }) => {
console.error(`Blocking new window creation request to '${url}'.`)
return { action: 'deny' }
const parsedUrl = new URL(url)
if (TRUSTED_EXTERNAL_HOSTS.includes(parsedUrl.host)) {
void electron.shell.openExternal(url)
return { action: 'deny' }
} else {
console.error(`Blocking new window creation request to '${url}'.`)
return { action: 'deny' }
}
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function TopBar(props: TopBarProps) {
<div className="grow" />
<a
href="https://discord.gg/enso"
target="_blank"
className="flex items-center bg-help rounded-full px-2.5 text-white mx-2"
>
<span>help chat</span>
Expand Down