~ubuntu-branches/ubuntu/precise/trac/precise

« back to all changes in this revision

Viewing changes to debian/patches/17_SA32652.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): W. Martin Borgert
  • Date: 2009-09-15 21:43:38 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20090915214338-q3ecy6qxwxfzf9y8
Tags: 0.11.5-2
* Set exec bit for *_frontends (Closes: #510441), thanks to Torsten
  Landschoff for the patch.
* Move python-psycopg2 and python-mysql from Suggests to Depends as
  alternative to python-psqlite2 (Closes: #513117).
* Use debhelper 7 (Closes: #497862).
* Don't compress *-hook files and don't install MS-Windows *.cmd
  files (Closes: #526142), thanks to Jan Dittberner for the patch.
* Add README.source to point to dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh /usr/share/dpatch/dpatch-run
2
 
## 17_SA32652.dpatch by Giuseppe Iuculano <giuseppe@iuculano.it>
3
 
##
4
 
## All lines beginning with `## DP:' are a description of the patch.
5
 
## DP: Backported patch to fix SA32652
6
 
 
7
 
@DPATCH@
8
 
diff -urNad trac-0.11.1~/trac/util/html.py trac-0.11.1/trac/util/html.py
9
 
--- trac-0.11.1~/trac/util/html.py      2008-08-07 03:00:20.000000000 +0200
10
 
+++ trac-0.11.1/trac/util/html.py       2008-11-16 18:22:50.000000000 +0100
11
 
@@ -14,10 +14,74 @@
12
 
 import re
13
 
 
14
 
 from genshi import Markup, escape, unescape
15
 
-from genshi.core import stripentities, striptags
16
 
+from genshi.core import stripentities, striptags, START, END
17
 
 from genshi.builder import Element, ElementFactory, Fragment
18
 
+from genshi.filters.html import HTMLSanitizer
19
 
 
20
 
-__all__ = ['escape', 'unescape', 'html', 'plaintext']
21
 
+__all__ = ['escape', 'unescape', 'html', 'plaintext', 'TracHTMLSanitizer']
22
 
+
23
 
+
24
 
+class TracHTMLSanitizer(HTMLSanitizer):
25
 
+
26
 
+    UNSAFE_CSS = ['position']
27
 
+
28
 
+    def __init__(self):
29
 
+        safe_attrs = HTMLSanitizer.SAFE_ATTRS | set(['style'])
30
 
+        super(TracHTMLSanitizer, self).__init__(safe_attrs=safe_attrs)
31
 
+
32
 
+    def sanitize_css(self, text):
33
 
+        decls = []
34
 
+        text = self._strip_css_comments(self._replace_unicode_escapes(text))
35
 
+        for decl in filter(None, text.split(';')):
36
 
+            decl = decl.strip()
37
 
+            if not decl:
38
 
+                continue
39
 
+            try:
40
 
+                prop, value = decl.split(':', 1)
41
 
+            except ValueError:
42
 
+                continue
43
 
+            if not self.is_safe_css(prop.strip().lower(), value.strip()):
44
 
+                continue
45
 
+            is_evil = False
46
 
+            if 'expression' in decl:
47
 
+                is_evil = True
48
 
+            for match in re.finditer(r'url\s*\(([^)]+)', decl):
49
 
+                if not self.is_safe_uri(match.group(1)):
50
 
+                    is_evil = True
51
 
+                    break
52
 
+            if not is_evil:
53
 
+                decls.append(decl.strip())
54
 
+        return decls
55
 
+
56
 
+    def __call__(self, stream):
57
 
+        """Remove input type="password" elements from the stream
58
 
+        """
59
 
+        suppress = False
60
 
+        for kind, data, pos in super(TracHTMLSanitizer, self).__call__(stream):
61
 
+            if kind is START:
62
 
+                tag, attrs = data
63
 
+                if (tag == 'input' and
64
 
+                    attrs.get('type', '').lower() == 'password'):
65
 
+                    suppress = True
66
 
+                else:
67
 
+                    yield kind, data, pos
68
 
+            elif kind is END:
69
 
+                if not suppress:
70
 
+                    yield kind, data, pos
71
 
+                suppress = False
72
 
+            else:
73
 
+                yield kind, data, pos
74
 
+
75
 
+    def is_safe_css(self, prop, value):
76
 
+        """Determine whether the given css property declaration is to be 
77
 
+        considered safe for inclusion in the output.
78
 
+        """
79
 
+        if prop in self.UNSAFE_CSS:
80
 
+            return False
81
 
+        # Negative margins can be used for phishing
82
 
+        elif prop.startswith('margin') and '-' in value:
83
 
+            return False
84
 
+        return True
85
 
 
86
 
 
87
 
 class Deuglifier(object):
88
 
diff -urNad trac-0.11.1~/trac/wiki/formatter.py trac-0.11.1/trac/wiki/formatter.py
89
 
--- trac-0.11.1~/trac/wiki/formatter.py 2008-08-07 03:00:20.000000000 +0200
90
 
+++ trac-0.11.1/trac/wiki/formatter.py  2008-11-16 18:22:50.000000000 +0100
91
 
@@ -26,7 +26,6 @@
92
 
 
93
 
 from genshi.builder import tag, Element
94
 
 from genshi.core import Stream, Markup, escape
95
 
-from genshi.filters import HTMLSanitizer
96
 
 from genshi.input import HTMLParser, ParseError
97
 
 from genshi.util import plaintext
98
 
 
99
 
@@ -38,6 +37,7 @@
100
 
 from trac.wiki.parser import WikiParser
101
 
 from trac.util.text import shorten_line, to_unicode, \
102
 
                            unicode_quote, unicode_quote_plus
103
 
+from trac.util.html import TracHTMLSanitizer
104
 
 from trac.util.translation import _
105
 
 
106
 
 __all__ = ['wiki_to_html', 'wiki_to_oneliner', 'wiki_to_outline',
107
 
@@ -86,8 +86,7 @@
108
 
                               'span': self._span_processor,
109
 
                               'Span': self._span_processor}
110
 
 
111
 
-        self._sanitizer = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS |
112
 
-                                        set(['style']))
113
 
+        self._sanitizer = TracHTMLSanitizer()
114
 
         
115
 
         self.processor = builtin_processors.get(name)
116
 
         if not self.processor:
117
 
diff -urNad trac-0.11.1~/trac/wiki/parser.py trac-0.11.1/trac/wiki/parser.py
118
 
--- trac-0.11.1~/trac/wiki/parser.py    2008-08-07 03:00:20.000000000 +0200
119
 
+++ trac-0.11.1/trac/wiki/parser.py     2008-11-16 18:23:51.000000000 +0100
120
 
@@ -98,9 +98,10 @@
121
 
         #  * list
122
 
         r"(?P<list>^(?P<ldepth>\s+)(?:[-*]|\d+\.|[a-zA-Z]\.|[ivxIVX]{1,5}\.) )",
123
 
         # definition:: 
124
 
-        r"(?P<definition>^\s+((?:%s[^%s]*%s|%s.*?%s|[^%s%s:]|:[^:])+::)(?:\s+|$))"
125
 
+        r"(?P<definition>^\s+((?:%s[^%s]*%s|%s(?:%s{,2}[^%s])*?%s|[^%s%s:]|:[^:])+::)(?:\s+|$))"
126
 
         % (INLINE_TOKEN, INLINE_TOKEN, INLINE_TOKEN,
127
 
-           STARTBLOCK_TOKEN, ENDBLOCK_TOKEN, INLINE_TOKEN, STARTBLOCK[0]),
128
 
+           STARTBLOCK_TOKEN, ENDBLOCK[0], ENDBLOCK[0], ENDBLOCK_TOKEN,
129
 
+           INLINE_TOKEN, STARTBLOCK[0]),
130
 
         # (leading space)
131
 
         r"(?P<indent>^(?P<idepth>\s+)(?=\S))",
132
 
         # || table ||
133
 
diff -urNad trac-0.11.1~/trac/wiki/tests/wiki-tests.txt trac-0.11.1/trac/wiki/tests/wiki-tests.txt
134
 
--- trac-0.11.1~/trac/wiki/tests/wiki-tests.txt 2008-08-07 03:00:20.000000000 +0200
135
 
+++ trac-0.11.1/trac/wiki/tests/wiki-tests.txt  2008-11-16 18:23:51.000000000 +0100
136
 
@@ -1034,6 +1034,16 @@
137
 
 </blockquote>
138
 
 ------------------------------
139
 
 term::definition
140
 
+============================== Pathological definition list counter example with block quotes
141
 
+ {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}} {{{a}}}
142
 
+------------------------------
143
 
+<blockquote>
144
 
+<p>
145
 
+<tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt>
146
 
+</p>
147
 
+</blockquote>
148
 
+------------------------------
149
 
+<tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt> <tt>a</tt>
150
 
 ============================== Definition list + escaped definition list
151
 
  complex topic:: multiline
152
 
                  `not:: a dl`