[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#959231: security-tracker: Proxy Error on CVE-2020-11565 tracker page



* Florian Weimer:

> * Francesco Poli:
>
>> Please note that the CVE is mentioned in [DSA-4667-1].
>>
>> [DSA-4667-1]: <https://lists.debian.org/debian-security-announce/2020/msg00071.html>
>>
>> What's wrong with that tracker page?
>
> It's something in the NVD data that breaks the HTML escaping.

This patch adds basic Unicode support to the web framework.  I'm not
sure if it is the right direction to move in, but it fixes the issue.

An alternative fix would be to change the NVD importer not to put
Unicode strings into the database, by encoding them as byte strings
first.

diff --git a/lib/python/web_support.py b/lib/python/web_support.py
index 5752f34b5f..116cbec2be 100644
--- a/lib/python/web_support.py
+++ b/lib/python/web_support.py
@@ -220,27 +220,25 @@ class URLFactory:
     def updateParams(self, **args):
         self.updateParamsDict(args)
 
-charToHTML = map(chr, range(256))
-charToHTMLattr = map(chr, range(256))
-def _initStringToHTML(s):
-    for (ch, repl) in (('<', '&lt;'),
-                       ('>', '&gt;'),
-                       ('&', '&amp;')):
-        s[ord(ch)] = repl
-_initStringToHTML(charToHTML)
-_initStringToHTML(charToHTMLattr)
-charToHTMLattr[ord('"')] = '&34;'
-del _initStringToHTML
+charToHTML = {
+    '<' : '&lt;',
+    '>' : '&gt;',
+    '&' : '&amp;',
+}
+charToHTMLattr = {
+    '&' : '&amp;',
+    '"' : '&34;',
+}
 
 def escapeHTML(str):
-    '''Replaces the characters <>&" in the passed strings with their
+    '''Replaces the characters <>& in the passed strings with their
     HTML entities.'''
+    return ''.join([charToHTML.get(ch, ch) for ch in str])
 
-    result = []
-    append = result.append
-    for ch in str:
-        append(charToHTML[ord(ch)])
-    return ''.join(result)
+def escapeHTMLattr(str):
+    '''Replaces the characters &" in the passed strings with their
+    HTML entities.'''
+    return ''.join([charToHTMLattr.get(ch, ch) for ch in str])
 
 class HTMLBase:
     def flatten(self, write):
@@ -310,8 +308,7 @@ class Tag(HTMLBase):
             else:
                 append(key)
             append('="')
-            for ch in str(value):
-                append(charToHTMLattr[ord(ch)])
+            append(escapeHTMLattr(str(value)))
             append('"')
         self.__attribs = ''.join(attrs)
         self.contents = contents
@@ -659,7 +656,12 @@ class HTMLResult(Result):
         buf = cStringIO.StringIO()
         buf.write(self.doctype)
         buf.write('\n')
-        self.contents.flatten(buf.write)
+        def write_both(s):
+            if type(s) == types.UnicodeType:
+                buf.write(s.encode('UTF-8'))
+            else:
+                buf.write(s)
+        self.contents.flatten(write_both)
         buf = buf.getvalue()
         self.headers['Content-Length'] = str(len(buf))
         def later(req):


Reply to: