<br><br><div><span class="gmail_quote">On 1/2/07, <b class="gmail_sendername">Barry Warsaw</b> &lt;<a href="mailto:barry@python.org">barry@python.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA1<br><br>On Jan 2, 2007, at 10:53 PM, Anthony Baxter wrote:<br><br>&gt; Additionally, base32 and base16 are not supported by codecs,<br>&gt; according to the docs, and neither is the ability to specify
<br>&gt; alternate character mappings (I don&#39;t know how heavily used the<br>&gt; last is, though).<br><br>Which reminds me of another problem I have with the codecs module.<br>codecs are a potential security issue because they are a backdoor way
<br>to get modules imported.&nbsp;&nbsp;For example, if I get an email with a<br>specified charset, the natural thing is to want to use .decode() to<br>turn that into a unicode.&nbsp;&nbsp;The problem is that Python can be<br>essentially tricked into importing any module that way.&nbsp;&nbsp;Try this:
<br><br>Python 2.4.3 (#1, Jun 12 2006, 19:42:21)<br>[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
<br> &gt;&gt;&gt; import sys<br> &gt;&gt;&gt; sys.modules[&#39;smtplib&#39;]<br>Traceback (most recent call last):<br>&nbsp;&nbsp; File &quot;&lt;stdin&gt;&quot;, line 1, in ?<br>KeyError: &#39;smtplib&#39;<br> &gt;&gt;&gt; &#39;foo&#39;.decode(&#39;smtplib&#39;)
<br>Traceback (most recent call last):<br>&nbsp;&nbsp; File &quot;&lt;stdin&gt;&quot;, line 1, in ?<br>LookupError: unknown encoding: smtplib<br> &gt;&gt;&gt; sys.modules[&#39;smtplib&#39;]<br>&lt;module &#39;smtplib&#39; from &#39;/opt/local/Library/Frameworks/
<br>Python.framework/Versions/2.4/lib/python2.4/smtplib.pyc&#39;&gt;<br> &gt;&gt;&gt;</blockquote><div><br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Okay, so this doesn&#39;t open any more holes than are already opened,<br>but I worry that the style of encouraging codec use will make such<br>potential holes more widespread.&nbsp;&nbsp;The problem is that it&#39;s very<br>difficult to code defensively around this because you can&#39;t really
<br>whitelist or blacklist the set of valid codecs, and you can&#39;t<br>feasibly audit every importable module to see if it has nasty import<br>side effects.<br><br>It would help if codec lookup wasn&#39;t import based, or somehow any
<br>import side-effects could be isolated.</blockquote><div><br>I bet using an absolute import on the part of the codecs module to specify the encodings package would deal with a lot of your worries.<br></div><br>-Brett</div>