Language: Python
Label: safe
CWE: CWE-79 \u2014 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.

Code:
def clean_html(html):
    """Use nh3/ammonia to strip out all HTML tags and attributes except those explicitly permitted."""
    return nh3.clean(
        html,
        tags=constants.HTML_ALLOWED_TAGS,
        attributes=constants.HTML_ALLOWED_ATTRIBUTES,
        url_schemes=set(settings.ALLOWED_URL_SCHEMES),
    )