@@ -157,8 +157,11 @@ var getAuth = function (opt) {
157157 pathname . indexOf ( '/' ) !== 0 && ( pathname = '/' + pathname ) ;
158158 }
159159
160- // 如果有传入存储桶,那么签名默认加 Host 参与计算,避免跨桶访问
161- if ( ! headers . Host && ! headers . host && opt . Bucket && opt . Region ) headers . Host = opt . Bucket + '.cos.' + opt . Region + '.myqcloud.com' ;
160+ // ForceSignHost明确传入false才不加入host签名
161+ var forceSignHost = opt . ForceSignHost === false ? false : true ;
162+
163+ // 如果有传入存储桶且需要强制签名,那么签名默认加 Host 参与计算,避免跨桶访问
164+ if ( ! headers . Host && ! headers . host && opt . Bucket && opt . Region && forceSignHost ) headers . Host = opt . Bucket + '.cos.' + opt . Region + '.myqcloud.com' ;
162165
163166 if ( ! SecretId ) throw new Error ( 'missing param SecretId' ) ;
164167 if ( ! SecretKey ) throw new Error ( 'missing param SecretKey' ) ;
@@ -596,6 +599,7 @@ var apiWrapper = function (apiName, apiFn) {
596599 var formatResult = function ( result ) {
597600 if ( result && result . headers ) {
598601 result . headers [ 'x-cos-request-id' ] && ( result . RequestId = result . headers [ 'x-cos-request-id' ] ) ;
602+ result . headers [ 'x-ci-request-id' ] && ( result . RequestId = result . headers [ 'x-ci-request-id' ] ) ;
599603 result . headers [ 'x-cos-version-id' ] && ( result . VersionId = result . headers [ 'x-cos-version-id' ] ) ;
600604 result . headers [ 'x-cos-delete-marker' ] && ( result . DeleteMarker = result . headers [ 'x-cos-delete-marker' ] ) ;
601605 }
@@ -2442,7 +2446,8 @@ var defaultOptions = {
24422446 UploadQueueSize : 10000 ,
24432447 UploadAddMetaMd5 : false ,
24442448 UploadIdCacheLimit : 50 ,
2445- UseAccelerate : false
2449+ UseAccelerate : false ,
2450+ ForceSignHost : true // 默认将host加入签名计算,关闭后可能导致越权风险,建议保持为true
24462451} ;
24472452
24482453// 对外暴露的类
@@ -2485,7 +2490,7 @@ COS.util = {
24852490 json2xml : util . json2xml
24862491} ;
24872492COS . getAuthorization = util . getAuth ;
2488- COS . version = '1.3.5 ' ;
2493+ COS . version = '1.3.6 ' ;
24892494
24902495module . exports = COS ;
24912496
@@ -7901,7 +7906,8 @@ function getObjectUrl(params, callback) {
79017906 Expires : params . Expires ,
79027907 Headers : params . Headers ,
79037908 Query : params . Query ,
7904- SignHost : SignHost
7909+ SignHost : SignHost ,
7910+ ForceSignHost : params . ForceSignHost === false ? false : self . options . ForceSignHost // getObjectUrl支持传参ForceSignHost
79057911 } , function ( err , AuthData ) {
79067912 if ( ! callback ) return ;
79077913 if ( err ) {
@@ -8072,9 +8078,11 @@ function getAuthorizationAsync(params, callback) {
80728078 ( v === '' || [ 'content-type' , 'cache-control' , 'expires' ] . indexOf ( k . toLowerCase ( ) ) > - 1 ) && delete headers [ k ] ;
80738079 if ( k . toLowerCase ( ) === 'host' ) headerHost = v ;
80748080 } ) ;
8081+ // ForceSignHost明确传入false才不加入host签名
8082+ var forceSignHost = params . ForceSignHost === false ? false : true ;
80758083
80768084 // Host 加入签名计算
8077- if ( ! headerHost && params . SignHost ) headers . Host = params . SignHost ;
8085+ if ( ! headerHost && params . SignHost && forceSignHost ) headers . Host = params . SignHost ;
80788086
80798087 // 获取凭证的回调,避免用户 callback 多次
80808088 var cbDone = false ;
@@ -8145,7 +8153,8 @@ function getAuthorizationAsync(params, callback) {
81458153 Expires : params . Expires ,
81468154 UseRawKey : self . options . UseRawKey ,
81478155 SystemClockOffset : self . options . SystemClockOffset ,
8148- KeyTime : KeyTime
8156+ KeyTime : KeyTime ,
8157+ ForceSignHost : self . options . ForceSignHost
81498158 } ) ;
81508159 var AuthData = {
81518160 Authorization : Authorization ,
@@ -8202,7 +8211,8 @@ function getAuthorizationAsync(params, callback) {
82028211 Query : params . Query ,
82038212 Headers : headers ,
82048213 Scope : Scope ,
8205- SystemClockOffset : self . options . SystemClockOffset
8214+ SystemClockOffset : self . options . SystemClockOffset ,
8215+ ForceSignHost : self . options . ForceSignHost
82068216 } , function ( AuthData ) {
82078217 if ( typeof AuthData === 'string' ) AuthData = { Authorization : AuthData } ;
82088218 var AuthError = checkAuthError ( AuthData ) ;
@@ -8245,7 +8255,8 @@ function getAuthorizationAsync(params, callback) {
82458255 Headers : headers ,
82468256 Expires : params . Expires ,
82478257 UseRawKey : self . options . UseRawKey ,
8248- SystemClockOffset : self . options . SystemClockOffset
8258+ SystemClockOffset : self . options . SystemClockOffset ,
8259+ ForceSignHost : self . options . ForceSignHost
82498260 } ) ;
82508261 var AuthData = {
82518262 Authorization : Authorization ,
@@ -8318,7 +8329,8 @@ function submitRequest(params, callback) {
83188329 SignHost : SignHost ,
83198330 Action : params . Action ,
83208331 ResourceKey : params . ResourceKey ,
8321- Scope : params . Scope
8332+ Scope : params . Scope ,
8333+ ForceSignHost : self . options . ForceSignHost
83228334 } , function ( err , AuthData ) {
83238335 if ( err ) {
83248336 callback ( err ) ;
0 commit comments