File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## Unreleased
9
9
10
+ ### Fixed
11
+
12
+ - Fixed not escaping the URL string when generating HTML responses to hURL: requests.
13
+
10
14
## v3.0.0 (2022-11-25)
11
15
12
16
### Added
Original file line number Diff line number Diff line change
1
+ import html
1
2
import re
2
3
3
4
from pygopherd import gopherentry , handlers
@@ -42,6 +43,9 @@ def write(self, wfile):
42
43
url = self .selector [4 :] # Strip off URL:
43
44
if self .selector [0 ] == "/" :
44
45
url = self .selector [5 :]
46
+
47
+ url = html .escape (url )
48
+
45
49
outdoc = "<HTML><HEAD>\n "
46
50
outdoc += '<META HTTP-EQUIV="refresh" content="5;URL=%s">' % url
47
51
outdoc += "</HEAD><BODY>\n "
@@ -77,7 +81,6 @@ def canhandlerequest(self):
77
81
)
78
82
79
83
def gethandler (self ):
80
-
81
84
handlers .HandlerMultiplexer .init_default_handlers (self .config )
82
85
handlerlist = [
83
86
x for x in handlers .HandlerMultiplexer .handlers if x != URLTypeRewriter
Original file line number Diff line number Diff line change @@ -38,6 +38,30 @@ def test_url_rewriter_handler(self):
38
38
b'<A HREF="http://gopher.quux.org/">http://gopher.quux.org/</A>' , out
39
39
)
40
40
41
+ def test_handler_escape_urls (self ):
42
+ """
43
+ URLs should be escaped in the generated HTML.
44
+ """
45
+ handler = HTMLURLHandler (
46
+ 'URL:http://gopher.quux.org/"<script>' ,
47
+ "" ,
48
+ self .protocol ,
49
+ self .config ,
50
+ self .stat_result ,
51
+ self .vfs ,
52
+ )
53
+
54
+ entry = handler .getentry ()
55
+ self .assertEqual (entry .mimetype , "text/html" )
56
+ self .assertEqual (entry .type , "h" )
57
+
58
+ wfile = io .BytesIO ()
59
+ handler .write (wfile )
60
+
61
+ out = wfile .getvalue ()
62
+ self .assertNotIn (b'http://gopher.quux.org/"<script>' , out )
63
+ self .assertIn (b"http://gopher.quux.org/"<script>" , out )
64
+
41
65
42
66
class TestURLTypeRewriterHandler (unittest .TestCase ):
43
67
def setUp (self ):
You can’t perform that action at this time.
0 commit comments