Skip to content

Commit 1e82941

Browse files
committed
merge code changes from fork
2 parents 557fd69 + 30691d8 commit 1e82941

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

roundup/cgi/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ def handle_csrf(self, xmlrpc=False):
11451145
state on the server (one nonce per form per
11461146
page). If you have multiple forms/page this can
11471147
lead to abandoned csrf tokens that have to time
1148-
out and get cleaned up.But you lose per form
1148+
out and get cleaned up. But you lose per form
11491149
tokens which may be an advantage. Also the HMAC
11501150
is constant for the session, so provides more
11511151
occasions for it to be exposed.
@@ -1157,7 +1157,7 @@ def handle_csrf(self, xmlrpc=False):
11571157
A session token lifetime is settable in
11581158
config.ini. A future enhancement to the
11591159
creation routines should allow for the requester
1160-
of the token to set the lifetime.t
1160+
of the token to set the lifetime.
11611161
11621162
The unique session key and user id is stored
11631163
with the token. The token is valid if the stored
@@ -1187,7 +1187,7 @@ def handle_csrf(self, xmlrpc=False):
11871187

11881188
# Assume: never allow changes via GET
11891189
if self.env['REQUEST_METHOD'] not in ['POST', 'PUT', 'DELETE']:
1190-
if "@csrf" in self.form:
1190+
if (self.form.list is not None) and ("@csrf" in self.form):
11911191
# We have a nonce being used with a method it should
11921192
# not be. If the nonce exists, report to admin so they
11931193
# can fix the nonce leakage and destroy it. (nonces

roundup/cgi/templating.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,16 @@ def history(self, direction='descending', dre=re.compile(r'^\d+$'),
11531153

11541154
arg_s = '<br />'.join(cell)
11551155
else:
1156-
# unkown event!!
1157-
comments['unknown'] = self._(
1158-
"<strong><em>This event is not handled"
1159-
" by the history display!</em></strong>")
1160-
arg_s = '<strong><em>' + str(args) + '</em></strong>'
1156+
if action in ( 'retired', 'restored' ):
1157+
# args = None for these actions
1158+
pass
1159+
else:
1160+
# unknown event!!
1161+
comments['unknown'] = self._(
1162+
"<strong><em>This event %s is not handled"
1163+
" by the history display!</em></strong>"%action)
1164+
arg_s = '<strong><em>' + str(args) + '</em></strong>'
1165+
11611166
date_s = date_s.replace(' ', '&nbsp;')
11621167
# if the user's an itemid, figure the username (older journals
11631168
# have the username)

roundup/cgi/wsgi_handler.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
from roundup.cgi import TranslationService
1515
from roundup.anypy import http_
1616
from roundup.anypy.strings import s2b, bs2b
17+
18+
from roundup.cgi.client import BinaryFieldStorage
19+
1720
BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler
1821
DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE
1922

@@ -69,21 +72,33 @@ def __call__(self, environ, start_response):
6972
request.headers = Headers(environ)
7073

7174
if environ ['REQUEST_METHOD'] == 'OPTIONS':
72-
code = 501
73-
message, explain = BaseHTTPRequestHandler.responses[code]
74-
request.start_response([('Content-Type', 'text/html'),
75-
('Connection', 'close')], code)
76-
request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals()))
77-
return []
78-
75+
if environ["PATH_INFO"][:5] == "/rest":
76+
# rest does support options
77+
# This I hope will result in self.form=None
78+
environ['CONTENT_LENGTH'] = 0
79+
else:
80+
code = 501
81+
message, explain = BaseHTTPRequestHandler.responses[code]
82+
request.start_response([('Content-Type', 'text/html'),
83+
('Connection', 'close')], code)
84+
request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals()))
85+
return []
86+
7987
tracker = roundup.instance.open(self.home, not self.debug)
8088

8189
# need to strip the leading '/'
8290
environ["PATH_INFO"] = environ["PATH_INFO"][1:]
8391
if request.timing:
8492
environ["CGI_SHOW_TIMING"] = request.timing
8593

86-
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
94+
form = BinaryFieldStorage(fp=environ['wsgi.input'], environ=environ)
95+
96+
if environ ['REQUEST_METHOD'] in ("OPTIONS", "DELETE"):
97+
# these methods have no data. When we init tracker.Client
98+
# set form to None and request.rfile to None to get a
99+
# properly initialized empty form.
100+
form = None
101+
request.rfile = None
87102

88103
client = tracker.Client(tracker, request, environ, form,
89104
request.translator)

0 commit comments

Comments
 (0)