Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block following redirects in logout #111

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mozilla_django_oidc_db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ def do_op_logout(config: OpenIDConnectConfigBase, id_token: str) -> None:
if not logout_endpoint:
return

response = requests.post(logout_endpoint, data={"id_token_hint": id_token})
response = requests.post(
logout_endpoint,
data={"id_token_hint": id_token},
allow_redirects=False,
)
if not response.ok:
logger.warning(
"Failed to log out the user at the OpenID Provider. Status code: %s",
Expand Down
14 changes: 14 additions & 0 deletions tests/test_logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,17 @@ def test_logout_with_logout_endpoint_configured(

assert kc_response.status_code == 200, "Did not end up on Keycloak's login page"
assert kc_response.headers["Content-Type"].startswith("text/html")


@pytest.mark.oidcconfig(oidc_op_logout_endpoint="https://example.com/oidc/logout")
def test_logout_response_has_redirect(dummy_config: OpenIDConnectConfig, requests_mock):
requests_mock.post(
"https://example.com/oidc/logout",
status_code=302,
headers={"Location": "http://testserver/endpoint-that-does-not-exist"},
)

try:
do_op_logout(dummy_config, id_token="dummy-id-token")
except Exception:
pytest.fail("Logout should not crash")