Skip to content

fix: update mock config to include scheme for csrf domains #37120

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

Merged

Conversation

wgu-taylor-payne
Copy link
Contributor

Related to #33228.

Description

Since the scheme must be included for the CSRF_TRUSTED_ORIGINS setting since Django 4.0, this changes the values in the mock.yml configuration files to use the scheme for the values under CSRF_TRUSTED_ORIGINS. We match the values defined under CSRF_TRUSTED_ORIGINS_WITH_SCHEME key.

lms/envs/production.py pulls from CSRF_TRUSTED_ORIGINS_WITH_SCHEME in the YAML config to set the CSRF_TRUSTED_ORIGINS setting , but cms/envs/production.py pulls from CSRF_TRUSTED_ORIGINS in the YAML. So, this change fixes the CMS when run with mock.yml.

Testing instructions

Run SERVICE_VARIANT=cms DJANGO_SETTINGS_MODULE=cms.envs.production CMS_CFG=cms/envs/mock.yml ./manage.py cms dump_settings in a Tutor dev environment on master and you will get this error:

ERRORS:
?: (4_0.E001) As of Django 4.0, the values in the CSRF_TRUSTED_ORIGINS setting must start with a scheme (usually http:// or https://) but found .localhost. See the release notes for details.

Run the command on this branch and it will execute successfully.

@openedx-webhooks
Copy link

Thanks for the pull request, @wgu-taylor-payne!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 4, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Aug 4, 2025
@wgu-taylor-payne wgu-taylor-payne self-assigned this Aug 4, 2025
@wgu-taylor-payne wgu-taylor-payne added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Aug 4, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Aug 5, 2025
@dwong2708 dwong2708 self-requested a review August 7, 2025 21:56
@wgu-taylor-payne
Copy link
Contributor Author

@kdmccormick - @wgu-ram-chandra brought to my attention that the command in the "Testing instructions" is working on master. I just looked, and in my recent settings PR I had updated this line to use CSRF_TRUSTED_ORIGINS_WITH_SCHEME (like what is done in lms/envs/production.py) rather than CSRF_TRUSTED_ORIGINS. I had put that in first as a temporary solution to solve the issue described in this PR, but failed to remove it.

This could potentially lead to unintended consequences, if operators had valid, up-to-date values in CSRF_TRUSTED_ORIGINS, but not in CSRF_TRUSTED_ORIGINS_WITH_SCHEME in a custom YAML file. Do you think it is safe to keep that change, or should we revert back to CSRF_TRUSTED_ORIGINS?

@tonybusa
Copy link
Contributor

tonybusa commented Aug 7, 2025

Incoming potentially stupid question - do you still need CSRF_TRUSTED_ORIGINS_WITH_SCHEME??

If Django>=4.0 must include both scheme and host in CSRF_TRUSTED_ORIGINS, is there any global constraint on allowing a minimum Django version (i.e. <3.x) that would require backwards compatibility to keep the CSRF_TRUSTED_ORIGINS_WITH_SCHEME variable?

@wgu-taylor-payne
Copy link
Contributor Author

wgu-taylor-payne commented Aug 7, 2025

@tonybusa That's a good point. CSRF_TRUSTED_ORIGINS_WITH_SCHEME was introduced during the transition to Django 4, but now that the transition is over, it probably doesn't make sense to keep around. I think it would be good to have the YAML key match the variable name (i.e. CSRF_TRUSTED_ORIGINS), but we would need to give operators some notice so that they can move from using CSRF_TRUSTED_ORIGINS_WITH_SCHEME to CSRF_TRUSTED_ORIGINS...at least on the LMS side of things.

@kdmccormick kdmccormick merged commit 325a0c1 into openedx:master Aug 8, 2025
49 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in Contributions Aug 8, 2025
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants