Opened at 2022-02-19T01:19:33Z
Closed at 2022-12-02T15:28:53Z
#3874 closed defect (fixed)
Incorrect encode in allmydata.testing.web._FakeTahoeUriHandler.render_GET
Reported by: | exarkun | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | undecided |
Component: | unknown | Version: | n/a |
Keywords: | Cc: | ||
Launchpad Bug: |
Description
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.
Change History (2)
comment:1 Changed at 2022-11-29T15:53:07Z by exarkun
comment:2 Changed at 2022-12-02T15:28:53Z by exarkun
- Resolution set to fixed
- Status changed from new to closed
https://github.com/tahoe-lafs/tahoe-lafs/pull/1233