Skip to content

Commit 657c66d

Browse files
committed
Do not honor the X-HTTP-Method-Override if the original method used
was GET. GET's are supposed to be a safe operation. Require a non-GET method (POST is suggested) in order for the override to occur.
1 parent 189296f commit 657c66d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

roundup/rest.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
basestring = str
3333
unicode = str
3434

35+
import logging
36+
logger = logging.getLogger('roundup.rest')
37+
3538
def _data_decorator(func):
3639
"""Wrap the returned data into an object."""
3740
def format_object(self, *args, **kwargs):
@@ -1110,7 +1113,21 @@ def dispatch(self, method, uri, input):
11101113
"""format and process the request"""
11111114
# if X-HTTP-Method-Override is set, follow the override method
11121115
headers = self.client.request.headers
1113-
method = headers.getheader('X-HTTP-Method-Override') or method
1116+
# Never allow GET to be an unsafe operation (i.e. data changing).
1117+
# User must use POST to "tunnel" DELETE, PUT, OPTIONS etc.
1118+
override = headers.getheader('X-HTTP-Method-Override')
1119+
output = None
1120+
if override:
1121+
if method.upper() != 'GET':
1122+
logger.debug(
1123+
'Method overridden from %s to %s', method, override)
1124+
method = override
1125+
else:
1126+
output = self.error_obj(400,
1127+
"X-HTTP-Method-Override: %s can not be used with GET method. Use Post instead." % override)
1128+
logger.info(
1129+
'Ignoring X-HTTP-Method-Override for GET request on %s',
1130+
uri)
11141131

11151132
# parse Accept header and get the content type
11161133
accept_header = parse_accept_header(headers.getheader('Accept'))
@@ -1154,7 +1171,10 @@ def dispatch(self, method, uri, input):
11541171

11551172
# Call the appropriate method
11561173
try:
1157-
output = Routing.execute(self, uri, method, input)
1174+
# If output was defined by a prior error
1175+
# condition skip call
1176+
if not output:
1177+
output = Routing.execute(self, uri, method, input)
11581178
except NotFound as msg:
11591179
output = self.error_obj(404, msg)
11601180
except Reject as msg:

0 commit comments

Comments
 (0)