如果你看this http://msdn.microsoft.com/en-us/library/dd744837.aspxMSDN 文档中有一个示例,代码如下:
// Define a change interceptor for the Products entity set.
[ChangeInterceptor("Products")]
public void OnChangeProducts(Product product, UpdateOperations operations)
{
if (operations == UpdateOperations.Add ||
operations == UpdateOperations.Change)
{
// Reject changes to discontinued products.
if (product.Discontinued) //<-- IS THIS BASED ON UNVERIFIED CLIENT DATA???
{
throw new DataServiceException(400,
"A discontinued product cannot be modified");
}
}
else if (operations == UpdateOperations.Delete)
{
// Block the delete and instead set the Discontinued flag.
throw new DataServiceException(400,
"Products cannot be deleted; instead set the Discontinued flag to 'true'");
}
}
查看全部大写的评论。我的问题是:“该行是否依赖于客户端提供的数据......如果是这样,我们可以做些什么来进行安全验证”?
更改拦截器应在将客户端的修改应用于实体后获取该实体。因此,行为取决于提供者。如果您的提供将此属性实现为只读(这通常意味着对其的任何更新都会被忽略),那么上述检查就没有问题。我确实同意样本在这方面可能会更好。
另外,取决于您的提供商,如果此属性不是只读的,您需要向提供商询问未更改/之前的值。执行此操作的方法取决于提供商。因此,如果是 EF,这更多是一个 EF 问题,如何确定修改后的属性的原始值(将在当前数据源上跟踪实体实例)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)