from colorama import Fore, Style
from vulnerability_tool.framework.resources.types import ResourceType

TEST_NAME = "ReactJS 'dangerouslySetInnerHTML' XSS Vulnerability"
TEST_DESCRIPTION = """
This test makes sure that dangerouslySetInnerHTML is not used.
Doing so can make your program prone to cross-site scripting attacks.
Source: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml"""

def validate(file, languages_and_libraries, **kwargs):
    if ResourceType.REACT_JS not in languages_and_libraries:
        return (None, None, None, None) # quit

    error = None
    status = "PASS"
    file_name, file_contents = file
    for line_number, line in enumerate(file_contents, 1):
        if "dangerouslySetInnerHTML" in line:
            status = "FAIL"
            error = "XSS Vulnerability in file: %s, line: %d." % (file_name, line_number)
            break

    return (TEST_NAME, TEST_DESCRIPTION, status, error)
from colorama import Fore, Style
from vulnerability_tool.framework.resources.types import ResourceType

TEST_NAME = "ReactJS 'dangerouslySetInnerHTML' XSS Vulnerability"
TEST_DESCRIPTION = """
This test makes sure that dangerouslySetInnerHTML is not used.
Doing so can make your program prone to cross-site scripting attacks.
Source: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml"""

def validate(file, languages_and_libraries, **kwargs):
    if ResourceType.REACT_JS not in languages_and_libraries:
        return (None, None, None, None) # quit

    error = None
    status = "PASS"
    file_name, file_contents = file
    for line_number, line in enumerate(file_contents, 1):
        if "dangerouslySetInnerHTML" in line:
            status = "FAIL"
            error = "XSS Vulnerability in file: %s, line: %d." % (file_name, line_number)
            break

    return (TEST_NAME, TEST_DESCRIPTION, status, error)
This test makes sure that dangerouslySetInnerHTML is not used.
 Doing so can make your program prone to cross-site scripting attacks.
 Source: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml # quit