diff --git a/cms/startup.py b/cms/startup.py
index 86586e8f7c1cf031cdfe076143a832dc495ee646..815b03ecea99a6c277c0ae1ac75f4cafa6bd88aa 100644
--- a/cms/startup.py
+++ b/cms/startup.py
@@ -15,10 +15,6 @@ def run():
     """
     Executed during django startup
     """
-    # Patch the xml libs.
-    from safe_lxml import defuse_xml_libs
-    defuse_xml_libs()
-
     django_utils_translation.patch()
 
     autostartup()
diff --git a/cms/wsgi.py b/cms/wsgi.py
index 70dba18d7ff942c3b5909f3acbeb86982b1453d8..199d3939eea7158c0520a28899ded64bab472a36 100644
--- a/cms/wsgi.py
+++ b/cms/wsgi.py
@@ -1,3 +1,7 @@
+# Patch the xml libs before anything else.
+from safe_lxml import defuse_xml_libs
+defuse_xml_libs()
+
 # Disable PyContract contract checking when running as a webserver
 import contracts
 contracts.disable_all()
diff --git a/lms/startup.py b/lms/startup.py
index 5d789c51461211c031e58cbb2d1f693a0d0a826a..bb6b312a5090bcd1c0f73c8ffb17941c15399002 100644
--- a/lms/startup.py
+++ b/lms/startup.py
@@ -20,11 +20,6 @@ def run():
     """
     Executed during django startup
     """
-
-    # Patch the xml libs.
-    from safe_lxml import defuse_xml_libs
-    defuse_xml_libs()
-
     django_utils_translation.patch()
 
     autostartup()
diff --git a/lms/wsgi.py b/lms/wsgi.py
index 4fe5b0b79f2a4be4afea3999331890a281c808e1..1f7a0e37c7b7bd914920db83478649060d6eb36e 100644
--- a/lms/wsgi.py
+++ b/lms/wsgi.py
@@ -1,3 +1,7 @@
+# Patch the xml libs
+from safe_lxml import defuse_xml_libs
+defuse_xml_libs()
+
 # Disable PyContract contract checking when running as a webserver
 import contracts
 contracts.disable_all()
diff --git a/lms/wsgi_apache_lms.py b/lms/wsgi_apache_lms.py
index 41c3317e14819dee5d3a87f7e1a394254f56d055..c69bb5f49842663f4fb1743f85cbc6fe88ab0443 100644
--- a/lms/wsgi_apache_lms.py
+++ b/lms/wsgi_apache_lms.py
@@ -1,3 +1,7 @@
+# Patch the xml libs before anything else.
+from safe_lxml import defuse_xml_libs
+defuse_xml_libs()
+
 import os
 
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.envs.aws")
diff --git a/manage.py b/manage.py
index a5c6e5fb2ba99015d6c3c5103c18a5b9fd496a0c..ce48d914eee5b2afa58be0d3da648f9285c76592 100755
--- a/manage.py
+++ b/manage.py
@@ -11,6 +11,10 @@ by passing the --settings flag, you can specify what environment specific settin
 Any arguments not understood by this manage.py will be passed to django-admin.py
 """
 
+# Patch the xml libs before anything else.
+from safe_lxml import defuse_xml_libs
+defuse_xml_libs()
+
 import os
 import sys
 import importlib