gpt4 book ai didi

.net - 角色检查应该在调用堆栈的哪个位置进行?

转载 作者:行者123 更新时间:2023-12-04 16:57:04 25 4
gpt4 key购买 nike

在我的典型应用程序中,用户单击 aspx 页面中的按钮,调用 C# 业务对象,然后运行存储过程。

角色检查应该在堆栈顶部、堆栈底部还是在每个级别进行?似乎如果恶意用户可以调用一个方法,他可以调用任何方法,因此为了有效的安全性,您需要检查每个方法(并且要编写很多额外的代码)。

这是一个典型的调用堆栈来说明我的问题:

Page_Load()
{
if(p.IsInRole("Managers")) //or equivalent attribute
{
AddAccount.Visible =true;
}
}

AddAccount_OnClick()
{
if(p.IsInRole("Managers")) //or equivalent attribute
{
//Add the account
Account.Add(...); //and maybe another role check...
}
}

-- TSQL doesn't understand .NET authorization, this call is in a 'trusted' subsystem
create proc Add_Account @user, @account_name
If @user in (Select user from role_table where role='manager')
-- Add the account

最佳答案

在我看来,你应该把它放在尽可能接近数据的地方。离数据越近,就越能确保不可能通过代码库采取迂回路线来规避访问检查。

该论点将要求在数据源本身(如果它支持它(如您最喜欢的 RDBMS))或数据访问层中进行安全检查。

但是,一些安全约束带有强烈的业务逻辑气味;例如“如果用户处于此角色并试图修改符合这些规范的数据,则应允许该操作;否则不允许”。在我看来,这听起来像是一项策略,并且属于某种单独的规则引擎的业务逻辑层。

I wrote about something similar in the context of WCF some time ago .

关于.net - 角色检查应该在调用堆栈的哪个位置进行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1050729/

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