<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Arial Black";
        panose-1:2 11 10 4 2 1 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Arial","sans-serif";
        color:windowtext;
        font-weight:normal;
        font-style:normal;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:70.85pt 70.85pt 56.7pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Take a look at the PlatformAdaptationLayer class. You can create your own and plug it in to the runtime. This might provide the hooks you are looking for.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">In particular, you should be able to override the LoadAssembly() and LoadAssemblyFromPath() methods to block anything that isn’t whitelisted for your host environment.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><b><span style="font-size:14.0pt;color:#1F497D">Keith Rome<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;color:#1F497D">Senior Consultant and Architect<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D">MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D">Wintellect | 770.617.4016 |
<a href="mailto:rome@wintellect.com">krome@wintellect.com</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D"><a href="http://www.wintellect.com/">www.wintellect.com</a><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Ironpython-users [mailto:ironpython-users-bounces+rome=wintellect.com@python.org]
<b>On Behalf Of </b>Markus Schaber<br>
<b>Sent:</b> Wednesday, October 17, 2012 6:09 AM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> [Ironpython-users] Restrict referencing of assemblies in hosted environment<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">We’re using IronPython as a hosted script engine in our application.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Now, we want to restrict the assemblies a user can reference from its python script,
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Currently, we just forbid “import clr”, by wrapping the import() method, but this is a bit harsh, and the side-effects are a little bit to strong (e. G. it causes “import minidom.py”
 to fail…)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">However, there seems to be no event or other hook available for AddReference which I could use. It may be possible to add an AssemblyLoading event to the ScriptDomainManager
 in Microsoft.Scripting.Runtime, which allows to cancel the assembly loading by throwing an exception. Would such a patch be accepted upstream?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">An alternative (not-so-elegant) idea is that I just wrap all the AddReference() & Co calls inside the clr module, but there may be a more elegant way.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Isolating Ironpython in its own AppDomain is not an option, as this would require major rework of our Scripting API implementation, and also break backwards compatibility for
 3<sup>rd</sup> party plugins which contribute API for the scripts.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">(We don’t need a 100% waterproof method -  we know that the user can use cTypes, System.Reflection, or whatever to circumvent everything - we just want to restrict the obvious
 ways to access some APIs we consider to be internal.)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="DE" style="font-size:10.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE">Best regards<br>
<br>
Markus Schaber<br>
<span style="color:white">-- </span><br>
</span><span lang="DE" style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#9C9C9F;mso-fareast-language:DE">___________________________</span><span lang="DE" style="font-size:12.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-top:6.0pt;mso-margin-bottom-alt:auto"><span lang="DE" style="font-size:9.0pt;font-family:"Arial Black","sans-serif";color:#9C9C9F;mso-fareast-language:DE">We software Automation.<br>
<br>
</span><span lang="DE" style="font-size:9.0pt;font-family:"Arial Black","sans-serif";color:#C40020;mso-fareast-language:DE">3S-Smart Software Solutions GmbH<br>
</span><span lang="DE" style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE">Markus Schaber | Developer<br>
Memminger Str. 151 | 87439 Kempten | Germany | Tel. </span><span style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE">+49-831-54031-0 | Fax +49-831-54031-50<br>
<br>
Email: </span><u><span lang="DE" style="font-size:9.0pt;font-family:"Arial","sans-serif";color:blue;mso-fareast-language:DE"><a href="mailto:m.schaber@3s-software.com"><span lang="EN-US">m.schaber@3s-software.com</span></a></span></u><span style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE">
 | Web: </span><span lang="DE" style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><a href="http://www.3s-software.com/"><span lang="EN-US">http://www.3s-software.com
</span></a></span><span style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><br>
CoDeSys internet forum:</span><span lang="DE" style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><a href="http://forum-en.3s-software.com/"><span lang="EN-US"> http://forum.3s-software.com</span></a></span><span style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><br>
Download CoDeSys sample projects: </span><span lang="DE" style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><a href="http://www.3s-software.com/index.shtml?sample_projects"><span lang="EN-US">http://www.3s-software.com/index.shtml?sample_projects</span></a></span><span style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><br>
<br>
</span><i><span style="font-size:7.5pt;font-family:"Arial","sans-serif";mso-fareast-language:DE">Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner</span></i><span style="font-size:7.5pt;font-family:"Arial","sans-serif";mso-fareast-language:DE">
 | <i>Trade register: Kempten HRB 6186</i> | <i>Tax ID No.: DE 167014915</i></span><i><span style="font-size:12.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE">
</span></i><span style="font-size:9.0pt;font-family:"Arial","sans-serif";mso-fareast-language:DE"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>