Skip to content

Commit b7d74ee

Browse files
committed
禁止GeneratePresignedUrl ip 访问
1 parent 688d527 commit b7d74ee

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

include/op/base_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class BaseOp {
115115
std::istream& is, BaseResp* resp, const SharedTransferHandler& handler = nullptr);
116116

117117
std::string GetRealUrl(const std::string& host, const std::string& path,
118-
bool is_https);
118+
bool is_https, bool is_generate_presigned_url = false);
119119

120120
protected:
121121
bool CheckConfigValidation() const;

src/op/base_op.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ CosResult BaseOp::UploadAction(
323323

324324
// 1. host优先级,私有ip > 自定义域名 > DNS cache > 默认域名
325325
std::string BaseOp::GetRealUrl(const std::string& host, const std::string& path,
326-
bool is_https) {
326+
bool is_https, bool is_generate_presigned_url) {
327327
std::string dest_uri;
328328
std::string dest_host = host;
329329
std::string dest_path = path;
@@ -339,17 +339,17 @@ std::string BaseOp::GetRealUrl(const std::string& host, const std::string& path,
339339
if (m_config &&
340340
m_config->GetSetIntranetOnce() &&
341341
m_config->IsUseIntranet() &&
342-
!m_config->GetIntranetAddr().empty()) {
342+
!m_config->GetIntranetAddr().empty() && !is_generate_presigned_url) {
343343
dest_host = m_config->GetIntranetAddr();
344344
} else if (CosSysConfig::IsUseIntranet() &&
345-
!CosSysConfig::GetIntranetAddr().empty()) {
345+
!CosSysConfig::GetIntranetAddr().empty() && !is_generate_presigned_url) {
346346
dest_host = CosSysConfig::GetIntranetAddr();
347347
} else if (m_config &&
348348
(!m_config->GetDestDomain().empty())) {
349349
dest_host = m_config->GetDestDomain();
350350
} else if (!CosSysConfig::GetDestDomain().empty()) {
351351
dest_host = CosSysConfig::GetDestDomain();
352-
} else if (CosSysConfig::GetUseDnsCache()) {
352+
} else if (CosSysConfig::GetUseDnsCache() && !is_generate_presigned_url) {
353353
dest_host = GetGlobalDnsCacheInstance().Resolve(host);
354354
}
355355

src/op/object_op.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ std::string ObjectOp::GeneratePresignedUrl(const GeneratePresignedUrlReq& req) {
17651765
return "";
17661766
}
17671767

1768-
std::string signed_url = GetRealUrl(host, req.GetPath(), req.UseHttps());
1768+
std::string signed_url = GetRealUrl(host, req.GetPath(), req.UseHttps(), true);
17691769
signed_url += "?sign=" + CodecUtil::EncodeKey(auth_str);
17701770

17711771
const std::map<std::string, std::string>& req_params = req.GetParams();

0 commit comments

Comments
 (0)