<div dir="ltr"><div dir="ltr" class="gmail_msg">> <span style="color:rgb(33,33,33)" class="gmail_msg">The code calling request.URLPath(), in a given Resource, or application, is highly unlikely to know whether it wants to honor (x-)forwarded-for.</span></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">You are right, I haven't thought about it.</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">But I'm in doubt whether trusting X-Forwarded-* by default can damage security if Twisted app is running with naked HTTP(S) port exposed without reverse proxy that handles these headers.</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">There are three headers:</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">1. X-Forwarded-For specifying original client IP and IPs of proxies</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">2. X-Forwarded-Host specifying original Host header from the client</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">3. X-Forwarded-Proto specifying original client's scheme</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">(there is also new-style "Forwarded:" header but it is not widely used yet, AFAIK)</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">X-Forwarded-For definetly can't be trusted if comes from untrusted client client. Fortunately we don't need it at all for generating URLs :) It will be in question when refactoring getClientIP() somewhen later.</span><br class="gmail_msg"></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg"><br></span></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">But can we trust </span><span style="color:rgb(33,33,33)" class="gmail_msg">X-Forwarded-Host & X-Forwarded-Proto? From the first glance it isn't a problem since we are using them to display URLs for the same client, so nasty client will get his nasty URLs, that's it. But if app is doing something like storing URL in DB or (more likely) sending an email with a link to another client, this would be an issue.</span></div><div class="gmail_msg"><br></div><div class="gmail_msg"><span style="color:rgb(33,33,33)" class="gmail_msg">-- ilya</span></div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">пт, 17 мар. 2017 г. в 11:18, Glyph <<a href="mailto:glyph@twistedmatrix.com" class="gmail_msg" target="_blank">glyph@twistedmatrix.com</a>>:<br class="gmail_msg"></div></div><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Mar 15, 2017, at 1:20 AM, Ilya Skriblovsky <<a href="mailto:ilyaskriblovsky@gmail.com" class="gmail_msg" target="_blank">ilyaskriblovsky@gmail.com</a>> wrote:</div><br class="m_-7434395177431637724m_2995826440253295589Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg">Ok, so in the sort term you are suggesting to change Request.URLPath</div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Yes.</div><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"> (uppercased method? Hmm)</div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Like I said, not a great interface, overall :-).</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"> to use Host header instead of getRequestHostname and to change Klein to use it instead of Request.getHost(), right?<div class="gmail_msg">Sounds wise and reasonable :)</div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">OK, glad you agree :).</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">But I'd like to add one more thing. In order to build correct external URL we need to know is it http or https. Currently URLPath is using Request.isSecure(), but it is not sufficient since Request.isSecure() just checks if backend connection is SSL while encryption is often terminated at a reverse proxy. Can we add "useXForwardedProto=False" argument to Request.URLPath() and check X-Forwarded-Proto header if it is true? And may be add "useXForwardedHost=False" too to simplify setting up a reverse proxy (with a bold red warning in docstring that it can be set to True only if reverse proxy is correctly configured to drop corresponding client-specified headers). What do you think?</div></div></blockquote><br class="gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"></div><div class="gmail_msg">I think that for starters, it would make more sense to just fix it to <i class="gmail_msg">always</i> honor forwarded-for and x-forwarded-for headers. The code calling request.URLPath(), in a given Resource, or application, is highly unlikely to know whether it wants to honor (x-)forwarded-for. The code that might know about this sort of configuration would be the thing that constructs the Site object, but I'd be much happier to just get a change that always honors it first, and then figure out how to customize it later.</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">-glyph</div><div class="gmail_msg"><br class="gmail_msg"></div></div>_______________________________________________<br class="gmail_msg">
Twisted-web mailing list<br class="gmail_msg">
<a href="mailto:Twisted-web@twistedmatrix.com" class="gmail_msg" target="_blank">Twisted-web@twistedmatrix.com</a><br class="gmail_msg">
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" rel="noreferrer" class="gmail_msg" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br class="gmail_msg">
</blockquote></div></div>