@alicloud/fetcher-jsonp 1.5.10-beta.0 → 1.5.10-beta.1
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 +6 -0
- package/build/cjs/util/jsonp.js +11 -6
- package/build/esm/util/jsonp.js +11 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/build/cjs/util/jsonp.js
CHANGED
|
@@ -9,16 +9,21 @@ 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
|
|
12
|
+
var REG_URL_SCHEME = /^([a-z][a-z0-9+.-]*):/i;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript:
|
|
15
|
+
* JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源。
|
|
16
|
+
* 这里用正则解析 scheme,不依赖 new URL(IE11 无 URL 构造函数)。
|
|
16
17
|
*/
|
|
17
18
|
function assertAllowedProtocol(url) {
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
var matched = url.trim().match(REG_URL_SCHEME);
|
|
20
|
+
if (!matched) {
|
|
21
|
+
// 相对路径或协议相对(//host),最终协议与当前页面一致
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
var protocol = (matched[1] || '').toLowerCase();
|
|
25
|
+
if (protocol !== 'http' && protocol !== 'https') {
|
|
26
|
+
throw (0, _createError.default)(_const.EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol, ":"));
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
|
package/build/esm/util/jsonp.js
CHANGED
|
@@ -2,16 +2,21 @@ 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
|
|
5
|
+
var REG_URL_SCHEME = /^([a-z][a-z0-9+.-]*):/i;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript:
|
|
8
|
+
* JSONP 本质是 <script src>,必须限制协议,禁止 data:/blob:/javascript: 等可执行任意代码的来源。
|
|
9
|
+
* 这里用正则解析 scheme,不依赖 new URL(IE11 无 URL 构造函数)。
|
|
9
10
|
*/
|
|
10
11
|
function assertAllowedProtocol(url) {
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var matched = url.trim().match(REG_URL_SCHEME);
|
|
13
|
+
if (!matched) {
|
|
14
|
+
// 相对路径或协议相对(//host),最终协议与当前页面一致
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
var protocol = (matched[1] || '').toLowerCase();
|
|
18
|
+
if (protocol !== 'http' && protocol !== 'https') {
|
|
19
|
+
throw createError(EJsonpError.INVALID_PROTOCOL, "JSONP url protocol is not allowed: ".concat(protocol, ":"));
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
|