当前位置:首页 > Web开发 > 正文

Flask 重定向问题:若没有对URL进行安全验证

2024-03-31 Web开发

一个fooo视图,一个barrr视图。通过点击视图里的链接,进行一些操作之后,返回fooo或barrr路由。

@app.route('/fooo') def fooo(): return '<h1>Fooo Page</h1><a href=http://www.mamicode.com/"%s">Do somethinggg</a>' % url_for('do_somethinggg', next=request.full_path) @app.route('/barrr') def barrr(): return '<h1>Barrr Page</h1><a href=http://www.mamicode.com/"%s">Do somethinggg</a>' % url_for('do_somethinggg', next=request.full_path) @app.route('/do_somethinggg') def do_somethinggg(): print('------do somethinggg------') print(request.referrer) # 方法一:查询request.referrer获取重定向位置 return redirect(request.referrer or url_for('hello')) # 方法二:查询参数获取重定向位置 return redirect(request.args.get('next'))

点击 URL:127.0.0.1:5000/fooo中的链接实现重定向,如下:

技术图片


链接的相对URL:/do_somethinggg?next=%2Ffooo%3F
如果我在地址栏中输入::5000/do_somethinggg?next=http://www.mamicode.com/
则会跳转到URL::5000/
导致开放重定向漏洞(Open Redirect)

Flask 重定向问题:若没有对URL进行安全验证

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/41307.html