控制器和操作的集中授权 (ASP.NET MVC 3)

发布于 2025-01-03 20:18:34 字数 406 浏览 1 评论 0原文

在自定义 AuthorizeAttibute(全局注册)中,根据所调用的控制器类型和操作应用授权是否存在任何可能的安全问题或陷阱?

例如(不是真正的代码)

string controllerFullName=_filterContext.ActionDescriptor.ControllerDescriptor.ControllerType.FullName;

string minRequiredRole = GetControllerMinRequiredRole(controllerFullName);

if(User.MeetsRoleRequirement(minRequiredRole))
{
     //give access
}
else
{
    //no you're not allowed
}

Are there any possible security issues or pitfalls to, within a custom AuthorizeAttibute (registered globally), apply authorization based on the controller type and action being called?

e.g. (not real code)

string controllerFullName=_filterContext.ActionDescriptor.ControllerDescriptor.ControllerType.FullName;

string minRequiredRole = GetControllerMinRequiredRole(controllerFullName);

if(User.MeetsRoleRequirement(minRequiredRole))
{
     //give access
}
else
{
    //no you're not allowed
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅的被狗咬 2025-01-10 20:18:34

主要问题是授权缓存 - 因此有一些事情需要了解。查看我在此处发布的链接:

创建 AuthorizeAttribute -我需要知道什么?

查看现有属性的代码以及它如何处理缓存,以确保您不会导致基本属性所防止的相同问题。

The main issue is with Authorization caching - so there are a few things to know. Check out the links I've posted here:

Creating a AuthorizeAttribute - what do I need to know?

Look at the code to the existing attribute and how it handles caching to ensure you arent causing the same issue the base attribute prevents.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文