]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: ReplaceKeyPrefixWith and ReplaceKeyWith can not set at the same time. 34599/head
authoryuliyang <yuliyang@cmss.chinamobile.com>
Mon, 13 Jan 2020 08:31:33 +0000 (16:31 +0800)
committerNathan Cutler <ncutler@suse.com>
Thu, 16 Apr 2020 20:11:30 +0000 (22:11 +0200)
and support some HttpErrorCodeReturnedEquals and HttpRedirectCode limit.

fix https://tracker.ceph.com/issues/43563

Signed-off-by: yuliyang <yuliyang@cmss.chinamobile.com>
(cherry picked from commit 0b4689865db3ab8efc39a73070a5d60bd9992fbd)

src/rgw/rgw_xml_enc.cc

index 1b9d250a7a6ccde07132a40d91e52b37cc4dfd60..5473c2f66ef72d59a28d539784d5c5d886230fcb 100644 (file)
@@ -40,14 +40,24 @@ void RGWBWRedirectInfo::dump_xml(Formatter *f) const
   }
 }
 
+#define WEBSITE_HTTP_REDIRECT_CODE_MIN      300
+#define WEBSITE_HTTP_REDIRECT_CODE_MAX      400
 void RGWBWRedirectInfo::decode_xml(XMLObj *obj) {
   RGWXMLDecoder::decode_xml("Protocol", redirect.protocol, obj);
   RGWXMLDecoder::decode_xml("HostName", redirect.hostname, obj);
   int code = 0;
-  RGWXMLDecoder::decode_xml("HttpRedirectCode", code, obj);
+  bool has_http_redirect_code = RGWXMLDecoder::decode_xml("HttpRedirectCode", code, obj);
+  if (has_http_redirect_code &&
+      !(code > WEBSITE_HTTP_REDIRECT_CODE_MIN &&
+        code < WEBSITE_HTTP_REDIRECT_CODE_MAX)) {
+    throw RGWXMLDecoder::err("The provided HTTP redirect code is not valid. Valid codes are 3XX except 300.");
+  }
   redirect.http_redirect_code = code;
-  RGWXMLDecoder::decode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, obj);
-  RGWXMLDecoder::decode_xml("ReplaceKeyWith", replace_key_with, obj);
+  bool has_replace_key_prefix_with = RGWXMLDecoder::decode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, obj);
+  bool has_replace_key_with = RGWXMLDecoder::decode_xml("ReplaceKeyWith", replace_key_with, obj);
+  if (has_replace_key_prefix_with && has_replace_key_with) {
+    throw RGWXMLDecoder::err("You can only define ReplaceKeyPrefix or ReplaceKey but not both.");
+  }
 }
 
 void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const
@@ -60,10 +70,17 @@ void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const
   }
 }
 
+#define WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MIN      400
+#define WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MAX      600
 void RGWBWRoutingRuleCondition::decode_xml(XMLObj *obj) {
   RGWXMLDecoder::decode_xml("KeyPrefixEquals", key_prefix_equals, obj);
   int code = 0;
-  RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code, obj);
+  bool has_http_error_code_returned_equals = RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code, obj);
+  if (has_http_error_code_returned_equals &&
+      !(code >= WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MIN &&
+        code < WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MAX)) {
+    throw RGWXMLDecoder::err("The provided HTTP redirect code is not valid. Valid codes are 4XX or 5XX.");
+  }
   http_error_code_returned_equals = code;
 }