mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-16 07:56:12 +03:00
Nginx: Fix UNIQUE_ID
This commit is contained in:
parent
6126374890
commit
35b36b7032
@ -1254,6 +1254,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
return ngx_http_next_body_filter(r, out);
|
||||
}
|
||||
|
||||
#define TXID_SIZE 25
|
||||
|
||||
static ngx_http_modsecurity_ctx_t *
|
||||
ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
|
||||
@ -1263,6 +1264,9 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
|
||||
ngx_http_modsecurity_ctx_t *ctx;
|
||||
apr_sockaddr_t *asa;
|
||||
struct sockaddr_in *sin;
|
||||
char *txid;
|
||||
unsigned char salt[TXID_SIZE];
|
||||
int i;
|
||||
#if (NGX_HAVE_INET6)
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
@ -1336,7 +1340,26 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
|
||||
ctx->req = modsecNewRequest(ctx->connection, cf->config);
|
||||
|
||||
apr_table_setn(ctx->req->notes, NOTE_NGINX_REQUEST_CTX, (const char *) ctx);
|
||||
apr_table_setn(ctx->req->subprocess_env, "UNIQUE_ID", "12345");
|
||||
apr_generate_random_bytes(salt, TXID_SIZE);
|
||||
|
||||
txid = apr_pcalloc (ctx->req->pool, TXID_SIZE);
|
||||
apr_base64_encode (txid, (const char*)salt, TXID_SIZE);
|
||||
|
||||
for(i=0;i<TXID_SIZE;i++) {
|
||||
if((salt[i] >= 0x30) && (salt[i] <= 0x39)) {}
|
||||
else if((salt[i] >= 0x40) && (salt[i] <= 0x5A)) {}
|
||||
else if((salt[i] >= 0x61) && (salt[i] <= 0x7A)) {}
|
||||
else {
|
||||
if((i%2)==0)
|
||||
salt[i] = 0x41;
|
||||
else
|
||||
salt[i] = 0x63;
|
||||
}
|
||||
}
|
||||
|
||||
salt[i] = '\0';
|
||||
|
||||
apr_table_setn(ctx->req->subprocess_env, "UNIQUE_ID", apr_psprintf(ctx->req->pool, "%s", salt));
|
||||
|
||||
ctx->brigade = apr_brigade_create(ctx->req->pool, ctx->req->connection->bucket_alloc);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user