Skip to content

fix: return 403 instead of redirecting from the courseware API for catalog-hidden courses - #39412

Draft
AhtishamShahid wants to merge 1 commit into
openedx:masterfrom
AhtishamShahid:ahtisham/courseware-api-catalog-visibility-403
Draft

AhtishamShahid wants to merge 1 commit into
openedx:masterfrom
AhtishamShahid:ahtisham/courseware-api-catalog-visibility-403

Conversation

@AhtishamShahid

@AhtishamShahid AhtishamShahid commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

With COURSE_ABOUT_VISIBILITY_PERMISSION = "see_about_page", a course with catalog_visibility: none makes the about-page access check raise CourseAccessRedirect for non-staff users (CatalogVisibilityError, from #38121). #38121 turned this into a 403 in the course home metadata API, but GET /api/courseware/course/<id> still answers with a 302 to /dashboard. The learning MFE follows that redirect, which fails (cross-origin on some deployments), and shows "There was an error loading this course." instead of the restricted-access message.

The redirect escapes in two places:

  • CoursewareMeta.__init__ → course_detail(): enrolled learners and anonymous users.
  • CoursewareMeta.show_courseware_link: staff using "View this course as" Learner. course_detail passes as the real staff user, but this check runs as the masqueraded learner.

Changes:

  • CoursewareInformation.get_object converts the redirect into a 403 with the access error's message, the same response as the course home metadata API.
  • show_courseware_link returns False when the user can't see the about page, instead of redirecting.

Roles affected: Learner, Course staff (masquerade).

Testing instructions

  1. Set COURSE_ABOUT_VISIBILITY_PERMISSION = "see_about_page" in LMS settings.
  2. In Studio Advanced Settings, set Course Visibility In Catalog to none for a course.
  3. As an enrolled, non-staff learner, GET /api/courseware/course/<course_id>.
    • Before: 302 → /dashboard.
    • After: 403 {"detail": "This course is not currently accessible. ..."}, the same as /api/course_home/course_metadata/<course_id>.
  4. As course staff, open the course in the learning MFE, set View this course as → Learner, and open a unit.
    • Before: the API returns 302 and the unit doesn't load.
    • After: the API returns 200 with show_courseware_link: false.
  5. As course staff without masquerade, nothing changes (200).

Tested locally on a Tutor dev stack, with the HTTP calls above and real logins. New unit tests in CourseApiCatalogVisibilityNoneTests fail without the fix (302) and pass with it. The courseware_api test suite passes.

Screenshots

Course staff, View this course as → Audit, opening a unit in a catalog_visibility: none course (local Tutor dev stack, COURSE_ABOUT_VISIBILITY_PERMISSION = "see_about_page").

Before (/api/courseware/course/ → 302 /dashboard) After (200)
before after

For an enrolled non-staff learner the page looks the same before and after: the MFE already shows the restricted-access message from the course home metadata 403. Only the courseware API response changes, from 302 to 403.

…talog-hidden courses

With COURSE_ABOUT_VISIBILITY_PERMISSION = 'see_about_page', a course with
catalog_visibility 'none' makes the about-page access check raise
CourseAccessRedirect for non-staff users. In the courseware metadata API
this escaped as a 302 to the dashboard, which the learning MFE follows
cross-origin and fails on.

Convert the redirect raised while building CoursewareMeta into a 403
carrying the access error message, matching the course home metadata
API. When staff masquerade as a learner, show_courseware_link now
returns False instead of redirecting.
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 20, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @AhtishamShahid!

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

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.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants