如何危险的是它让用户指定RazorEngine模板? [英] How dangerous is it to let users specify RazorEngine templates?

查看:168
本文介绍了如何危险的是它让用户指定RazorEngine模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的邮件合并功能类似,这需要一个模板,一些业务对象,并生成HTML,然后制作成PDF格式。

I have mail-merge like functionality, which takes a template, some business object, and produces html which is then made into PDF.

我使用 RazorEngine 做模板+模式为HTML位。

I'm using RazorEngine to do the template+model to html bit.

如果我让使用者指定的模板,我会采取什么样的风险?是否有可能减轻任何风险?

If I let the users specify the templates, what risks am I taking? Is it possible to mitigate any risks?

例如,可以在用户执行任意code? (删除文件,修改数据库等?)有一些方法可以让我发现这样的事情? (我知道这是不可能的一般,但code在剃刀模板位应该为模型属性获取,或可能,如果基于模型的属性值的语句)。

For example, could the users execute arbitrary code? (delete files, alter database, etc.?) Is there some way I can detect this sort of thing? (I know that would be impossible generally, but the bits of code in the razor template should be model property gets, or possibly if statements based on model property values).

我这里基本上信任的用户(这是一个小型私人项目),但作为模板引擎去,这一次似乎过于强大了这个应用程序。

I do basically trust the users here (it's a small private project), but as templating engines go, this one seems excessively powerful for this application.

推荐答案

一个CSHTML剃刀文件是能够执行任何。 NET code在现场的现场,从而是的,这是一个安全隐患,以使它们能够被用户所提供的。

A cshtml Razor file is able to execute any. NET code in the context of the site so yes, it is a security risk to permit them to be supplied by users.

您会得到更好的接受更广泛的HTML模板服务,定制标记输入模型数据。

You would be better served by accepting a more general HTML template, with custom tokens to input Model data.

这篇关于如何危险的是它让用户指定RazorEngine模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆