[Archive] Prevent extracting files with ".." in relative paths
[platform/core/api/webapi-plugins.git] / src / archive / archive_utils.cc
index 3c91f2b..f07be1d 100644 (file)
@@ -224,5 +224,17 @@ std::string getArchiveLogMessage(const int errorCode, const std::string& hint) {
   return std::string(ss.str());
 }
 
+bool pathContainsProhibitedSubstrings(const std::string& path) {
+  ScopeLogger("Path: %s", path.c_str());
+
+  for (const auto& prohibited_substring : kProhibitedSubstrings) {
+    if (path.find(prohibited_substring) != std::string::npos) {
+      LoggerE("Prohibited substring found: %s", prohibited_substring.c_str());
+      return true;
+    }
+  }
+  return false;
+}
+
 }  // namespace archive
 }  // namespace extension