Skip to content

Commit 30507df

Browse files
committed
ftx: 去掉严格签名逻辑
1 parent 7ccf128 commit 30507df

File tree

5 files changed

+7
-120
lines changed

5 files changed

+7
-120
lines changed

dist/cos-js-sdk-v5.js

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3932,7 +3932,7 @@ module.exports = function(module) {
39323932
/*! exports provided: name, version, description, main, types, scripts, repository, keywords, author, license, bugs, homepage, dependencies, devDependencies, default */
39333933
/***/ (function(module) {
39343934

3935-
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.9.0-beta.1\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"prettier\":\"prettier --write src demo/demo.js demo/CIDemos/*.js test/test.js server/sts.js lib/request.js index.d.ts\",\"server\":\"node server/sts.js\",\"dev\":\"cross-env NODE_ENV=development webpack -w --mode=development\",\"build\":\"cross-env NODE_ENV=production webpack --mode=production\",\"cos-auth.min.js\":\"uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m\",\"test\":\"jest --runInBand --coverage\",\"postinstall\":\"patch-package\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/tencentyun/cos-js-sdk-v5.git\"},\"keywords\":[],\"author\":\"carsonxu\",\"license\":\"ISC\",\"bugs\":{\"url\":\"https://github.com/tencentyun/cos-js-sdk-v5/issues\"},\"homepage\":\"https://github.com/tencentyun/cos-js-sdk-v5#readme\",\"dependencies\":{\"fast-xml-parser\":\"4.5.0\"},\"devDependencies\":{\"@babel/core\":\"7.17.9\",\"@babel/plugin-transform-runtime\":\"7.18.10\",\"@babel/preset-env\":\"7.16.11\",\"babel-loader\":\"8.2.5\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^5.2.0\",\"express\":\"^4.16.4\",\"jest\":\"29.7.0\",\"jest-environment-jsdom\":\"29.7.0\",\"patch-package\":\"^8.0.0\",\"prettier\":\"^3.0.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"uglifyjs\":\"^2.4.11\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
3935+
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.9.0\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"prettier\":\"prettier --write src demo/demo.js demo/CIDemos/*.js test/test.js server/sts.js lib/request.js index.d.ts\",\"server\":\"node server/sts.js\",\"dev\":\"cross-env NODE_ENV=development webpack -w --mode=development\",\"build\":\"cross-env NODE_ENV=production webpack --mode=production\",\"cos-auth.min.js\":\"uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m\",\"test\":\"jest --runInBand --coverage\",\"postinstall\":\"patch-package\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/tencentyun/cos-js-sdk-v5.git\"},\"keywords\":[],\"author\":\"carsonxu\",\"license\":\"ISC\",\"bugs\":{\"url\":\"https://github.com/tencentyun/cos-js-sdk-v5/issues\"},\"homepage\":\"https://github.com/tencentyun/cos-js-sdk-v5#readme\",\"dependencies\":{\"fast-xml-parser\":\"4.5.0\"},\"devDependencies\":{\"@babel/core\":\"7.17.9\",\"@babel/plugin-transform-runtime\":\"7.18.10\",\"@babel/preset-env\":\"7.16.11\",\"babel-loader\":\"8.2.5\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^5.2.0\",\"express\":\"^4.16.4\",\"jest\":\"29.7.0\",\"jest-environment-jsdom\":\"29.7.0\",\"patch-package\":\"^8.0.0\",\"prettier\":\"^3.0.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"uglifyjs\":\"^2.4.11\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
39363936

39373937
/***/ }),
39383938

@@ -8761,9 +8761,7 @@ function getAuthorizationAsync(params, callback) {
87618761
var headers = util.clone(params.Headers);
87628762
var headerHost = '';
87638763
util.each(headers, function (v, k) {
8764-
if (v === '') {
8765-
delete headers[k];
8766-
}
8764+
(v === '' || ['content-type', 'cache-control', 'expires'].indexOf(k.toLowerCase()) > -1) && delete headers[k];
87678765
if (k.toLowerCase() === 'host') headerHost = v;
87688766
});
87698767
// ForceSignHost明确传入false才不加入host签名
@@ -9054,41 +9052,6 @@ function submitRequest(params, callback) {
90549052
params.qs && (params.qs = util.clearKey(params.qs));
90559053
var Query = util.clone(params.qs);
90569054
params.action && (Query[params.action] = '');
9057-
var contentType;
9058-
var contentLength = 0;
9059-
// 指定一个默认的 content-type,如不指定浏览器默认会指定 text/plain;charset=UTF-8
9060-
var defaultContentType = 'text/plain';
9061-
util.each(params.headers, function (value, key) {
9062-
if (key.toLowerCase() === 'content-type') {
9063-
contentType = value;
9064-
}
9065-
if (key.toLowerCase() === 'content-length') {
9066-
contentLength = value;
9067-
}
9068-
});
9069-
var method = params.method.toLowerCase();
9070-
var body = params.body;
9071-
if (body) {
9072-
if (!contentLength) {
9073-
// 传了请求体需补充 content-length
9074-
var size = util.getContentLength(body);
9075-
if (size === null) {
9076-
callback(util.error(new Error('params body format error, Only allow File|Blob|String.')));
9077-
return;
9078-
}
9079-
params.headers['Content-Length'] = size;
9080-
}
9081-
} else {
9082-
// 非 get、head 请求的空请求体需补充 content-length = 0
9083-
var noContentLengthMethods = ['get', 'head'].includes(method);
9084-
if (!noContentLengthMethods) {
9085-
params.headers['Content-Length'] = 0;
9086-
}
9087-
}
9088-
// 补充默认 content-type,(putObject/multipartInit 不需要补充)
9089-
if (contentType === undefined) {
9090-
params.headers['Content-Type'] = defaultContentType;
9091-
}
90929055

90939056
/**
90949057
* 手动传params.SignHost的场景:cos.getService、cos.getObjectUrl
@@ -10583,7 +10546,7 @@ var obj2str = function obj2str(obj, lowerCaseKey) {
1058310546
};
1058410547

1058510548
// 可以签入签名的headers
10586-
var signHeaders = ['cache-control', 'content-disposition', 'content-encoding', 'content-length', 'content-md5', 'content-type', 'expect', 'expires', 'host', 'if-match', 'if-modified-since', 'if-none-match', 'if-unmodified-since', 'origin', 'range', 'transfer-encoding', 'pic-operations'];
10549+
var signHeaders = ['cache-control', 'content-disposition', 'content-encoding', 'content-length', 'content-md5', 'expect', 'expires', 'host', 'if-match', 'if-modified-since', 'if-none-match', 'if-unmodified-since', 'origin', 'range', 'transfer-encoding', 'pic-operations'];
1058710550
var getSignHeaderObj = function getSignHeaderObj(headers) {
1058810551
var signHeaderObj = {};
1058910552
for (var i in headers) {
@@ -11223,24 +11186,6 @@ var getFileSize = function getFileSize(api, params, callback) {
1122311186
params.ContentLength = size;
1122411187
callback(null, size);
1122511188
};
11226-
var getContentLength = function getContentLength(body) {
11227-
var size = null;
11228-
var haveSize = body instanceof Blob || body.toString() === '[object File]' || body.toString() === '[object Blob]';
11229-
if (typeof body === 'string') {
11230-
var f = new Blob([body], {
11231-
type: 'text/plain'
11232-
});
11233-
size = f.size;
11234-
f = null;
11235-
} else if (body instanceof ArrayBuffer) {
11236-
var f = new Blob([body]);
11237-
size = f.size;
11238-
f = null;
11239-
} else if (haveSize) {
11240-
size = body.size;
11241-
}
11242-
return size;
11243-
};
1124411189

1124511190
// 获取调正的时间戳
1124611191
var getSkewTime = function getSkewTime(offset) {
@@ -11396,7 +11341,6 @@ var util = {
1139611341
camSafeUrlEncode: camSafeUrlEncode,
1139711342
throttleOnProgress: throttleOnProgress,
1139811343
getFileSize: getFileSize,
11399-
getContentLength: getContentLength,
1140011344
getSkewTime: getSkewTime,
1140111345
error: error,
1140211346
obj2str: obj2str,

dist/cos-js-sdk-v5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-js-sdk-v5",
3-
"version": "1.9.0-beta.1",
3+
"version": "1.9.0",
44
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
55
"main": "dist/cos-js-sdk-v5.js",
66
"types": "index.d.ts",

src/base.js

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,9 +3696,7 @@ function getAuthorizationAsync(params, callback) {
36963696
var headers = util.clone(params.Headers);
36973697
var headerHost = '';
36983698
util.each(headers, function (v, k) {
3699-
if (v === '') {
3700-
delete headers[k];
3701-
}
3699+
(v === '' || ['content-type', 'cache-control', 'expires'].indexOf(k.toLowerCase()) > -1) && delete headers[k];
37023700
if (k.toLowerCase() === 'host') headerHost = v;
37033701
});
37043702
// ForceSignHost明确传入false才不加入host签名
@@ -4016,43 +4014,6 @@ function submitRequest(params, callback) {
40164014
var Query = util.clone(params.qs);
40174015
params.action && (Query[params.action] = '');
40184016

4019-
var contentType;
4020-
var contentLength = 0;
4021-
// 指定一个默认的 content-type,如不指定浏览器默认会指定 text/plain;charset=UTF-8
4022-
var defaultContentType = 'text/plain';
4023-
util.each(params.headers, function (value, key) {
4024-
if (key.toLowerCase() === 'content-type') {
4025-
contentType = value;
4026-
}
4027-
if (key.toLowerCase() === 'content-length') {
4028-
contentLength = value;
4029-
}
4030-
});
4031-
4032-
var method = params.method.toLowerCase();
4033-
var body = params.body;
4034-
if (body) {
4035-
if (!contentLength) {
4036-
// 传了请求体需补充 content-length
4037-
var size = util.getContentLength(body);
4038-
if (size === null) {
4039-
callback(util.error(new Error('params body format error, Only allow File|Blob|String.')));
4040-
return;
4041-
}
4042-
params.headers['Content-Length'] = size;
4043-
}
4044-
} else {
4045-
// 非 get、head 请求的空请求体需补充 content-length = 0
4046-
var noContentLengthMethods = ['get', 'head'].includes(method);
4047-
if (!noContentLengthMethods) {
4048-
params.headers['Content-Length'] = 0;
4049-
}
4050-
}
4051-
// 补充默认 content-type,(putObject/multipartInit 不需要补充)
4052-
if (contentType === undefined) {
4053-
params.headers['Content-Type'] = defaultContentType;
4054-
}
4055-
40564017
/**
40574018
* 手动传params.SignHost的场景:cos.getService、cos.getObjectUrl
40584019
* 手动传Url的场景:cos.request

src/util.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ var signHeaders = [
9696
'content-encoding',
9797
'content-length',
9898
'content-md5',
99-
'content-type',
10099
'expect',
101100
'expires',
102101
'host',
@@ -131,6 +130,7 @@ var getAuth = function (opt) {
131130
var method = (opt.method || opt.Method || 'get').toLowerCase();
132131
var queryParams = clone(opt.Query || opt.params || {});
133132
var headers = getSignHeaderObj(clone(opt.Headers || opt.headers || {}));
133+
134134
var Key = opt.Key || '';
135135
var pathname;
136136
if (opt.UseRawKey) {
@@ -815,23 +815,6 @@ var getFileSize = function (api, params, callback) {
815815
callback(null, size);
816816
};
817817

818-
var getContentLength = function (body) {
819-
var size = null;
820-
var haveSize = body instanceof Blob || body.toString() === '[object File]' || body.toString() === '[object Blob]';
821-
if (typeof body === 'string') {
822-
var f = new Blob([body], { type: 'text/plain' });
823-
size = f.size;
824-
f = null;
825-
} else if (body instanceof ArrayBuffer) {
826-
var f = new Blob([body]);
827-
size = f.size;
828-
f = null;
829-
} else if (haveSize) {
830-
size = body.size;
831-
}
832-
return size;
833-
};
834-
835818
// 获取调正的时间戳
836819
var getSkewTime = function (offset) {
837820
return Date.now() + (offset || 0);
@@ -986,7 +969,6 @@ var util = {
986969
camSafeUrlEncode: camSafeUrlEncode,
987970
throttleOnProgress: throttleOnProgress,
988971
getFileSize: getFileSize,
989-
getContentLength: getContentLength,
990972
getSkewTime: getSkewTime,
991973
error: error,
992974
obj2str: obj2str,

0 commit comments

Comments
 (0)