mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds random id to each assay
This commit is contained in:
parent
3112794025
commit
888b9622c7
@ -135,6 +135,7 @@ class Assay {
|
||||
int http_code_returned;
|
||||
|
||||
private:
|
||||
std::string id;
|
||||
std::ofstream myfile;
|
||||
Rules *m_rules;
|
||||
const char *m_clientIpAddress;
|
||||
|
@ -85,6 +85,8 @@ Assay::Assay(ModSecurity *ms, Rules *rules)
|
||||
do_not_save_in_auditlog(false),
|
||||
m_timeStamp(std::time(NULL)),
|
||||
http_code_returned(200) {
|
||||
id = std::to_string(this->m_timeStamp) + \
|
||||
std::to_string(generate_assay_unique_id());
|
||||
m_rules->incrementReferenceCount();
|
||||
this->debug(4, "Initialising transaction");
|
||||
}
|
||||
|
@ -26,9 +26,7 @@ namespace ModSecurity {
|
||||
* @name ModSecurity
|
||||
* @brief Initilizes ModSecurity CPP API
|
||||
*
|
||||
* ModSecurity initializer. Although it is not really doing anything
|
||||
* in this version, further versions of this API may demands this to
|
||||
* be executed.
|
||||
* ModSecurity initializer.
|
||||
*
|
||||
* Example Usage:
|
||||
* @code
|
||||
@ -41,6 +39,7 @@ namespace ModSecurity {
|
||||
*/
|
||||
ModSecurity::ModSecurity() {
|
||||
UniqueId::uniqueId();
|
||||
srand(time(NULL));
|
||||
}
|
||||
|
||||
|
||||
@ -48,9 +47,7 @@ ModSecurity::ModSecurity() {
|
||||
* @name msc_init
|
||||
* @brief Initilizes ModSecurity C API
|
||||
*
|
||||
* ModSecurity initializer. Although it is not really doing anything
|
||||
* in this version, further versions of this API may demands this to
|
||||
* be executed.
|
||||
* ModSecurity initializer.
|
||||
*
|
||||
* Example Usage:
|
||||
* @code
|
||||
|
22
src/utils.cc
22
src/utils.cc
@ -15,6 +15,14 @@
|
||||
|
||||
#include "src/utils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <random>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include "modsecurity/modsecurity.h"
|
||||
|
||||
@ -33,5 +41,19 @@ std::vector<std::string> split(std::string str, char delimiter) {
|
||||
}
|
||||
|
||||
|
||||
double random_number(const double from, const double to) {
|
||||
std::random_device rd;
|
||||
|
||||
return std::bind(
|
||||
std::uniform_real_distribution<>{from, to},
|
||||
std::default_random_engine{ rd() })();
|
||||
}
|
||||
|
||||
|
||||
double generate_assay_unique_id() {
|
||||
return random_number(0, 100);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ModSecurity
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
namespace ModSecurity {
|
||||
std::vector<std::string> split(std::string str, char delimiter);
|
||||
double random_number(const double from, const double to);
|
||||
double generate_assay_unique_id();
|
||||
} // namespace ModSecurity
|
||||
|
||||
#define SRC_UTILS_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user