How to use the bleach.sanitizer.Cleaner function in bleach

To help you get started, we’ve selected a few bleach examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / bleach / tests / test_clean.py View on Github external
def test_basics(self):
        TAGS = ['span', 'br']
        ATTRS = {'span': ['style']}

        cleaner = Cleaner(tags=TAGS, attributes=ATTRS)

        assert (
            cleaner.clean('a <br><span style="color:red">test</span>') ==
            'a <br><span style="">test</span>'
        )
github sethsec / celerystalk / lib / report.py View on Github external
def report(workspace,config_file,target_list=None):
    terminal_width = lib.utils.get_terminal_width()
    if not terminal_width:
        terminal_width = 80
    workspace_mode = lib.db.get_workspace_mode(workspace)[0][0]
    cleaner = Cleaner()
    report_count = 0

    host_report_file_names = []
    if target_list:
        #TODO for loop around targets in scope or somethign...
        a=""
    else:
        #unique_hosts = lib.db.get_unique_hosts_in_workspace(workspace)
        unique_ips = lib.db.get_unique_hosts(workspace)
        unique_submittted_vhosts = lib.db.get_unique_submitted_vhosts(workspace)
        unique_vhosts = lib.db.get_unique_inscope_vhosts(workspace)

        if len(unique_ips) == 0:
            print("[!] - There are no hosts in the [{0}] workspace. Try another?\n".format(workspace))
            exit()
        elif len(unique_submittted_vhosts) == 0:
github gojuukaze / DeerU / tool / html_helper.py View on Github external
def get_safe_comment_html(html_doc):
    cleaner = Cleaner(tags=COMMENT_ALLOWED_TAGS, attributes=COMMENT_ALLOWED_ATTRIBUTES, styles=COMMENT_ALLOWED_STYLES,
                      protocols=COMMENT_ALLOWED_PROTOCOLS, strip=False)
    return cleaner.clean(html_doc)
github gojuukaze / DeerU / tool / html_helper.py View on Github external
def clean_all_tags(html_doc):
    cleaner = Cleaner(tags=[], attributes={}, styles=[], protocols=[], strip=True)
    return cleaner.clean(html_doc)
github mozilla / standup / standup / status / models.py View on Github external
from standup.mdext.nixheaders import NixHeaderExtension


BUG_RE = re.compile(r'(bug #?(\d+))', flags=re.I)
PULL_RE = re.compile(r'((?:pull|pr) #?(\d+))', flags=re.I)
ISSUE_RE = re.compile(r'(issue #?(\d+))', flags=re.I)
USER_RE = re.compile(r'(?&lt;=^|(?&lt;=[^\w\-.]))@([\w-]+)', flags=re.I)
TAG_RE = re.compile(r'(?:^|[^\w\\/])#([a-z][a-z0-9_.-]*)(?:\b|$)', flags=re.I)
MD = Markdown(output_format='html5', extensions=[
    NixHeaderExtension(),
    'nl2br',
    'smart_strong'
])


CLEANER = Cleaner(tags=[])
LINKER = Linker(callbacks=[trim_urls, nofollow])


class StandupUser(models.Model):
    """A standup participant--tied to Django's User model."""
    # Note: User provides "username", "is_superuser", "is_staff" and "email"
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
    name = models.CharField(max_length=100, blank=True, null=True)
    slug = models.SlugField(max_length=100, blank=True, null=True, unique=True)
    irc_nick = models.CharField(
        max_length=100, blank=True, null=True, unique=True,
        help_text='IRC nick for this particular user'
    )

    class Meta:
        # ordering = ('user__username',)
github hasgeek / coaster / coaster / utils / text.py View on Github external
def sanitize_html(value, valid_tags=None, strip=True, linkify=False):
    """
    Strips unwanted markup out of HTML.
    """
    if valid_tags is None:
        valid_tags = VALID_TAGS
    if linkify:
        filters = [
            partial(LinkifyFilter, skip_tags=['pre'], callbacks=DEFAULT_CALLBACKS)
        ]
    else:
        filters = []
    cleaner = Cleaner(
        tags=list(valid_tags.keys()),
        attributes=valid_tags,
        filters=filters,
        strip=strip,
    )
    return Markup(cleaner.clean(value))