Skip to content

Commit

Permalink
added whitelist handler to correct any data incorrectly sanitized bef…
Browse files Browse the repository at this point in the history
…ore whitelist in place.
  • Loading branch information
Matthew Mulholland committed Sep 27, 2018
1 parent ed2d2f1 commit 16b8653
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions config/src/main/config/home/restore/redboxMigration1.9.py
Expand Up @@ -10,6 +10,7 @@
from org.apache.commons.lang import StringUtils
from org.joda.time import DateTime, DateTimeZone
from com.googlecode.fascinator.portal.services import OwaspSanitizer
from java.util import Arrays, Collections


class MigrateData:
Expand Down Expand Up @@ -55,6 +56,8 @@ def __activate__(self, bindings):
# add new keys if not present
self.injectFreshKeys()

self.handleOwaspWhitelist()

# # save the package data...
self.__savePackageData()

Expand Down Expand Up @@ -117,10 +120,10 @@ def setDescriptionShadow(self):
## no tags are added to wysiwyg until user interacts with wysiwyg editor
unescapedDescription = ""
escapedDescription = ""
rawDescription = StringUtils.defaultString(deprecated_description)
rawDescription = StringUtils.defaultString("%s" % deprecated_description)
## sanitize the incoming description
self.log.debug("raw deprecated description is: %s" % rawDescription)
sanitizedDescription = OwaspSanitizer.sanitizeHtml(rawDescription)
sanitizedDescription = OwaspSanitizer.sanitizeHtml("dc:description.1.text", rawDescription)
if (sanitizedDescription):
# not completely accurate for checking for tags but ensures a style consistent with wysiwyg editor
if re.search("^<p>.*</p>|^&lt;p&gt;.*&lt;\/p&gt;", sanitizedDescription):
Expand Down Expand Up @@ -185,6 +188,19 @@ def injectFreshKeys(self):
else:
self.log.info("skipping fresh key: %s as it already exists" % freshKey)

def handleOwaspWhitelist(self):
whitelist = OwaspSanitizer.whitelist
self.log.debug("have whitelist: %s" % whitelist.toString())
for field in whitelist.toArray():
value = self.getPackageJson().get(field)
if value:
unescaped = StringEscapeUtils.unescapeHtml("%s" % value)
self.log.debug("Unescaped field: %s from: %s to: %s" % (field, value, unescaped))
if unescaped:
self.getPackageJson().put(field, unescaped)
else:
self.log.warning("Failed to unescape field: %s from: %s" % (field, value))

def getPackageJson(self):
return self.packageData.getJsonObject()

Expand Down

0 comments on commit 16b8653

Please sign in to comment.