Python-social-auth 登录后重定向到另一个域

Goc*_*cht 5 python django redirect python-social-auth

使用 登录后是否可以重定向到另一个网站python-social-auth

比方说:

<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}"></a>
Run Code Online (Sandbox Code Playgroud)

上面的例子是根据文档,它运行良好,但是当我尝试这个时:

<a href="{% url 'social:begin' 'facebook' %}?next=http://www.google.com/"></a>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

http://example.com:8000/accounts/profile/ Not Found
Run Code Online (Sandbox Code Playgroud)

这是有道理的;我没有定义这个 URL

此时我已经登录,但我看到一个错误页面。

但是使用相同的配置,如果我重定向到我自己的网站,这有效,我认为这是有关设置的问题,但我不知道是哪一个。

编辑:

如果我next在第一个配置中删除 GET 参数,它会引发相同的错误。

Ala*_*air 3

重定向到不同的域是不安全的,例如https://www.google.com. 要理解原因,想象一下我向您的用户发送了一个链接:

http://www.yoursite.com/login?next=http://myevilsite.com
Run Code Online (Sandbox Code Playgroud)

如果您的登录页面信任该next网址,那么您的用户在登录后将被重定向到我的网站。我可以使用它进行网络钓鱼攻击。

为了防止这种情况,Django 检查下一个 url 是否可以安全重定向。如果不安全,则会重定向到settings.LOGIN_REDIRECT_URL,默认为/accounts/profile/。您可以在此处查看代码