@theia/mini-browser 1.74.0-next.6 → 1.74.0-next.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"mini-browser-ws-validator.d.ts","sourceRoot":"","sources":["../../src/node/mini-browser-ws-validator.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B;;GAEG;AACH,qBACa,6BAA8B,YAAW,8BAA8B;IAEhF,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEpC,SAAS,CAAC,eAAe,EAAE,OAAO,CAAS;IAG3C,SAAS,CAAC,IAAI,IAAI,IAAI;IAYhB,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;CAUxE"}
1
+ {"version":3,"file":"mini-browser-ws-validator.d.ts","sourceRoot":"","sources":["../../src/node/mini-browser-ws-validator.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B;;GAEG;AACH,qBACa,6BAA8B,YAAW,8BAA8B;IAEhF,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEpC,SAAS,CAAC,eAAe,EAAE,OAAO,CAAS;IAG3C,SAAS,CAAC,IAAI,IAAI,IAAI;IAYhB,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;CAexE"}
@@ -18,7 +18,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MiniBrowserWsRequestValidator = void 0;
19
19
  const tslib_1 = require("tslib");
20
20
  const inversify_1 = require("@theia/core/shared/inversify");
21
- const url = require("url");
22
21
  const mini_browser_endpoint_1 = require("../common/mini-browser-endpoint");
23
22
  /**
24
23
  * Prevents explicit WebSocket connections from the mini-browser virtual host.
@@ -40,8 +39,14 @@ let MiniBrowserWsRequestValidator = class MiniBrowserWsRequestValidator {
40
39
  }
41
40
  async allowWsUpgrade(request) {
42
41
  if (request.headers.origin && !this.serveSameOrigin) {
43
- const origin = url.parse(request.headers.origin);
44
- if (origin.host && this.miniBrowserHostRe.test(origin.host)) {
42
+ let host;
43
+ try {
44
+ host = new URL(request.headers.origin).host;
45
+ }
46
+ catch {
47
+ host = undefined;
48
+ }
49
+ if (host && this.miniBrowserHostRe.test(host)) {
45
50
  // If the origin comes from the WebViews, refuse:
46
51
  return false;
47
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mini-browser-ws-validator.js","sourceRoot":"","sources":["../../src/node/mini-browser-ws-validator.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAIhF,4DAAyE;AACzE,2BAA2B;AAC3B,2EAAsE;AAEtE;;GAEG;AAEI,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IAAnC;QAIO,oBAAe,GAAY,KAAK,CAAC;IAyB/C,CAAC;IAtBa,IAAI;QACV,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,2CAAmB,CAAC,gBAAgB,CAAC,IAAI,2CAAmB,CAAC,oBAAoB,CAAC;QAC9G,IAAI,OAAO,KAAK,cAAc,EAAE,CAAC;YAC7B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAChC,CAAC;QACD,MAAM,OAAO,GAAG,OAAO;aAClB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;aACrB,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC;aACzB,OAA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CAAmB,CAAC,oBAAoB,CAAC;QAC9G,IAAI,OAAO,KAAK,cAAc,EAAE,CAAC;YAC7B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAChC,CAAC;QACD,MAAM,OAAO,GAAG,OAAO;aAClB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;aACrB,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC;aACzB,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,iBAAiB,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA6B;QAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YAClD,IAAI,IAAwB,CAAC;YAC7B,IAAI,CAAC;gBACD,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YAChD,CAAC;YAAC,MAAM,CAAC;gBACL,IAAI,GAAG,SAAS,CAAC;YACrB,CAAC;YACD,IAAI,IAAI,IAAI,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5C,iDAAiD;gBACjD,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAlCY,sEAA6B;AAO5B;IADT,IAAA,yBAAa,GAAE;;;;yDAWf;wCAjBQ,6BAA6B;IADzC,IAAA,sBAAU,GAAE;GACA,6BAA6B,CAkCzC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mini-browser-ws-validator.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mini-browser-ws-validator.spec.d.ts","sourceRoot":"","sources":["../../src/node/mini-browser-ws-validator.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2026 EclipseSource and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const chai_1 = require("chai");
19
+ const mini_browser_ws_validator_1 = require("./mini-browser-ws-validator");
20
+ describe('MiniBrowserWsRequestValidator', () => {
21
+ function createValidator() {
22
+ const validator = new mini_browser_ws_validator_1.MiniBrowserWsRequestValidator();
23
+ // Uses the default host pattern '{{uuid}}.mini-browser.{{hostname}}'.
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ validator['init']();
26
+ return validator;
27
+ }
28
+ function createRequest(origin) {
29
+ const request = {
30
+ headers: {}
31
+ };
32
+ if (origin !== undefined) {
33
+ request.headers.origin = origin;
34
+ }
35
+ return request;
36
+ }
37
+ it('should refuse WebSocket upgrades from the mini-browser virtual host', async () => {
38
+ const validator = createValidator();
39
+ (0, chai_1.expect)(await validator.allowWsUpgrade(createRequest('http://abc.mini-browser.localhost:3000'))).to.be.false;
40
+ });
41
+ it('should allow WebSocket upgrades from other origins', async () => {
42
+ const validator = createValidator();
43
+ (0, chai_1.expect)(await validator.allowWsUpgrade(createRequest('http://localhost:3000'))).to.be.true;
44
+ });
45
+ it('should allow requests with no Origin header', async () => {
46
+ const validator = createValidator();
47
+ (0, chai_1.expect)(await validator.allowWsUpgrade(createRequest())).to.be.true;
48
+ });
49
+ it('should not throw and should allow when the Origin header is malformed', async () => {
50
+ const validator = createValidator();
51
+ (0, chai_1.expect)(await validator.allowWsUpgrade(createRequest('not-a-valid-url'))).to.be.true;
52
+ });
53
+ });
54
+ //# sourceMappingURL=mini-browser-ws-validator.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mini-browser-ws-validator.spec.js","sourceRoot":"","sources":["../../src/node/mini-browser-ws-validator.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,+BAA8B;AAE9B,2EAA4E;AAE5E,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAE3C,SAAS,eAAe;QACpB,MAAM,SAAS,GAAG,IAAI,yDAA6B,EAAE,CAAC;QACtD,sEAAsE;QACtE,8DAA8D;QAC7D,SAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,SAAS,aAAa,CAAC,MAAe;QAClC,MAAM,OAAO,GAAG;YACZ,OAAO,EAAE,EAA8B;SAClB,CAAC;QAC1B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QACpC,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,EAAE,CAAC,qEAAqE,EAAE,KAAK,IAAI,EAAE;QACjF,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;QACpC,IAAA,aAAM,EAAC,MAAM,SAAS,CAAC,cAAc,CACjC,aAAa,CAAC,wCAAwC,CAAC,CAC1D,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;QAChE,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;QACpC,IAAA,aAAM,EAAC,MAAM,SAAS,CAAC,cAAc,CACjC,aAAa,CAAC,uBAAuB,CAAC,CACzC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;QACpC,IAAA,aAAM,EAAC,MAAM,SAAS,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;QACnF,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;QACpC,IAAA,aAAM,EAAC,MAAM,SAAS,CAAC,cAAc,CACjC,aAAa,CAAC,iBAAiB,CAAC,CACnC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@theia/mini-browser",
3
- "version": "1.74.0-next.6+04cb275b0",
3
+ "version": "1.74.0-next.60+46ce275d4",
4
4
  "description": "Theia - Mini-Browser Extension",
5
5
  "dependencies": {
6
- "@theia/core": "1.74.0-next.6+04cb275b0",
7
- "@theia/filesystem": "1.74.0-next.6+04cb275b0",
6
+ "@theia/core": "1.74.0-next.60+46ce275d4",
7
+ "@theia/filesystem": "1.74.0-next.60+46ce275d4",
8
8
  "@types/mime-types": "^2.1.4",
9
9
  "mime-types": "^2.1.35",
10
10
  "pdfobject": "^2.3.1",
@@ -54,5 +54,5 @@
54
54
  "nyc": {
55
55
  "extends": "../../configs/nyc.json"
56
56
  },
57
- "gitHead": "04cb275b0eb41688cdf025c43555938fea5bc1ef"
57
+ "gitHead": "46ce275d49f80aaaf9eb453a0852bda9da783c76"
58
58
  }
@@ -0,0 +1,66 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 EclipseSource and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { expect } from 'chai';
18
+ import * as http from 'http';
19
+ import { MiniBrowserWsRequestValidator } from './mini-browser-ws-validator';
20
+
21
+ describe('MiniBrowserWsRequestValidator', () => {
22
+
23
+ function createValidator(): MiniBrowserWsRequestValidator {
24
+ const validator = new MiniBrowserWsRequestValidator();
25
+ // Uses the default host pattern '{{uuid}}.mini-browser.{{hostname}}'.
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ (validator as any)['init']();
28
+ return validator;
29
+ }
30
+
31
+ function createRequest(origin?: string): http.IncomingMessage {
32
+ const request = {
33
+ headers: {} as http.IncomingHttpHeaders
34
+ } as http.IncomingMessage;
35
+ if (origin !== undefined) {
36
+ request.headers.origin = origin;
37
+ }
38
+ return request;
39
+ }
40
+
41
+ it('should refuse WebSocket upgrades from the mini-browser virtual host', async () => {
42
+ const validator = createValidator();
43
+ expect(await validator.allowWsUpgrade(
44
+ createRequest('http://abc.mini-browser.localhost:3000')
45
+ )).to.be.false;
46
+ });
47
+
48
+ it('should allow WebSocket upgrades from other origins', async () => {
49
+ const validator = createValidator();
50
+ expect(await validator.allowWsUpgrade(
51
+ createRequest('http://localhost:3000')
52
+ )).to.be.true;
53
+ });
54
+
55
+ it('should allow requests with no Origin header', async () => {
56
+ const validator = createValidator();
57
+ expect(await validator.allowWsUpgrade(createRequest())).to.be.true;
58
+ });
59
+
60
+ it('should not throw and should allow when the Origin header is malformed', async () => {
61
+ const validator = createValidator();
62
+ expect(await validator.allowWsUpgrade(
63
+ createRequest('not-a-valid-url')
64
+ )).to.be.true;
65
+ });
66
+ });
@@ -17,7 +17,6 @@
17
17
  import { WsRequestValidatorContribution } from '@theia/core/lib/node/ws-request-validators';
18
18
  import * as http from 'http';
19
19
  import { injectable, postConstruct } from '@theia/core/shared/inversify';
20
- import * as url from 'url';
21
20
  import { MiniBrowserEndpoint } from '../common/mini-browser-endpoint';
22
21
 
23
22
  /**
@@ -45,8 +44,13 @@ export class MiniBrowserWsRequestValidator implements WsRequestValidatorContribu
45
44
 
46
45
  async allowWsUpgrade(request: http.IncomingMessage): Promise<boolean> {
47
46
  if (request.headers.origin && !this.serveSameOrigin) {
48
- const origin = url.parse(request.headers.origin);
49
- if (origin.host && this.miniBrowserHostRe.test(origin.host)) {
47
+ let host: string | undefined;
48
+ try {
49
+ host = new URL(request.headers.origin).host;
50
+ } catch {
51
+ host = undefined;
52
+ }
53
+ if (host && this.miniBrowserHostRe.test(host)) {
50
54
  // If the origin comes from the WebViews, refuse:
51
55
  return false;
52
56
  }