improve script context handling
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import re
|
||||
|
||||
from core.config import badTags, xsschecker
|
||||
from core.utils import isBadContext, equalize
|
||||
from core.utils import isBadContext, equalize, escaped
|
||||
|
||||
|
||||
def htmlParser(response, encoding):
|
||||
@@ -13,12 +13,22 @@ def htmlParser(response, encoding):
|
||||
position_and_context = {}
|
||||
environment_details = {}
|
||||
clean_response = re.sub(r'<!--[.\s\S]*?-->', '', response)
|
||||
script_context = re.finditer(r'(?i)<script[^>]*>.*?(%s).*?</script>' % xsschecker, clean_response)
|
||||
for occurence in script_context:
|
||||
script_checkable = clean_response
|
||||
for i in range(reflections):
|
||||
occurence = re.search(r'(?i)(?s)<script[^>]*>.*?(%s).*?</script>' % xsschecker, script_checkable)
|
||||
if occurence:
|
||||
thisPosition = occurence.start(1)
|
||||
position_and_context[thisPosition] = 'script'
|
||||
environment_details[thisPosition] = {}
|
||||
environment_details[thisPosition]['details'] = {}
|
||||
environment_details[thisPosition]['details'] = {'quote' : ''}
|
||||
for i in range(len(occurence.group())):
|
||||
currentChar = occurence.group()[i]
|
||||
if currentChar in ('\'', '`', '"') and not escaped(i, occurence.group()):
|
||||
environment_details[thisPosition]['details']['quote'] = currentChar
|
||||
elif currentChar in (')', ']', '}', '}') and not escaped(i, occurence.group()):
|
||||
break
|
||||
script_checkable = script_checkable.replace(xsschecker, '', 1)
|
||||
if len(position_and_context) < reflections:
|
||||
attribute_context = re.finditer(r'<[^>]*?(%s)[^>]*?>' % xsschecker, clean_response)
|
||||
for occurence in attribute_context:
|
||||
match = occurence.group(0)
|
||||
@@ -42,6 +52,7 @@ def htmlParser(response, encoding):
|
||||
position_and_context[thisPosition] = 'attribute'
|
||||
environment_details[thisPosition] = {}
|
||||
environment_details[thisPosition]['details'] = {'tag' : tag, 'type' : Type, 'quote' : quote, 'value' : value, 'name' : name}
|
||||
if len(position_and_context) < reflections:
|
||||
html_context = re.finditer(xsschecker, clean_response)
|
||||
for occurence in html_context:
|
||||
thisPosition = occurence.start()
|
||||
@@ -49,6 +60,7 @@ def htmlParser(response, encoding):
|
||||
position_and_context[occurence.start()] = 'html'
|
||||
environment_details[thisPosition] = {}
|
||||
environment_details[thisPosition]['details'] = {}
|
||||
if len(position_and_context) < reflections:
|
||||
comment_context = re.finditer(r'<!--(?![.\s\S]*-->)[.\s\S]*(%s)[.\s\S]*?-->' % xsschecker, response)
|
||||
for occurence in comment_context:
|
||||
thisPosition = occurence.start(1)
|
||||
|
||||
Reference in New Issue
Block a user