Skip to content

Commit 66b3c1d

Browse files
committed
Use security-patched defusedxml, if available
The Python stdlib xml module has several known vulnerabilities in its XML parsing code, which defusedxml corrects. We attempt to load defused, and if it fails to import, just continue with stdlib.
1 parent f4615cf commit 66b3c1d

File tree

6 files changed

+55
-24
lines changed

6 files changed

+55
-24
lines changed

src/classes/ui_util.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
1-
"""
1+
"""
22
@file
33
@brief This file contains PyQt help functions, to translate the interface, load icons, and connect signals
44
@author Noah Figg <[email protected]>
55
@author Jonathan Thomas <[email protected]>
66
@author Olivier Girard <[email protected]>
7-
7+
88
@section LICENSE
9-
9+
1010
Copyright (c) 2008-2018 OpenShot Studios, LLC
1111
(http://www.openshotstudios.com). This file is part of
1212
OpenShot Video Editor (http://www.openshot.org), an open-source project
1313
dedicated to delivering high quality video editing and animation solutions
1414
to the world.
15-
15+
1616
OpenShot Video Editor is free software: you can redistribute it and/or modify
1717
it under the terms of the GNU General Public License as published by
1818
the Free Software Foundation, either version 3 of the License, or
1919
(at your option) any later version.
20-
20+
2121
OpenShot Video Editor is distributed in the hope that it will be useful,
2222
but WITHOUT ANY WARRANTY; without even the implied warranty of
2323
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2424
GNU General Public License for more details.
25-
25+
2626
You should have received a copy of the GNU General Public License
2727
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2828
"""
2929

3030
import os
31-
import xml.etree.ElementTree
3231
import time
3332

33+
# Try to get the security-patched XML functions from defusedxml
34+
try:
35+
from defusedxml import ElementTree
36+
except ImportError:
37+
from xml.etree import ElementTree
38+
3439
from PyQt5.QtCore import QDir, QLocale
3540
from PyQt5.QtGui import QIcon
3641
from PyQt5.QtWidgets import *
@@ -85,7 +90,7 @@ def load_ui(window, path):
8590
raise error
8691

8792
# Save xml tree for ui
88-
window.uiTree = xml.etree.ElementTree.parse(path)
93+
window.uiTree = ElementTree.parse(path)
8994

9095

9196
def get_default_icon(theme_name):

src/language/generate_translations.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/python3
2-
"""
2+
"""
33
@file
44
@brief This file updates the OpenShot.POT (language translation template) by scanning all source files.
55
@author Jonathan Thomas <[email protected]>
6-
6+
77
This file helps you generate the POT file that contains all of the translatable
88
strings / text in OpenShot. Because some of our text is in custom XML files,
9-
the xgettext command can't correctly generate the POT file. Thus... the
9+
the xgettext command can't correctly generate the POT file. Thus... the
1010
existence of this file. =)
1111
1212
Command to create the individual language PO files (Ascii files)
@@ -28,23 +28,23 @@
2828
$ msgcat ~/openshot/locale/OpenShot/OpenShot_source.pot ~/openshot/openshot/locale/OpenShot/OpenShot_glade.pot -o ~/openshot/main/locale/OpenShot/OpenShot.pot
2929
3030
@section LICENSE
31-
31+
3232
Copyright (c) 2008-2018 OpenShot Studios, LLC
3333
(http://www.openshotstudios.com). This file is part of
3434
OpenShot Video Editor (http://www.openshot.org), an open-source project
3535
dedicated to delivering high quality video editing and animation solutions
3636
to the world.
37-
37+
3838
OpenShot Video Editor is free software: you can redistribute it and/or modify
3939
it under the terms of the GNU General Public License as published by
4040
the Free Software Foundation, either version 3 of the License, or
4141
(at your option) any later version.
42-
42+
4343
OpenShot Video Editor is distributed in the hope that it will be useful,
4444
but WITHOUT ANY WARRANTY; without even the implied warranty of
4545
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4646
GNU General Public License for more details.
47-
47+
4848
You should have received a copy of the GNU General Public License
4949
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
5050
"""
@@ -54,8 +54,14 @@
5454
import os
5555
import subprocess
5656
import sys
57-
import xml.dom.minidom as xml
5857
import json
58+
59+
# Try to get the security-patched XML functions from defusedxml
60+
try:
61+
from defusedxml import minidom as xml
62+
except ImportError:
63+
from xml.dom import minidom as xml
64+
5965
import openshot
6066

6167
# Get the absolute path of this project

src/windows/export.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@
2828
import locale
2929
import os
3030
import time
31-
import xml.dom.minidom as xml
3231
import tempfile
3332

33+
# Try to get the security-patched XML functions from defusedxml
34+
try:
35+
from defusedxml import minidom as xml
36+
except ImportError:
37+
from xml.dom import minidom as xml
3438

3539
from PyQt5.QtCore import *
3640
from PyQt5.QtWidgets import *

src/windows/file_properties.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,26 @@
2727

2828
import os
2929
import locale
30-
import xml.dom.minidom as xml
3130
import functools
31+
import json
32+
33+
# Try to get the security-patched XML functions from defusedxml
34+
try:
35+
from defusedxml import minidom as xml
36+
except ImportError:
37+
from xml.dom import minidom as xml
3238

3339
from PyQt5.QtCore import *
3440
from PyQt5.QtWidgets import *
35-
import openshot # Python module for libopenshot (required video editing module installed separately)
41+
42+
# Python module for libopenshot (required video editing module installed separately)
43+
import openshot
3644

3745
from classes import info, ui_util, settings
3846
from classes.app import get_app
3947
from classes.logger import log
4048
from classes.metrics import *
4149

42-
import json
4350

4451
class FileProperties(QDialog):
4552
""" File Properties Dialog """

src/windows/models/blender_model.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
"""
2727

2828
import os
29-
import xml.dom.minidom as xml
29+
30+
# Try to get the security-patched XML functions from defusedxml
31+
try:
32+
from defusedxml import minidom as xml
33+
except ImportError:
34+
from xml.dom import minidom as xml
3035

3136
from PyQt5.QtCore import Qt, QSize
3237
from PyQt5.QtGui import *

src/windows/views/blender_listview.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@
3030
import subprocess
3131
import sys
3232
import re
33-
import xml.dom.minidom as xml
3433
import functools
34+
import json
35+
36+
# Try to get the security-patched XML functions from defusedxml
37+
try:
38+
from defusedxml import minidom as xml
39+
except ImportError:
40+
from xml.dom import minidom as xml
3541

3642
from PyQt5.QtCore import QSize, Qt, QEvent, QObject, QThread, pyqtSlot, pyqtSignal, QMetaObject, Q_ARG, QTimer
3743
from PyQt5.QtGui import *
@@ -44,8 +50,6 @@
4450
from classes.app import get_app
4551
from windows.models.blender_model import BlenderModel
4652

47-
import json
48-
4953

5054
class BlenderListView(QListView):
5155
""" A TreeView QWidget used on the animated title window """

0 commit comments

Comments
 (0)