Skip to content

Commit

Permalink
region校验防止拼接跳转 (#46)
Browse files Browse the repository at this point in the history
* dev_tidy (merge request !28)

Squash merge branch 'dev_tidy_e8e91608' into 'master'

* 预签名下载不做路径校验

* dev_signUrlDownloadFix (merge request !31)

Squash merge branch 'dev_signUrlDownloadFix' into 'master'

* 状态判断后写入文件

* update

* 404下载创建文件

* dev_bucketPolicy (merge request !34)

Squash merge branch 'dev_bucketPolicy' into 'master'

* dev_optimDemoAndDocNew (merge request !35)

Squash merge branch 'dev_optimDemoAndDocNew' into 'master'
bucket policy逻辑更新到github上

* 更新版本 (merge request !36)

Squash merge branch 'dev_addVersiion' into 'master'

* add interface

* add interface

* add interface

* add request

* dev_optdemo (merge request !41)

Squash merge branch 'dev_optdemo' into 'master'

* modify version (merge request !42)

Squash merge branch 'dev_ci_doc' into 'master'
modify verison

* dev_demoopt13 (merge request !43)

Squash merge branch 'dev_demoopt13' into 'master'

* dev_demoopt14 (merge request !45)

Squash merge branch 'dev_demoopt14' into 'master'

* dev_demo0919 (merge request !46)

Squash merge branch 'dev_demo0919' into 'master'

* region校验

* 更新版本

---------

Co-authored-by: nedzzhang <[email protected]>
Co-authored-by: weiyankong <[email protected]>
Co-authored-by: weiyankong <[email protected]>
  • Loading branch information
4 people authored Dec 18, 2024
1 parent 023a68f commit 756d655
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 49 deletions.
2 changes: 1 addition & 1 deletion QCloudCSharpSDK/COSXML/COSXML-Netcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Deterministic>true</Deterministic>

<PackageId>Tencent.QCloud.Cos.Sdk</PackageId>
<Version>5.4.40.0</Version>
<Version>5.4.41.0</Version>
<Authors>Tencent</Authors>
<Company>Tencent</Company>
<description>Tencent Cloud COS(Cloud Object Service) .Net SDK</description>
Expand Down
3 changes: 2 additions & 1 deletion QCloudCSharpSDK/COSXML/Common/CosVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace COSXML.Common
{
public sealed class CosVersion
{
private static string SDKVersion = "5.4.40.0";

private static string SDKVersion = "5.4.41.0";

public static string GetUserAgent()
{
Expand Down
5 changes: 5 additions & 0 deletions QCloudCSharpSDK/COSXML/CosXmlConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public Builder SetRegion(string region)
"region cannot be empty"
);
}
if (region.Contains("@"))
{
throw new CosException.CosClientException((int)COSXML.Common.CosClientError.InvalidArgument,
"region中不能包含特殊字符@");
}
this.region = region;

return this;
Expand Down
56 changes: 31 additions & 25 deletions QCloudCSharpSDK/COSXMLDemo/AccessManage/BucketPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void InitCosXml()
//获取桶的策略
public void GetBucketPolicy()
{
// string bucket = "examplebucket-1250000000";
string bucket = "examplebucket-1250000000";
GetBucketPolicyRequest request = new GetBucketPolicyRequest(bucket);
GetBucketPolicyResult result = cosXml.GetBucketPolicy(request);
Console.WriteLine(result.Data); //返回数据,json格式
Expand All @@ -48,7 +48,7 @@ public void GetBucketPolicy()
//删除桶的策略
public void DeleteBucketPolicy()
{
// string bucket = "examplebucket-1250000000";
string bucket = "examplebucket-1250000000";
DeleteBucketPolicyRequest request = new DeleteBucketPolicyRequest(bucket);
DeleteBucketPolicyResult result = cosXml.DeleteBucketPolicy(request);
Console.WriteLine(result.GetResultInfo());
Expand All @@ -57,32 +57,38 @@ public void DeleteBucketPolicy()
//设置桶的策略
public void PutBucketPolicy()
{
string bucket = "examplebucket-1250000000";
PutBucketPolicyRequest request = new PutBucketPolicyRequest(bucket);
// string region = Environment.GetEnvironmentVariable("COS_REGION");
// string appId = Environment.GetEnvironmentVariable("APPID");
// string resource = "qcs::cos:" + region + ":uid/" + appId + ":" + bucket + "/*";
// string policy = "{\"Statement\":[{\"Action\":[\"name/cos:PutBucketPolicy\",\"name/cos:GetBucketPolicy\",\"name/cos:DeleteBucketPolicy\"],\"Effect\":\"Allow\",\"Principal\":{\"qcs\":[\"qcs::cam::uin/2832742109:uin/100032069732\"]},\"Resource\":[\"" + resource + "\"]}],\"Version\":\"2.0\"}";
// long mainUin = 283274210;
// long subUin = 10003206973;
// string qcs = "qcs::cam::uin/" + mainUin + ":uin/" + subUin;
// string policy = "{\"Statement\":[{\"Action\":[\"name/cos:PutBucketPolicy\",\"name/cos:GetBucketPolicy\",\"name/cos:DeleteBucketPolicy\"],\"Effect\":\"Allow\",\"Principal\":{\"qcs\":[\"" + qcs + "\"]},\"Resource\":[\"" + resource + "\"]}],\"Version\":\"2.0\"}";
// Console.WriteLine(policy);

string policy = @"{
""Statement"": [
{
""Action"": [
""name/cos:PutBucketPolicy"",
""name/cos:GetBucketPolicy"",
""name/cos:DeleteBucketPolicy""
],
""Effect"": ""Allow"",
""Principal"": {
""qcs"": [
""qcs::cam::uin/100000000011:uin/100000000011""
]
},
""Resource"": [
""qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*""
]
}
],
""Version"": ""2.0""
}";
""Statement"": [
{
""Action"": [
""name/cos:PutBucketPolicy"",
""name/cos:GetBucketPolicy"",
""name/cos:DeleteBucketPolicy""
],
""Effect"": ""Allow"",
""Principal"": {
""qcs"": [
""qcs::cam::uin/100000000001:uin/100000000002""
]
},
""Resource"": [
""qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*""
]
}
],
""Version"": ""2.0""
}";
request.SetBucketPolicy(policy);
PutBucketPolicyResult result = cosXml.PutBucketPolicy(request);
Console.WriteLine(result.GetResultInfo());
Expand All @@ -91,8 +97,8 @@ public void PutBucketPolicy()
public static void BucketPolicyMain()
{
BucketPolicyModel demo = new BucketPolicyModel();
// demo.PutBucketPolicy();
demo.GetBucketPolicy();
demo.PutBucketPolicy();
// demo.GetBucketPolicy();
// demo.DeleteBucketPolicy();
}
}
Expand Down
10 changes: 8 additions & 2 deletions QCloudCSharpSDK/COSXMLDemo/DateManage/BucketTagging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ public void GetBucketTagging()
//执行请求
GetBucketTaggingResult result = cosXml.GetBucketTagging(request);
//请求成功
Tagging tagging = result.tagging;
Console.WriteLine(tagging);
if (result.tagging != null)
{
foreach (var tag in result.tagging.tagSet.tags)
{
Console.WriteLine("key {0} value {1}", tag.key, tag.value);
}
}
Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
Expand Down
2 changes: 1 addition & 1 deletion QCloudCSharpSDK/COSXMLDemo/DateManage/BucketWebsite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ public static void BucketWebsiteMain()

}
}
}
}
6 changes: 3 additions & 3 deletions QCloudCSharpSDK/COSXMLDemo/DateManage/ObjectTagging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void GetObjectTagging()
try
{
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
// string bucket = "examplebucket-1250000000";
string bucket = "examplebucket-1250000000";
string key = "exampleobject"; //对象键
GetObjectTaggingRequest request = new GetObjectTaggingRequest(bucket, key);
// 执行请求
Expand Down Expand Up @@ -72,7 +72,7 @@ public void DeleteObjectTagging()
try
{
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
// string bucket = "examplebucket-1250000000";
string bucket = "examplebucket-1250000000";
string key = "exampleobject"; //对象键
DeleteObjectTaggingRequest request = new DeleteObjectTaggingRequest(bucket, key);
// 执行请求
Expand All @@ -95,7 +95,7 @@ public void PutObjectTagging()
try
{
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
// string bucket = "examplebucket-1250000000";
string bucket = "examplebucket-1250000000";
string key = "exampleobject"; //对象键
PutObjectTaggingRequest request = new PutObjectTaggingRequest(bucket, key);
// 增加标签键值对
Expand Down
26 changes: 15 additions & 11 deletions QCloudCSharpSDK/COSXMLDemo/MainProcess.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace COSXMLDemo
{
public class Process
Expand All @@ -10,10 +12,10 @@ static void Main(string[] args)
}

public void DoSomething()
{
// BucketPolicy.BucketPolicyMain();
{
// BucketPolicyModel.BucketPolicyMain();
// DownloadObject.DownloadObjectMain();
// UploadObject.UploadObjectMain();
UploadObject.UploadObjectMain();
// GetObjectUrlDemo.GetObjectUrlDemoMain();

// DeleteObjectModel.DeleteObjectModelMain();
Expand All @@ -24,24 +26,26 @@ public void DoSomething()
// HeadObjectModel.HeadObjectMain();
// ObjectRestoreModel.ObjectRestoreModelMain();
// GetObjectUrlDemo.GetObjectUrlDemoMain();

// CreateBucketModel.CreateBucketModelMain();//
// DeleteBucketModel.DeleteObjectModelMain();//
// DoesBucketExistModel.DoesBucketExistModelMain();//
// HeadBucketModel.HeadBucketModelMain();//
// ListBucketModel.ListBucketModelMain();//
// BucketPolicyModel.BucketPolicyMain();

// BucketVersioningModel.BucketVersioningMain();//
// BucketLifecycleModel.BucketLifecycleMain();
// BucketReplicationModel.BucketReplicationMain();
// BucketLoggingModel.BucketLoggingMain();

ObjectTaggingModel.ObjectTaggingMain();
BucketInventoryModel.BucketInventoryMain();
BucketDomainModel.BucketDomainMain();
PutObjectACLModel.PutObjectACLMain();//
BucketRefererModel.BucketRefererMain();//

// BucketTaggingModel.BucketTaggingMain();
// ObjectTaggingModel.ObjectTaggingMain();
// BucketInventoryModel.BucketInventoryMain();
// BucketDomainModel.BucketDomainMain();
// PutObjectACLModel.PutObjectACLMain();//
// BucketRefererModel.BucketRefererMain();//
// BucketWebsiteModel.BucketWebsiteMain();
}

public void SetEnvironmentVariable()
Expand Down
2 changes: 1 addition & 1 deletion QCloudCSharpSDK/COSXMLDemo/Object/CopyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,4 @@ public static void CopyObjectModelMain()
demo.MoveObject().Wait();
}
}
}
}
7 changes: 3 additions & 4 deletions QCloudCSharpSDK/COSXMLDemo/Object/GetObjectUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ public void GetObjectUrl()
{
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
string bucket = "examplebucket-1250000000";
string key = "exampleobject"; //对象键

string key = "object"; //对象键
// 生成链接(默认域名访问)
String url = cosXml.GetObjectUrl(bucket, key);
Console.WriteLine("Object Url is: " + url);
Expand Down Expand Up @@ -263,11 +262,11 @@ public static void GetObjectUrlDemoMain()
// // 获取预签名上传链接
// demo.GetPreSignUploadUrl();
// 获取无签名访问链接
// demo.GetObjectUrl(); //done
demo.GetObjectUrl(); //done
// 生成预签名 URL,并在签名中携带 Host
// demo.GetPreSignUrlWithHost();
// // 生成预签名URL,并在签名中携带请求参数
// demo.GetPreSignUrlWithReqParam();
}
}
}
}

0 comments on commit 756d655

Please sign in to comment.