hgweb: only recognize wire protocol commands from query string (BC)
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 08 Mar 2018 11:33:33 -0800
changeset 36818 886fba199022
parent 36817 3c15b84ab66c
child 36819 cfb9ef24968c
hgweb: only recognize wire protocol commands from query string (BC) Previously, we attempted to parse the wire protocol command from `req.form`. Data could have come from the query string or POST form data. The wire protocol states that the command must be declared in the query string. And AFAICT all Mercurial releases from at least 1.0 send the command in the query string. So let's actual require this behavior. This is technically BC. But I'm not sure how anyone in the wild would encounter this. POST has historically been used for sending bundle data. So there's no opportunity to encode arguments there. And the experimental HTTP POST args also takes over the body. So the only way someone would be impacted by this is if they wrote a custom client that both used POST for everything and sent arguments via the HTTP body. I don't believe such a client exists. .. bc:: The HTTP wire protocol server no longer accepts the ``cmd`` argument to control which command to run via HTTP POST bodies. The ``cmd`` argument must be specified on the URL query string. Differential Revision: https://phab.mercurial-scm.org/D2738
mercurial/hgweb/hgweb_mod.py
mercurial/wireprotoserver.py
--- a/mercurial/hgweb/hgweb_mod.py	Thu Mar 08 11:21:46 2018 -0800
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Mar 08 11:33:33 2018 -0800
@@ -330,7 +330,7 @@
 
         # Route it to a wire protocol handler if it looks like a wire protocol
         # request.
-        protohandler = wireprotoserver.parsehttprequest(rctx, wsgireq, query,
+        protohandler = wireprotoserver.parsehttprequest(rctx, wsgireq, req,
                                                         self.check_perm)
 
         if protohandler:
--- a/mercurial/wireprotoserver.py	Thu Mar 08 11:21:46 2018 -0800
+++ b/mercurial/wireprotoserver.py	Thu Mar 08 11:33:33 2018 -0800
@@ -150,7 +150,7 @@
 def iscmd(cmd):
     return cmd in wireproto.commands
 
-def parsehttprequest(rctx, wsgireq, query, checkperm):
+def parsehttprequest(rctx, wsgireq, req, checkperm):
     """Parse the HTTP request for a wire protocol request.
 
     If the current request appears to be a wire protocol request, this
@@ -159,16 +159,17 @@
     request. Otherwise, ``None`` is returned.
 
     ``wsgireq`` is a ``wsgirequest`` instance.
+    ``req`` is a ``parsedrequest`` instance.
     """
     repo = rctx.repo
 
     # HTTP version 1 wire protocol requests are denoted by a "cmd" query
     # string parameter. If it isn't present, this isn't a wire protocol
     # request.
-    if 'cmd' not in wsgireq.form:
+    if 'cmd' not in req.querystringdict:
         return None
 
-    cmd = wsgireq.form['cmd'][0]
+    cmd = req.querystringdict['cmd'][0]
 
     # The "cmd" request parameter is used by both the wire protocol and hgweb.
     # While not all wire protocol commands are available for all transports,