gpt4 book ai didi

python - flask-login 中不存在 next_is_valid()?

转载 作者:太空狗 更新时间:2023-10-29 18:05:56 25 4
gpt4 key购买 nike

Flask-login doc说我们应该使用 next_is_valid() 验证下一个,但我找不到任何这样的方法:

Warning: You MUST validate the value of the next parameter. If you do not, your application will be vulnerable to open redirects.

@app.route('/login', methods=['GET', 'POST'])
def login():
# Here we use a class of some kind to represent and validate our
# client-side form data. For example, WTForms is a library that will
# handle this for us.
form = LoginForm()
if form.validate_on_submit():
# Login and validate the user.
login_user(user)

flask.flash('Logged in successfully.')

next = flask.request.args.get('next')
if not next_is_valid(next):
return flask.abort(400)

return flask.redirect(next or flask.url_for('index'))
return flask.render_template('login.html', form=form)

运行这个我得到错误:

NameError: global name 'next_is_valid' is not defined

如果我这样做:

from flask.ext.login import next_is_valid
>> ImportError: cannot import name next_is_valid

next_is_valid() 函数在哪里,如果它不存在,我该如何验证 next 参数?

最佳答案

它没有说你必须用next_is_valid验证next,只是说

You MUST validate the value of the next parameter.

next_is_valid 只是一个示例函数。

您必须根据自己的标准确定next 是否有效。 next 是成功登录时重定向到的 url。如果您在您的网站上有任何应用权限或限制,您需要确保这些权限得到执行。

例如,用户可以尝试使用请求 url http://example.com/login?next=admin/delete/all/users 登录。如果登录尝试成功并且未在您的登录功能或端点本身上检查管理员权限,那么,可能会发生不好的事情。这完全取决于您如何构建应用程序和控制对各个端点的访问。

关于python - flask-login 中不存在 next_is_valid()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31927227/

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