]> granicus.if.org Git - icinga2/commitdiff
Fix incorrect HTTP content length limits
authorGunnar Beutner <gunnar.beutner@icinga.com>
Wed, 28 Feb 2018 11:06:01 +0000 (12:06 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Wed, 28 Feb 2018 13:17:17 +0000 (14:17 +0100)
doc/12-icinga2-api.md
lib/remote/httpserverconnection.cpp

index 8351c90e0c3b13a56ecfdd8c8daa138b22c2317f..01d0e2d284c83c26f3aa7f3f5f7d29f5ca285a05 100644 (file)
@@ -230,12 +230,12 @@ Available permissions for specific URL endpoints:
   actions/&lt;action&gt;        | /v1/actions   | Yes               | 1
   config/query                  | /v1/config    | No                | 1
   config/modify                 | /v1/config    | No                | 512
-  console                       | /v1/console   | No                | 512
+  console                       | /v1/console   | No                | 1
   events/&lt;type&gt;           | /v1/events    | No                | 1
   objects/query/&lt;type&gt;    | /v1/objects   | Yes               | 1
-  objects/create/&lt;type&gt;   | /v1/objects   | No                | 512
-  objects/modify/&lt;type&gt;   | /v1/objects   | Yes               | 512
-  objects/delete/&lt;type&gt;   | /v1/objects   | Yes               | 512
+  objects/create/&lt;type&gt;   | /v1/objects   | No                | 1
+  objects/modify/&lt;type&gt;   | /v1/objects   | Yes               | 1
+  objects/delete/&lt;type&gt;   | /v1/objects   | Yes               | 1
   status/query                  | /v1/status    | Yes               | 1
   templates/&lt;type&gt;        | /v1/templates | Yes               | 1
   types                         | /v1/types     | Yes               | 1
index e087437e613ab4d18fa6563d2fa9dddf5a3c78b4..fdb87097dac6f7c2d7565dfe84117c941915cf50 100644 (file)
@@ -190,15 +190,6 @@ bool HttpServerConnection::ProcessMessage(void)
 
 bool HttpServerConnection::ManageHeaders(HttpResponse& response)
 {
-       static const size_t defaultContentLengthLimit = 1 * 1024 * 1024;
-       static const Dictionary::Ptr specialContentLengthLimits = new Dictionary;
-    specialContentLengthLimits->Set("*", 512 * 1024 * 1024);
-       specialContentLengthLimits->Set("config/modify", 512 * 1024 * 1024);
-       specialContentLengthLimits->Set("console", 512 * 1024 * 1024);
-       specialContentLengthLimits->Set("objects/create", 512 * 1024 * 1024);
-       specialContentLengthLimits->Set("objects/modify", 512 * 1024 * 1024);
-       specialContentLengthLimits->Set("objects/delete", 512 * 1024 * 1024);
-
        if (m_CurrentRequest.Headers->Get("expect") == "100-continue") {
                String continueResponse = "HTTP/1.1 100 Continue\r\n\r\n";
                m_Stream->Write(continueResponse.CStr(), continueResponse.GetLength());
@@ -289,16 +280,34 @@ bool HttpServerConnection::ManageHeaders(HttpResponse& response)
                return false;
        }
 
+       static const size_t defaultContentLengthLimit = 1 * 1024 * 1024;
        size_t maxSize = defaultContentLengthLimit;
 
        Array::Ptr permissions = m_AuthenticatedUser->GetPermissions();
-       ObjectLock olock(permissions);
 
-       for (const Value& permission : permissions) {
-               std::vector<String> permissionParts = String(permission).Split("/");
-               String permissionPath = permissionParts[0] + (permissionParts.size() > 1 ? "/" + permissionParts[1] : "");
-               int size = specialContentLengthLimits->Get(permissionPath);
-               maxSize = size > maxSize ? size : maxSize;
+       if (permissions) {
+               ObjectLock olock(permissions);
+
+               for (const Value& permissionInfo : permissions) {
+                       String permission;
+
+                       if (permissionInfo.IsObjectType<Dictionary>())
+                               permission = static_cast<Dictionary::Ptr>(permissionInfo)->Get("permission");
+                       else
+                               permission = permissionInfo;
+
+                       static std::vector<std::pair<String, size_t>> specialContentLengthLimits {
+                                 { "config/modify", 512 * 1024 * 1024 }
+                       };
+
+                       for (const auto& limitInfo : specialContentLengthLimits) {
+                               if (limitInfo.second <= maxSize)
+                                       continue;
+
+                               if (Utility::Match(permission, limitInfo.first))
+                                       maxSize = limitInfo.second;
+                       }
+               }
        }
 
        size_t contentLength = m_CurrentRequest.Headers->Get("content-length");