Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Can not use SECURITY_UNAUTHORIZED_VIEW to redirect.  #821

Description

@odinms

1.From the FLASK docs:

url_for() usage is like : return redirect(url_for('auth.login'))

this will get you the url for auth.login()

2.if the SECURITY_UNAUTHORIZED_VIEW is set right.
e.g.

SECURITY_UNAUTHORIZED_VIEW = 'auth.login'

view = utils.get_url(utils.config_value('UNAUTHORIZED_VIEW')) will set view = "/login" with is the URL of the login page correspond to the 'auth.login' endpoint

def get_url(endpoint_or_url):
    try:
        return url_for(endpoint_or_url)
    except:
        return endpoint_or_url

And since view = "/login" is just a STRING, not a callable().
it will go to

try:
    view = url_for(view)
except BuildError:
    view = None

THEN, everything went wrong here~!!!
url_for() can not use "/login" as input to process, since it is already processed by url_for() once!! It will always raise error~!!

So , the code runs to except BuildError: view = None
Finally, end up with view = None

So.. the redirect to request.referrer or '/' forever~!!!!

Originally posted by @odinms in https://github.com/mattupstate/flask-security/issue_comments#issuecomment-448192001

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions