On Fri, Jul 16, 2010 at 11:28 PM, Graham Dumpleton <span dir="ltr">&lt;<a href="mailto:graham.dumpleton@gmail.com">graham.dumpleton@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<div><div></div><div class="h5">&gt; Nah, not nearly that hard:<br>
&gt;<br>
&gt; path_info = urllib.parse.unquote_to_bytes(environ[&#39;wsgi.raw_path_info&#39;]).decode(&#39;UTF-8&#39;)<br>
&gt;<br>
&gt; I don&#39;t see the problem?  If you want to distinguish %2f from /, then you&#39;ll do it slightly differently, like:<br>
&gt;<br>
&gt; path_parts = [<br>
&gt;     urllib.parse.unquote_to_bytes(p).decode(&#39;UTF-8&#39;)<br>
&gt;     for p in environ[&#39;wsgi.raw_path_info&#39;].split(&#39;/&#39;)]<br>
&gt;<br>
&gt; This second recipe is impossible to do currently with WSGI.<br>
&gt; So... before jumping to conclusions, what&#39;s the hard part with using<br>
<br>
</div></div>Sorry, it is not that simple. The thing that everyone is ignoring is<br>
that SCRIPT_NAME and PATH_INFO are also normalized by the web server<br>
normally. That is, .. instances are removed. By passing the raw URL<br>
through to the application, you are now forcing every application to<br>
have to deal with that as well with the possibility of directory<br>
traversal attacks when people get it wrong and the URL is mapping<br>
somehow to file system resources. It is a huge can of worms which at<br>
the moment the web server deals with.<br></blockquote><div><br>Well... at least to me &quot;raw&quot; only means &quot;not URL decoded&quot;, so it doesn&#39;t necessarily mean you can&#39;t clean up the request path.  I guess an attacker could encode &quot;.&quot; to make things harder.<br>

<br>Nevertheless, WSGI servers don&#39;t currently guarantee this cleaning.  I added it to paste.httpserver, but I don&#39;t know one way or the other about any other servers.  A quick test shows wsgiref does not clean paths.  So apps shouldn&#39;t rely on a clean path.<br clear="all">

<br></div></div><br>-- <br>Ian Bicking  |  <a href="http://blog.ianbicking.org">http://blog.ianbicking.org</a><br>