Skip to content

Commit

Permalink
fix: use defusedxml instead of xml library
Browse files Browse the repository at this point in the history
  • Loading branch information
artemrys committed May 27, 2021
1 parent b47a713 commit c3fdfc0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ reuse = "*"

Sphinx = "^4.0.2"
sphinx-rtd-theme = "^0.5.2"
defusedxml = "^0.7.1"
[tool.poetry.dev-dependencies]
pytest = "^6.0"
pytest-splunk-addon = { version = "^1.6", extras = [ "docker" ] }
Expand Down
4 changes: 2 additions & 2 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys
import argparse
import json
from xml.etree import cElementTree as et
from defusedxml import cElementTree as defused_et
from .uccrestbuilder.global_config import (
GlobalConfigBuilderSchema,
GlobalConfigPostProcessor,
Expand Down Expand Up @@ -586,7 +586,7 @@ def _removeinput(path):
Args:
path (str) : path to default.xml
"""
tree = et.parse(path)
tree = defused_et.parse(path)
root = tree.getroot()

for element in root:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from munch import Munch
from mako.template import Template
from mako.lookup import TemplateLookup
from lxml import etree, html
from defusedxml import lxml as defused_lxml
from re import search
from .alert_actions_template import AlertActionsTemplateMgr
from .alert_actions_helper import write_file
Expand Down Expand Up @@ -74,13 +74,13 @@ def handle_one_alert(self, one_alert_setting):
alert_obj = Munch.fromDict(one_alert_setting)
final_form = self._template.render(mod_alert=alert_obj,
home_page=self._html_home)
final_form = html.fromstring(final_form)
final_form = defused_lxml.fromstring(final_form)
# Checking python version before converting and encoding XML Tree to string.
if sys.version_info < (3, 0):
final_string = etree.tostring(final_form, encoding='utf-8',
final_string = defused_lxml.tostring(final_form, encoding='utf-8',
pretty_print=True)
else:
final_string = etree.tostring(
final_string = defused_lxml.tostring(
final_form, encoding='utf-8', pretty_print=True)
text = linesep.join(
[s for s in final_string.decode('utf-8').splitlines() if not search(r'^\s*$', s)])
Expand Down

0 comments on commit c3fdfc0

Please sign in to comment.