|
26 | 26 | import subprocess |
27 | 27 | import sys |
28 | 28 | import tempfile |
| 29 | +import threading |
29 | 30 | import time |
30 | 31 | import urllib |
31 | 32 | import urllib2 |
|
139 | 140 | from lib.core.settings import REFLECTED_BORDER_REGEX |
140 | 141 | from lib.core.settings import REFLECTED_MAX_REGEX_PARTS |
141 | 142 | from lib.core.settings import REFLECTED_REPLACEMENT_REGEX |
| 143 | +from lib.core.settings import REFLECTED_REPLACEMENT_TIMEOUT |
142 | 144 | from lib.core.settings import REFLECTED_VALUE_MARKER |
143 | 145 | from lib.core.settings import REFLECTIVE_MISS_THRESHOLD |
144 | 146 | from lib.core.settings import SENSITIVE_DATA_REGEX |
@@ -3429,11 +3431,27 @@ def _(value): |
3429 | 3431 | else: |
3430 | 3432 | regex = r"%s\b" % regex |
3431 | 3433 |
|
3432 | | - retVal = re.sub(r"(?i)%s" % regex, REFLECTED_VALUE_MARKER, retVal) |
| 3434 | + _retVal = [retVal] |
| 3435 | + def _thread(regex): |
| 3436 | + _retVal[0] = re.sub(r"(?i)%s" % regex, REFLECTED_VALUE_MARKER, _retVal[0]) |
3433 | 3437 |
|
3434 | | - if len(parts) > 2: |
3435 | | - regex = REFLECTED_REPLACEMENT_REGEX.join(parts[1:]) |
3436 | | - retVal = re.sub(r"(?i)\b%s\b" % regex, REFLECTED_VALUE_MARKER, retVal) |
| 3438 | + if len(parts) > 2: |
| 3439 | + regex = REFLECTED_REPLACEMENT_REGEX.join(parts[1:]) |
| 3440 | + _retVal[0] = re.sub(r"(?i)\b%s\b" % regex, REFLECTED_VALUE_MARKER, _retVal[0]) |
| 3441 | + |
| 3442 | + thread = threading.Thread(target=_thread, args=(regex,)) |
| 3443 | + thread.daemon = True |
| 3444 | + thread.start() |
| 3445 | + thread.join(REFLECTED_REPLACEMENT_TIMEOUT) |
| 3446 | + |
| 3447 | + if thread.isAlive(): |
| 3448 | + kb.reflectiveMechanism = False |
| 3449 | + retVal = content |
| 3450 | + if not suppressWarning: |
| 3451 | + debugMsg = "turning off reflection removal mechanism (because of timeouts)" |
| 3452 | + logger.debug(debugMsg) |
| 3453 | + else: |
| 3454 | + retVal = _retVal[0] |
3437 | 3455 |
|
3438 | 3456 | if retVal != content: |
3439 | 3457 | kb.reflectiveCounters[REFLECTIVE_COUNTER.HIT] += 1 |
|
0 commit comments