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(csp): automatically include SAML IDP URL in form-action #12669

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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
22 changes: 18 additions & 4 deletions weblate/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from django.utils.translation import gettext_lazy
from social_core.backends.oauth import OAuthAuth
from social_core.backends.open_id import OpenIdAuth
from social_core.backends.saml import SAMLAuth
from social_django.utils import load_strategy

from weblate.auth.models import AuthenticatedHttpRequest, get_auth_backends
Expand Down Expand Up @@ -428,14 +429,27 @@ def build_csp_auth(self) -> None:
else:
social_strategy = load_strategy(self.request)
for backend in get_auth_backends().values():
url = ""
urls: list[str] = []

# Handle OpenId redirect flow
if issubclass(backend, OpenIdAuth):
url = backend(social_strategy).openid_url()
urls = [backend(social_strategy).openid_url()]

# Handle OAuth redirect flow
if issubclass(backend, OAuthAuth):
url = backend(social_strategy).authorization_url()
if url:
urls = [backend(social_strategy).authorization_url()]

# Handle SAML redirect flow
if issubclass(backend, SAMLAuth):
saml_auth = backend(social_strategy)
urls = [
saml_auth.get_idp(idp_name).sso_url
for idp_name in getattr(
settings, "SOCIAL_AUTH_SAML_ENABLED_IDPS", {}
)
]

for url in urls:
self.add_csp_host(url, "form-action")


Expand Down
Loading