Skip to content

Commit 3ac42f9

Browse files
committed
Fix HTML markup in Flash messages
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 8728606 commit 3ac42f9

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

scripts/auth.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from decorator import decorator
44
import pwd, os
55
import re
6+
import cgi
67

78
import webob.exc
89

@@ -14,9 +15,8 @@
1415
def html(s):
1516
return '<html>'+s
1617
# Monkeypatch to prevent webflash from escaping HTML conditionally
17-
import webflash
18-
html_escape = webflash.html_escape
19-
webflash.html_escape = lambda s: s[len('<html>'):] if s.startswith('<html>') else html_escape(s)
18+
import sys, tg.flash
19+
sys.modules['tg.flash'].escape = lambda s: s[len('<html>'):] if s.startswith('<html>') else cgi.escape(s)
2020

2121
def current_user():
2222
return getattr(state,'username',None)
@@ -70,7 +70,7 @@ def validate_locker(locker,team_ok=False,sudo_ok=False):
7070
try:
7171
pwd.getpwnam(locker)
7272
except KeyError:
73-
raise AuthError(html("""The '%s' locker is not signed up for scripts.mit.edu; <a href="http://scripts.mit.edu/web/">sign it up</a> first."""%locker))
73+
raise AuthError(html("""The '%s' locker is not signed up for scripts.mit.edu; <a href="http://scripts.mit.edu/web/">sign it up</a> first."""%cgi.escape(locker)))
7474
if ((not team_ok or not on_scripts_team())
7575
and (not sudo_ok or not getattr(state,'sudo',False))
7676
and not can_admin(locker)):

scriptspony/vhosts.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import random
88
import string
99
from decorator import decorator
10+
import cgi
1011

1112
import tg
1213

@@ -253,12 +254,12 @@ def validate_hostname(hostname,locker):
253254
connection.close()
254255
if status.status != httplib.OK:
255256
raise UserError(auth.html("'%s' does not point at scripts-vhosts. If you want to continue anyway, please create a file called '%s' in the root directory of the site. See <a href='http://scripts.mit.edu/faq/132/can-i-add-a-vhost-before-i-point-my-domain-at-scripts' target='_blank'>the FAQ</a> for more information."
256-
% (hostname,check_file)))
257+
% (cgi.escape(hostname),cgi.escape(check_file))))
257258
except socket.gaierror:
258259
raise UserError("'%s' does not exist." % hostname)
259260
except (httplib.HTTPException, socket.error):
260261
raise UserError(auth.html("'%s' does not point at scripts-vhosts, and appears to have no running webserver. Please see <a href='http://scripts.mit.edu/faq/132/can-i-add-a-vhost-before-i-point-my-domain-at-scripts' target='_blank'>the FAQ</a> for more information."
261-
% hostname))
262+
% cgi.escape(hostname)))
262263

263264
return hostname,reqtype
264265

0 commit comments

Comments
 (0)