Skip to content

Commit 7299214

Browse files
committed
feat: issue2551372 - REST-API CSRF protection should document mandatory Origin header
Logging is more useful I hope. Logs the name of the user making the request. Logs the value of the origin header if the value is not authorized to use the rest interface. Added a comment about difficulty include originating IP address in log.
1 parent 3d2fecd commit 7299214

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

roundup/cgi/client.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,10 @@ def handle_rest(self):
726726
if not self.is_origin_header_ok(api=True):
727727
if 'HTTP_ORIGIN' not in self.env:
728728
msg = self._("Required Header Missing")
729-
err = 'Origin header missing'
729+
err = "REST request missing 'Origin' header by user %(user)s."
730730
else:
731731
msg = self._("Client is not allowed to use Rest Interface.")
732-
err = 'Unauthorized for REST request'
732+
err = "REST request 'Origin' (%(origin)s) unauthorized by user %(user)s."
733733

734734
# Use code 400. Codes 401 and 403 imply that authentication
735735
# is needed or authenticated person is not authorized.
@@ -739,7 +739,18 @@ def handle_rest(self):
739739
self.reject_request(output,
740740
message_type="application/json",
741741
status=400)
742-
logger.error(err)
742+
# Would be nice to log the original source address here to
743+
# allow firewalling in case of abuse/attack. Especially if
744+
# anonymous is allowed REST access. However,
745+
# self.request.connection.getpeername()
746+
# only gets us 127.0.0.1 when a proxy is used. I think the
747+
# same is true of wsgi mode (but it might be a UNIX domain
748+
# socket address). The upstream server needs to supply the
749+
# real IP as it sees it and we need to consume it. There
750+
# is no method for this that handles all the ways roundup
751+
# can be run AFAIK. So no IP address, just user.
752+
logger.error(err, {"user": self.user,
753+
"origin": self.env.get('HTTP_ORIGIN', None)})
743754
return
744755

745756
# Handle CORS preflight request. We know rest is enabled

0 commit comments

Comments
 (0)