<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Warning: os.path.join surprising behaviour</title>
	<atom:link href="http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/feed" rel="self" type="application/rss+xml" />
	<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour</link>
	<description>pulling the rug</description>
	<pubDate>Fri, 09 Jan 2009 22:09:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chui</title>
		<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/comment-page-1#comment-5804</link>
		<dc:creator>Chui</dc:creator>
		<pubDate>Tue, 19 Jun 2007 23:04:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour#comment-5804</guid>
		<description>Fuzzyman,

You are right that it's documented. It doesn't stop the behavior from being surprising. 

About stripping leading "/", you also need to strip the drive name on Windows platforms.

A better guard is to assert that the joined path is a subdirectory of the base.

e.g. &lt;code&gt;
newpath = os.path.join(base, subpath)
assert newpath.find(base) == 0
&lt;/code&gt;
Perhaps it should be annotated as being unsafe on web platforms.

Chui</description>
		<content:encoded><![CDATA[<p>Fuzzyman,</p>
<p>You are right that it&#8217;s documented. It doesn&#8217;t stop the behavior from being surprising. </p>
<p>About stripping leading &#8220;/&#8221;, you also need to strip the drive name on Windows platforms.</p>
<p>A better guard is to assert that the joined path is a subdirectory of the base.</p>
<p>e.g. <code><br />
newpath = os.path.join(base, subpath)<br />
assert newpath.find(base) == 0<br />
</code><br />
Perhaps it should be annotated as being unsafe on web platforms.</p>
<p>Chui</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/comment-page-1#comment-5803</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Tue, 19 Jun 2007 13:59:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour#comment-5803</guid>
		<description>It surprises me. But os.path.join is inherently unsafe: '../../../d/e/f' would have the same effect as '/d/e/f' here. Don't let untrusted sources supply paths!</description>
		<content:encoded><![CDATA[<p>It surprises me. But os.path.join is inherently unsafe: &#8216;../../../d/e/f&#8217; would have the same effect as &#8216;/d/e/f&#8217; here. Don&#8217;t let untrusted sources supply paths!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dtlin</title>
		<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/comment-page-1#comment-5802</link>
		<dc:creator>dtlin</dc:creator>
		<pubDate>Tue, 19 Jun 2007 13:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour#comment-5802</guid>
		<description>&#62;&#62;&#62; os.path.join("/a/b/c", *"/d/e/f".split('/'))
'/a/b/c/d/e/f'

It is a bit surprising.</description>
		<content:encoded><![CDATA[<p>&gt;&gt;&gt; os.path.join(&#8221;/a/b/c&#8221;, *&#8221;/d/e/f&#8221;.split(&#8217;/'))<br />
&#8216;/a/b/c/d/e/f&#8217;</p>
<p>It is a bit surprising.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fuzzyman</title>
		<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/comment-page-1#comment-5801</link>
		<dc:creator>Fuzzyman</dc:creator>
		<pubDate>Tue, 19 Jun 2007 11:44:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour#comment-5801</guid>
		<description>Oh - and you can stop it by detecting/removing the leading "/".</description>
		<content:encoded><![CDATA[<p>Oh - and you can stop it by detecting/removing the leading &#8220;/&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fuzzyman</title>
		<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/comment-page-1#comment-5800</link>
		<dc:creator>Fuzzyman</dc:creator>
		<pubDate>Tue, 19 Jun 2007 11:43:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour#comment-5800</guid>
		<description>How is that surprising? It is the documented behaviour, and usually desirable. The second path in your example is rooted.</description>
		<content:encoded><![CDATA[<p>How is that surprising? It is the documented behaviour, and usually desirable. The second path in your example is rooted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afoo</title>
		<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/comment-page-1#comment-5799</link>
		<dc:creator>afoo</dc:creator>
		<pubDate>Tue, 19 Jun 2007 11:26:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour#comment-5799</guid>
		<description>Ah, nevermind, there already are http://sourceforge.net/tracker/index.php?func=detail&#38;aid=1209447&#38;group_id=5470&#38;atid=105470 and http://sourceforge.net/tracker/index.php?func=detail&#38;aid=1688564&#38;group_id=5470&#38;atid=105470</description>
		<content:encoded><![CDATA[<p>Ah, nevermind, there already are <a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1209447&amp;group_id=5470&amp;atid=105470" rel="nofollow">http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1209447&amp;group_id=5470&amp;atid=105470</a> and <a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1688564&amp;group_id=5470&amp;atid=105470" rel="nofollow">http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1688564&amp;group_id=5470&amp;atid=105470</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afoo</title>
		<link>http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour/comment-page-1#comment-5798</link>
		<dc:creator>afoo</dc:creator>
		<pubDate>Tue, 19 Jun 2007 11:21:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/warning-ospathjoin-surprising-behaviour#comment-5798</guid>
		<description>Hm IMHO, this is a bug and should be reported. What do you think?</description>
		<content:encoded><![CDATA[<p>Hm IMHO, this is a bug and should be reported. What do you think?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
