【问题标题】:django security: can an indirect view be called by a non-admin?django 安全性:非管理员可以调用间接视图吗?
【发布时间】:2019-07-19 11:34:23
【问题描述】:

说我有以下方法

@staff_member_required 
def foo(request):
    return say_secret_hello(request)

def says_secret_hello(request):
    #do secret stuff 
    return "hello

urls.py

path("/hello", foo)

如您所见,我只向我的管理员公开了foo。从安全的角度来看,非管理员是否可以致电say_secret_hello()

【问题讨论】:

  • 管理员/非管理员无关,您只提供了其中一个视图的路径

标签: python django security python-3.7


【解决方案1】:

不,普通用户无法调用此函数,您也可以在视图中使用以下语法:

if request.user.is_staff:
   #do some code

在模板中你可以使用 if 语句:

{% if request.user.is_staff %}
Show some content 
{% endif %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多