[tahoe-lafs-trac-stream] [Tahoe-LAFS] #3874: Incorrect encode in allmydata.testing.web._FakeTahoeUriHandler.render_GET
Tahoe-LAFS
trac at tahoe-lafs.org
Sat Feb 19 01:19:33 UTC 2022
#3874: Incorrect encode in allmydata.testing.web._FakeTahoeUriHandler.render_GET
---------------------+---------------------------
Reporter: exarkun | Owner:
Type: defect | Status: new
Priority: normal | Milestone: undecided
Component: unknown | Version: n/a
Keywords: | Launchpad Bug:
---------------------+---------------------------
`render_GET` does:
{{{
for arg, value in uri.query:
if arg == u"uri":
capability = value
# it's legal to use the form "/uri/<capability>"
if capability is None and request.postpath and
request.postpath[0]:
capability = request.postpath[0]
# if we don't yet have a capability, that's an error
if capability is None:
request.setResponseCode(http.BAD_REQUEST)
return b"GET /uri requires uri="
# the user gave us a capability; if our Grid doesn't have any
# data for it, that's an error.
capability = capability.encode('ascii')
}}}
So it reads `capability` from either a DecodedURL's `query` attribute or
from `request.postpath[0]`. `DecodedURL.query` is certainly a str.
`request.postpath` comes from `twisted.web.server.Request.process`:
{{{
self.postpath = list(map(unquote, self.path[1:].split(b'/')))
}}}
`self.path` must be `bytes` since it is being split with `bytes` but it
comes from `twisted.web.http.Request.requestReceived`:
{{{
x = self.uri.split(b'?', 1)
if len(x) == 1:
self.path = self.uri
else:
self.path, argstring = x
self.args = parse_qs(argstring, 1)
}}}
`requestReceived` also documents `path` as `bytes` and then derives
`self.uri` from it so ... probably bytes.
Thus, in Tahoe, `capability` is either str or bytes depending on which
codepath finds it. And if it is bytes then `.encode('ascii')` fails.
which seems to confirm that it is bytes.
--
Ticket URL: <https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3874>
Tahoe-LAFS <https://Tahoe-LAFS.org>
secure decentralized storage
More information about the tahoe-lafs-trac-stream
mailing list