Opened 8 years ago

Closed 8 years ago

#4782 defect closed duplicate (duplicate)

request.redirect(someUnicode) infects the whole http response with unicode

Reported by: drewp Owned by:
Priority: normal Milestone:
Component: web Keywords:
Cc: msabramo Branch:


I'm on twisted 10.1.0, using nevow too. In a rend.Page.renderHTTP method, I do this (accidentally):


The response looks like this (curl + strace):

recvfrom(3, "HTTP/1.0 200 OK\r\nDate: Sun, 26 Dec 2010 08:57:21 GMT\r\nX-Transformed-From: HTTP/0.9\r\nX-Cache: MISS from localhost\r\nX-Cache-Lookup: MISS from localhost:3128\r\nVia: 1.0 localhost (squid/3.0.STABLE19)\r\nProxy-Connection: close\r\n\r\nH\0\0\0T\0\0\0T\0\0\0P\0\0\0/\0\0\0001\0\0\0.\0\0\0000\0\0\0 \0\0\0003\0\0\0000\0\0\0002\0\0\0 \0\0\0F\0\0\0o\0\0\0u\0\0\0n\0\0\0d\0\0\0\r\0\0\0\n\0\0\0D\0\0\0a\0\0\0t\0\0\0e\0\0\0:\0\0\0 \0\0\0S\0\0\0u\0\0\0n\0\0\0,\0\0\0 \0\0\0002\0\0\0006\0\0\0 \0\0\0D\0\0\0e\0\0\0c\0\0\0 \0\0\0002\0\0\0000\0\0\0001\0\0\0000\0\0\0 \0\0\0000\0\0\0008\0\0\0:\0\0\0005\0\0\0007\0\0\0:\0\0\0002\0\0\0001\0\0\0 \0\0\0G\...

An HTTP response has been rendered into some kind of 32-bit encoding and included as the response content. Maybe my squid cache completely invented the outer part because the other response was so corrupt.

Changing my code to call redirect() with str only has fixed my problem.

From IRC:

<glyph> drewp: it ought to raise an exception immediately

I agree with this.

Change History (4)

comment:1 Changed 8 years ago by drewp

request.addCookie(k, someUnicode) has the same problem.

comment:2 Changed 8 years ago by Jean-Paul Calderone

Fairly related to #3896.

comment:3 in reply to:  2 Changed 8 years ago by msabramo

Cc: msabramo added
Resolution: duplicate
Status: newclosed

Replying to exarkun:

Fairly related to #3896.

I just tested with

>>> twisted.version
Version('twisted', 10, 1, 0)  # (SVN r30361)

along with the patch in #3896 and both the redirect and the cookie with unicode lead to an exception as desired:

exceptions.TypeError: Data must not be unicode

The patch deals with data at the TCP level rather than the HTTP level, so it should find all sorts of improper uses of unicode. Theoretically it should be useful for other protocols besides HTTP.

comment:4 Changed 8 years ago by <automation>

Owner: jknight deleted
Note: See TracTickets for help on using tickets.