<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Protecting Against Malicious Code Injection</title><link>http://blogs.msdn.com/powershell/archive/2006/11/23/protecting-against-malicious-code-injection.aspx</link><description>If you are writing scripts that accept input from users - you need to be aware of the potential dangers of Malicious Code-Injection. Below is a good good article on this topic: http://www.site-reference.com/articles/Website-Development/Malicious-Code-Injection-It-s-Not-Just-for-SQL-Anymore.html</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Protecting Against Malicious Code Injection</title><link>http://blogs.msdn.com/powershell/archive/2006/11/23/protecting-against-malicious-code-injection.aspx#1141425</link><pubDate>Fri, 24 Nov 2006 19:29:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1141425</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;So let's say you have a situation where you _need_ to include user input in an invoke-expression statement.&lt;/p&gt;
&lt;p&gt;What would be the best approach to escaping the input? I imagine the usual characters like &amp;quot; ' ; etc would need to be backticked. Perhaps there needs to be a standard function for this kind of thing?&lt;/p&gt;</description></item><item><title>re: Protecting Against Malicious Code Injection</title><link>http://blogs.msdn.com/powershell/archive/2006/11/23/protecting-against-malicious-code-injection.aspx#1149206</link><pubDate>Sat, 25 Nov 2006 22:38:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1149206</guid><dc:creator>PowerShellTeam</dc:creator><description>&lt;p&gt;It really depends on what you mean by &amp;quot;include the user input&amp;quot;. If you just want to use it as data, put it in a variable and then reference the variable:&lt;/p&gt;
&lt;p&gt;$i = read-host&lt;/p&gt;
&lt;p&gt;invoke-expression 'write-output $i'&lt;/p&gt;
&lt;p&gt;There is no need to quote the user's input since it's just a value. Of course there's also no reason to use invoke-expression in this case since&lt;/p&gt;
&lt;p&gt;write-output $i&lt;/p&gt;
&lt;p&gt;will work fine. Perhaps you can expand on the scenario where you need to include the user's input?&lt;/p&gt;
&lt;p&gt;-bruce&lt;/p&gt;
&lt;p&gt;--------------------------&lt;/p&gt;
&lt;p&gt;Bruce Payette [MSFT]&lt;/p&gt;
&lt;p&gt;PowerShell Technical Lead&lt;/p&gt;
&lt;p&gt;Microsoft Corp.&lt;/p&gt;
</description></item><item><title>re: Protecting Against Malicious Code Injection</title><link>http://blogs.msdn.com/powershell/archive/2006/11/23/protecting-against-malicious-code-injection.aspx#1160367</link><pubDate>Mon, 27 Nov 2006 20:05:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1160367</guid><dc:creator>PowerShellTeam</dc:creator><description>&lt;p&gt;Another thing to keep in mind is what you consider to be your trust boundary. &lt;/p&gt;
&lt;p&gt;Most commonly, improper use of Invoke-Expression will just result in buggy code -- the user might use a semicolon and wonder why they are getting an error message. For that reason, you should avoid Invoke-Expression when dealing with user input unless necessary.&lt;/p&gt;
&lt;p&gt;If the user is running your script on their own machine under their own credentials, then you don't have to worry about the security aspects of Invoke-Expression, as they could just as easily do whatever they wanted to trick your script into anyways. If you've taken input from an untrusted user on the network, an untrusted user on a web page input field, or some other untrusted source, THEN you should be extremely conservative with what input you allow.&lt;/p&gt;
&lt;p&gt;Code injection attacks become attacks once they cross a trust boundary. If they don't cross a trust boundary, they are just a complicated and buggy way of doing what a user could already do.&lt;/p&gt;
&lt;p&gt;Lee&lt;/p&gt;
</description></item></channel></rss>