简体   繁体   English

运行运行时代码的安全方式(XML文件编辑)C#

[英]Secure way to run runtime code (XML file editing) C#

I have a CLI application which is able to edit XML files with some parameters. 我有一个CLI应用程序,它能够使用一些参数来编辑XML文件。

However I'm needing now a more powerful way to do it. 但是,我现在需要一种更强大的方法来做到这一点。

I want to give users the option to edit XML files using custom code from a .txt for total control over the XML editing. 我想为用户提供使用.txt中的自定义代码来编辑XML文件的选项,以完全控制XML编辑。

For example: 例如:

@CODE File<file name for XML editing>
<code>
# Custom XML parser/editing code
for elem in tree.iter(tag='location'):
if elem.text == 'J':
    elem.text = 'January'
</code>

Which would be the safest way to do this in .net C#? 在.net C#中,哪种方法最安全? I mean the user only be able to edit the XML file and not doing anything more that compromises the security of the system (like deleting files)? 我的意思是用户只能编辑XML文件,而不能做其他有损系统安全性的事情(例如删除文件)?

I'm thinking of using a Javascript engine ( like this one ) and running javascript code from the file. 我正在考虑使用Javascript引擎( 例如这种引擎)并从文件中运行javascript代码。 I believe javascript would limit what the user would be able to do. 我相信JavaScript会限制用户的操作能力。 I also thought in C# code and Python but this ones may introduce the security issues. 我也考虑过使用C#代码和Python,但这可能会引入安全性问题。

Edit: One requirement is that it must work on mono. 编辑:一个要求是它必须在单声道上工作。

I have choose the IronJS .NET runtime with a javascript XML library discussed here (XML for < script> W3C DOM Parser). 我选择了IronJS .NET运行时以及此处讨论的JavaScript XML库(用于<script> W3C DOM Parser的XML)。

I have also looked for other javascript .NET runtimes like: Javascript .NET, Jurassic and Jint (opted for IronJS because the better performance). 我还寻找了其他javascript .NET运行时,例如:Javascript .NET,Jurassic和Jint(之所以选择IronJS是因为性能更好)。 Plus tested some .NET Lua libraries, namely Kopilua , but opted for the javascript solution because it seemed more complete, more documented and easier to use. Plus还测试了一些.NET Lua库(即Kopilua) ,但选择了javascript解决方案,因为它似乎更完整,文档更丰富且更易于使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM