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

fix: Make sure Okta iss has proper form #190

Merged
merged 3 commits into from
Oct 17, 2023
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
10 changes: 10 additions & 0 deletions codecov_auth/tests/unit/views/test_okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ def test_okta_redirect_to_authorize_no_iss(client):
assert res.url == f"{settings.CODECOV_DASHBOARD_URL}/login"


@override_settings(
OKTA_OAUTH_CLIENT_ID="test-client-id",
OKTA_OAUTH_REDIRECT_URL="https://localhost:8000/login/okta",
)
def test_okta_redirect_to_authorize_invalid_iss(client):
res = client.get(reverse("okta-login"), data={"iss": "https://non.okta.domain"})
assert res.status_code == 302
assert res.url == f"{settings.CODECOV_DASHBOARD_URL}/login"


@override_settings(
OKTA_OAUTH_CLIENT_ID="test-client-id",
OKTA_OAUTH_CLIENT_SECRE="test-client-secret",
Expand Down
6 changes: 5 additions & 1 deletion codecov_auth/views/okta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import logging
import uuid
import re
from typing import Dict, Optional
from urllib.parse import urlencode

Expand All @@ -18,6 +18,7 @@
from utils.services import get_short_service_name

log = logging.getLogger(__name__)
iss_regex = re.compile(r"https://[\w\d\-\_]+.okta.com/?")


def validate_id_token(iss: str, id_token: str) -> dict:
Expand Down Expand Up @@ -186,4 +187,7 @@ def get(self, request):
if not iss:
log.warning("Missing Okta issuer")
return redirect(f"{settings.CODECOV_DASHBOARD_URL}/login")
if not iss_regex.match(iss):
log.warning("Invalid Okta issuer")
return redirect(f"{settings.CODECOV_DASHBOARD_URL}/login")
return self._redirect_to_consent(iss=iss)
Loading