-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core,mini-browser: server enhancements
# mini-browser: serve on separate origin The mini-browser currently hosts its services on the same origin than Theia's main origin. This commit makes the `mini-browser` serve on its own origin: `mini-browser.{{hostname}}` by default. Can be configured with a `THEIA_MINI_BROWSER_HOST_PATTERN` environment variable. # core: validate ws upgrade origin Hosting the `mini-browser` on its own origin prevents cross-origin requests from happening easily, but WebSockets don't benefit from the same protection. We need to allow/disallow upgrade requests in the backend application ourselves. This means that in order to know who to refuse, we need to know where we are hosted. This is done by specifying the `THEIA_HOSTS` environment variable. If left empty, no check will be done. But if set, nothing besides what is written in this var will be allowed. See `BackendApplicationHosts` to get the hosts extracted from this var. Note that the latter is not set when running Electron, since there's no need to deal with arbitrary origins, everything should be local. No check is done on the HTTP(s) endpoints because we'll rely on the browser's SOP and CORS policies to take effect. A new contribution point is added: `WsRequestValidatorContribution`. An extender can implement this contribution to allow or not WebSocket connections. Internally used to filter origins and Electron's token as well as checking the origin of requests to prevent some type of XSS. Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
- Loading branch information
1 parent
cd85908
commit 57a88c6
Showing
30 changed files
with
600 additions
and
104 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
39 changes: 39 additions & 0 deletions
39
packages/core/src/electron-main/electron-security-token-service.ts
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,39 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { session } from 'electron'; | ||
import { inject, injectable } from 'inversify'; | ||
import { ElectronSecurityToken } from '../electron-common/electron-token'; | ||
|
||
@injectable() | ||
export class ElectronSecurityTokenService { | ||
|
||
@inject(ElectronSecurityToken) | ||
protected readonly electronSecurityToken: ElectronSecurityToken; | ||
|
||
async setElectronSecurityTokenCookie(url: string): Promise<void> { | ||
await session.defaultSession.cookies.set({ | ||
url, | ||
name: ElectronSecurityToken, | ||
value: JSON.stringify(this.electronSecurityToken), | ||
httpOnly: true | ||
}); | ||
} | ||
|
||
setElectronSecurityTokenEnv(env: { [key: string]: string | undefined }): void { | ||
env[ElectronSecurityToken] = JSON.stringify(this.electronSecurityToken); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/core/src/electron-node/hosting/electron-backend-hosting-module.ts
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,24 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ContainerModule } from 'inversify'; | ||
import { WsRequestValidatorContribution } from '../../node/ws-request-validators'; | ||
import { ElectronWsOriginValidator } from './electron-ws-origin-validator'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(ElectronWsOriginValidator).toSelf().inSingletonScope(); | ||
bind(WsRequestValidatorContribution).toService(ElectronWsOriginValidator); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/core/src/electron-node/hosting/electron-ws-origin-validator.ts
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,29 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as http from 'http'; | ||
import { injectable } from 'inversify'; | ||
import { WsRequestValidatorContribution } from '../../node/ws-request-validators'; | ||
|
||
@injectable() | ||
export class ElectronWsOriginValidator implements WsRequestValidatorContribution { | ||
|
||
allowWsUpgrade(request: http.IncomingMessage): boolean { | ||
// On Electron the main page is served from the `file` protocol. | ||
// We don't expect the requests to come from anywhere else. | ||
return request.headers.origin === 'file://'; | ||
} | ||
} |
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
Oops, something went wrong.