{
SCLogDebug("save %s", save);
- if (PathIsAbsolute(save)) {
- return 0;
+ int allow_absolute = 0;
+ (void)ConfGetBool("datasets.rules.allow-absolute-filenames", &allow_absolute);
+ if (allow_absolute) {
+ SCLogNotice("Allowing absolute filename for dataset rule: %s", save);
+ } else {
+ if (PathIsAbsolute(save)) {
+ SCLogError("Absolute paths not allowed: %s", save);
+ return -1;
+ }
+
+ if (SCPathContainsTraversal(save)) {
+ SCLogError("Directory traversals not allowed: %s", save);
+ return -1;
+ }
}
// data dir
return final + 1;
}
+
+/**
+ * \brief Check for directory traversal
+ *
+ * \param path The path string to check for traversal
+ *
+ * \retval true if directory traversal is found, otherwise false
+ */
+bool SCPathContainsTraversal(const char *path)
+{
+#ifdef OS_WIN32
+ const char *pattern = "..\\";
+#else
+ const char *pattern = "../";
+#endif
+ return strstr(path, pattern) != NULL;
+}
bool SCIsRegularFile(const struct dirent *const dir_entry);
char *SCRealPath(const char *path, char *resolved_path);
const char *SCBasename(const char *path);
+bool SCPathContainsTraversal(const char *path);
#endif /* __UTIL_PATH_H__ */
# defaults:
# memcap: 100mb
# hashsize: 2048
+#
+# rules:
+# # Set to true to allow absolute filenames and filenames that use
+# # ".." components to reference parent directories in rules that specify
+# # their filenames.
+# #allow-absolute-filenames: false
##############################################################################
##