vmware-tanzu-labs / educates-training-platform

A platform for hosting interactive workshop environments in Kubernetes, or on top of a local container runtime.
https://docs.educates.dev
Apache License 2.0
72 stars 18 forks source link

CSRF verification broken when using PORTAL_HOSTNAME #379

Closed mocdaniel closed 4 months ago

mocdaniel commented 4 months ago

Describe the bug

Since v2.7.0 of the TrainingPortal, the CSRF verification is broken for portals configured with a custom Ingress domain via spec.portal.ingress.hostname.

This is due to the introduction of the CSRF_TRUSTED_ORIGINS setting in the Django settings.py of the project in 2552a4a.

Additional information

The current definition of CSRF_TRUSTED_ORIGINS only works when the TrainingPortal has not been configured to use a custom Ingress domain, thus defaulting to {PORTAL_NAME}-ui.{INGRESS_DOMAIN} for the Ingress domain.

Within the project's settings.py another variable PORTAL_HOSTNAME gets introduced which encapsulates the needed application logic already: using the configured Ingress domain if provided and falling back to the default case if not.

I will provide a PR fixing this issue, I already confirmed that it's working locally.