albumy中一个url安全验证函数不太懂,是is_safe_url()

书里有讲过这个方法吗?我网上查了下,好像flask_login内置了相似的方法is_safe_url(),但是用法细节不太明白?

代码:

def is_safe_url(target):
    ref_url = urlparse(request.host_url)
    test_url = urlparse(urljoin(request.host_url, target))
    return test_url.scheme in ('http', 'https') and \
           ref_url.netloc == test_url.netloc


def redirect_back(default='main.index', **kwargs):
    for target in request.args.get('next'), request.referrer:
        if not target:
            continue
        if is_safe_url(target):
            return redirect(target)
    return redirect(url_for(default, **kwargs))

见第 60 页。