cloud-web-corejs 1.0.323 → 1.0.324
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/package.json +1 -1
- package/src/utils/request.js +39 -1
package/package.json
CHANGED
package/src/utils/request.js
CHANGED
|
@@ -42,6 +42,40 @@ function isBinaryRequestBody(data) {
|
|
|
42
42
|
return typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(data);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
function isAbsoluteHttpUrl(url) {
|
|
46
|
+
return /^(https?:)?\/\//i.test(String(url || ""));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function toOrigin(url) {
|
|
50
|
+
try {
|
|
51
|
+
return new URL(String(url), window.location.href).origin;
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 相对地址走当前 baseURL,视为本系统后台。绝对地址只有和后台同源才加密。
|
|
58
|
+
function isOwnBackendRequest(config) {
|
|
59
|
+
const rawUrl = String((config && config.url) || "");
|
|
60
|
+
let targetOrigin = "";
|
|
61
|
+
if (isAbsoluteHttpUrl(rawUrl)) {
|
|
62
|
+
targetOrigin = toOrigin(rawUrl);
|
|
63
|
+
} else {
|
|
64
|
+
const baseUrl =
|
|
65
|
+
config && config.baseURL != null && config.baseURL !== ""
|
|
66
|
+
? config.baseURL
|
|
67
|
+
: configUtil.baseUrl || "";
|
|
68
|
+
targetOrigin = isAbsoluteHttpUrl(baseUrl)
|
|
69
|
+
? toOrigin(baseUrl)
|
|
70
|
+
: window.location.origin;
|
|
71
|
+
}
|
|
72
|
+
const ownBase = configUtil.baseUrl || "";
|
|
73
|
+
const ownOrigin = isAbsoluteHttpUrl(ownBase)
|
|
74
|
+
? toOrigin(ownBase)
|
|
75
|
+
: window.location.origin;
|
|
76
|
+
return !!targetOrigin && targetOrigin === ownOrigin;
|
|
77
|
+
}
|
|
78
|
+
|
|
45
79
|
// 调用方已经 stringify 成对象或数组文本时直接加密,避免再包一层字符串。
|
|
46
80
|
function aesPlainText(data, useEmptyObject) {
|
|
47
81
|
if (typeof data === "string") {
|
|
@@ -89,7 +123,11 @@ service.interceptors.request.use(
|
|
|
89
123
|
);
|
|
90
124
|
}
|
|
91
125
|
const canEncryptBody = !isBinaryRequestBody(config.data);
|
|
92
|
-
if (
|
|
126
|
+
if (
|
|
127
|
+
settingConfig.requestAesEnabled === true &&
|
|
128
|
+
canEncryptBody &&
|
|
129
|
+
isOwnBackendRequest(config)
|
|
130
|
+
) {
|
|
93
131
|
config.data = wrapAesBody(config.data, true);
|
|
94
132
|
config.headers["Content-Type"] = "application/json;charset=UTF-8";
|
|
95
133
|
} else if (
|