gpt4 book ai didi

c# - WCF 查询拦截器 : Is this MSDN sample a security risk?

转载 作者:太空宇宙 更新时间:2023-11-03 14:25:38 25 4
gpt4 key购买 nike

如果你看this MSDN 文档中有一个示例,代码如下:

// 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 问题,如何确定修改后的属性的原始值(实体实例将在当前数据源上进行跟踪)。

关于c# - WCF 查询拦截器 : Is this MSDN sample a security risk?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4150669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com