@alicloud/fetcher-jsonp 1.5.9 → 1.5.10-beta.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.5.10-beta.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: post-message 增加消息来源观测(非本窗口/非同源发送),fetcher-jsonp 限制 JSONP 协议为 http(s),修复控制台 PostMessage JSONP XSS
8
+
3
9
  ## 1.0.0 2020/11/30 @驳是
4
10
 
5
- * 开源第一版
11
+ - 开源第一版
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.EJsonpError = void 0;
7
- var EJsonpError = /*#__PURE__*/function (EJsonpError) {
7
+ var EJsonpError = exports.EJsonpError = /*#__PURE__*/function (EJsonpError) {
8
8
  EJsonpError["TIMEOUT"] = "EJsonpTimeout";
9
+ // 超时
9
10
  EJsonpError["NETWORK"] = "EJsonpNetwork";
11
+ // 网络错误,script onerror
12
+ EJsonpError["INVALID_PROTOCOL"] = "EJsonpInvalidProtocol"; // URL 协议不允许
10
13
  return EJsonpError;
11
- }({});
12
- exports.EJsonpError = EJsonpError;
14
+ }({});
@@ -9,6 +9,19 @@ var _const = require("../const");
9
9
  var _createError = _interopRequireDefault(require("./create-error"));
10
10
  var _generateCallbackName = _interopRequireDefault(require("./generate-callback-name"));
11
11
  var _clearCallbackFn = _interopRequireDefault(require("./clear-callback-fn"));
12
+ var ALLOWED_PROTOCOLS = ['http:', 'https:'];
13
+
14
+ /**
15
+ * JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源
16
+ */
17
+ function assertAllowedProtocol(url) {
18
+ var _URL = new URL(url, window.location.href),
19
+ protocol = _URL.protocol;
20
+ if (!ALLOWED_PROTOCOLS.includes(protocol)) {
21
+ throw (0, _createError.default)(_const.EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol));
22
+ }
23
+ }
24
+
12
25
  /**
13
26
  * 一个「纯」的 Promise 封装的 JSONP
14
27
  *
@@ -17,6 +30,11 @@ var _clearCallbackFn = _interopRequireDefault(require("./clear-callback-fn"));
17
30
  function jsonp() {
18
31
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
19
32
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
33
+ try {
34
+ assertAllowedProtocol(url);
35
+ } catch (err) {
36
+ return Promise.reject(err);
37
+ }
20
38
  var _options$timeout = options.timeout,
21
39
  timeout = _options$timeout === void 0 ? 5000 : _options$timeout,
22
40
  charset = options.charset,
@@ -1,5 +1,8 @@
1
1
  export var EJsonpError = /*#__PURE__*/function (EJsonpError) {
2
2
  EJsonpError["TIMEOUT"] = "EJsonpTimeout";
3
+ // 超时
3
4
  EJsonpError["NETWORK"] = "EJsonpNetwork";
5
+ // 网络错误,script onerror
6
+ EJsonpError["INVALID_PROTOCOL"] = "EJsonpInvalidProtocol"; // URL 协议不允许
4
7
  return EJsonpError;
5
8
  }({});
@@ -2,6 +2,18 @@ import { EJsonpError } from '../const';
2
2
  import createError from './create-error';
3
3
  import generateCallbackName from './generate-callback-name';
4
4
  import clearCallbackFn from './clear-callback-fn';
5
+ var ALLOWED_PROTOCOLS = ['http:', 'https:'];
6
+
7
+ /**
8
+ * JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源
9
+ */
10
+ function assertAllowedProtocol(url) {
11
+ var _URL = new URL(url, window.location.href),
12
+ protocol = _URL.protocol;
13
+ if (!ALLOWED_PROTOCOLS.includes(protocol)) {
14
+ throw createError(EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol));
15
+ }
16
+ }
5
17
 
6
18
  /**
7
19
  * 一个「纯」的 Promise 封装的 JSONP
@@ -11,6 +23,11 @@ import clearCallbackFn from './clear-callback-fn';
11
23
  export default function jsonp() {
12
24
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
13
25
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
26
+ try {
27
+ assertAllowedProtocol(url);
28
+ } catch (err) {
29
+ return Promise.reject(err);
30
+ }
14
31
  var _options$timeout = options.timeout,
15
32
  timeout = _options$timeout === void 0 ? 5000 : _options$timeout,
16
33
  charset = options.charset,
@@ -1,4 +1,5 @@
1
1
  export declare enum EJsonpError {
2
- TIMEOUT = "EJsonpTimeout",
3
- NETWORK = "EJsonpNetwork"
2
+ TIMEOUT = "EJsonpTimeout",// 超时
3
+ NETWORK = "EJsonpNetwork",// 网络错误,script onerror
4
+ INVALID_PROTOCOL = "EJsonpInvalidProtocol"
4
5
  }
package/package.json CHANGED
@@ -1,39 +1,26 @@
1
1
  {
2
2
  "name": "@alicloud/fetcher-jsonp",
3
- "version": "1.5.9",
3
+ "version": "1.5.10-beta.0",
4
4
  "description": "fetcher 的底层 jsonp 实现,可独立使用",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "main": "build/cjs/index.js",
8
- "module": "build/es/index.js",
8
+ "module": "build/esm/index.js",
9
9
  "types": "build/types/index.d.ts",
10
- "homepage": "https://github.com/aliyun/alibabacloud-console-base/tree/master/packages-fetcher/fetcher-jsonp",
11
- "author": {
12
- "name": "Jianchun Wang",
13
- "email": "justnewbee@gmail.com"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/aliyun/alibabacloud-console-base.git"
18
- },
19
10
  "publishConfig": {
20
11
  "access": "public"
21
12
  },
22
- "keywords": [
23
- "fetcher",
24
- "jsonp",
25
- "promise"
26
- ],
13
+ "keywords": [],
27
14
  "devDependencies": {
28
15
  "@alicloud/console-base-demo-helper-theme-switcher": "^1.1.9",
29
16
  "@alicloud/console-toolkit-cli": "^1.2.30",
30
17
  "@alicloud/console-toolkit-preset-component": "^1.2.61",
31
- "@alicloud/demo-rc-elements": "^1.11.16",
18
+ "@alicloud/demo-rc-elements": "^1.13.0",
32
19
  "@alicloud/fetcher-demo-helpers": "^1.4.10",
33
20
  "@alicloud/ts-config": "^1.1.3",
34
- "@types/react": "^17.0.48",
21
+ "@types/react": "^17.0.58",
35
22
  "react": "^17.0.2",
36
- "typescript": "^4.9.5"
23
+ "typescript": "^5.0.4"
37
24
  },
38
25
  "scripts": {
39
26
  "start": "breezr start-storybook",
@@ -41,10 +28,9 @@
41
28
  "build:esm": "breezr build --engine babel --es-module",
42
29
  "build:cjs": "breezr build --engine babel",
43
30
  "build:bundle": "breezr build --engine webpack",
44
- "build:typings": "tsc --outDir build/types --declaration --emitDeclarationOnly",
45
- "build": "yarn build:esm && yarn build:cjs && yarn build:typings",
31
+ "build:types": "tsc -p tsconfig-declaration.json --outDir build/types --declaration --emitDeclarationOnly",
32
+ "build": "npm run build:esm && npm run build:cjs && npm run build:types",
46
33
  "clean": "rm -rf build",
47
- "prepublishOnly": "yarn clean && yarn build"
48
- },
49
- "gitHead": "056768173dd99b5af268df646c8a09eb08648920"
34
+ "prepublishOnly": "npm run clean && npm run build"
35
+ }
50
36
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 Alibaba Cloud
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
File without changes
File without changes
File without changes
File without changes