Flask redirection problem: If no security verification URL

A fooo view, a barrr view. After clicking through the link in the view, do something, or return fooo barrr route.

@app.route('/fooo')
def fooo():
    return '<h1>Fooo Page</h1><a href="%s">Do somethinggg</a>' % url_for('do_somethinggg', next=request.full_path)

@app.route('/barrr')
def barrr():
    return '<h1>Barrr Page</h1><a href="%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'))

Click URL: 127.0.0.1: Link 5000 / fooo the redirection, as follows:

relative URL link: / do_somethinggg next =% 2Ffooo% 3F?
If I type in the address bar: http: //127.0.0.1: 5000 ? / do_somethinggg next = /
will jump to the URL: http: //127.0.0.1: 5000 /
results in an open redirect vulnerability (open redirect)

Guess you like

Origin www.cnblogs.com/daemonFlY/p/12003064.html