Repository navigation
Description
Description
Duplicating a block from another course writes the new block into the source course and attaches it as a child of a parent in a different course. This bypasses access checks and leaves a cross-course reference that cannot be loaded or deleted. It is backend only and needs a direct API call.
Current Behavior
Two problems:
- With authz enabled, nothing checks access to the source course. The read check on the source only runs on the legacy path (
view_handlers.py:362-366). duplicate_blockbuilds the new key from the source location (contentstore/utils.py:1132:source_item.location.replace(name=uuid4().hex)), so the new block is created in the source course and then attached to a parent in another course. The resulting structure fails to load and to delete (KeyError). The same happens when duplicating a v1 library block into a course.
Expected Behavior
- The duplicated block is created in the destination course (the parent's course), never in the source course. The source course is left unchanged.
- The user must have view access on the source course and write access on the destination, in both modes (AuthZ and legacy). A user who can edit the destination but cannot view the source gets
403. - Duplicating a v1 library block into a course creates the copy in the course. Previously it returned
200but created the copy in the library and left the course with a dangling child. - Same-course duplication keeps working as before.
Steps to reproduce
This cannot be reproduced from the Studio UI, because the Duplicate button always sends a source and a parent from the same course. It needs a direct request to POST /xblock/ on the Studio (CMS) host.
Setup
- Create two courses, course A and course B (e.g.
course-v1:SandboxOrg01+DemoX01A+2026_T1andcourse-v1:SandboxOrg02+DemoX02A+2026_T1). - In course A, add a section, subsection, unit and an HTML component. Copy the component's usage key:
block-v1:SandboxOrg01+DemoX01A+2026_T1+type@html+block@<HTML_A>. - In course B, add a section, subsection and unit. Copy the unit's usage key:
block-v1:SandboxOrg02+DemoX02A+2026_T1+type@vertical+block@<VERTICAL_B>. - Create a user
userb, not a superuser and not global staff. Make sure it has no legacy course role (Staff/Instructor) in either course, no org-level role, and no authz role in course A. - Enable authz on the platform: turn on the waffle flag
authz.enable_course_authoringglobally (Django admin,Waffle flags, set it to Everyone / On). - Assign
userban authz role in course B only that allows editing content, for example Course Editor. The role must be granted through authz (Admin Console / authz API), not from the legacy course team page.
Send the request
-
Send the following request to the Studio (CMS) host, authenticated as
userb:-
Endpoint:
POST http://studio.local.openedx.io:8001/xblock/ -
Headers:
Content-Type: application/json -
Body:
{ "parent_locator": "block-v1:SandboxOrg02+DemoX02A+2026_T1+type@vertical+block@<VERTICAL_B>", "duplicate_source_locator": "block-v1:SandboxOrg01+DemoX01A+2026_T1+type@html+block@<HTML_A>" }
Replace
<VERTICAL_B>and<HTML_A>with the keys from the setup.Note: for the request to work, two cookies of
userbmust be added to the request, copied from the browser (DevTools → Application → Cookies, on the Studio domain after logging in to Studio):studio_session_id: the Studio session cookie. Without it the request is anonymous ([user None]in the CMS logs) and fails.csrftoken: the CSRF cookie. Its value must also be sent in theX-CSRFTokenheader. Without it Studio rejects the request with403 CSRF cookie not set.
-
Observed
- The response is
200with a newlocator, even thoughuserbhas no access to course A. - Open course B: the course fails to load, with
ItemNotFoundErrorfor that block in the CMS logs, because the unit lists a child that does not exist in B's structure. - Trying to delete the block from the unit raises
KeyError.
Control (legacy path)
- Turn the flag
authz.enable_course_authoringoff. With the flag off, authz roles are ignored, so giveuserbthe legacy Staff role in course B (from the course team page) to pass the destination check. Make sureuserbstill has no legacy role in A (no direct, org-level or global role), and repeat step 7. The request returns403, becausehas_studio_read_accesson course A fails (view_handlers.py:362-366).
Acceptance Criteria
- The duplicated block key is built in the parent's course (or library), not in the source's.
- Duplicating requires view access on the source course:
courses.view_coursewhen AuthZ is enabled for it,has_studio_read_accessotherwise (including v1 libraries, which AuthZ does not cover). - Write access on the destination is still required.
- A user without view access on the source gets
403, and no block is created in the source or the destination. - Cross-course duplication by a user with the required access creates the block in the destination course, which loads and can be deleted, and leaves the source unchanged.
- Duplicating a v1 library block into a course creates the copy in the course.
- Same-course duplication keeps working with and without AuthZ.
- Tests are added or updated.
Proposed Solution
- In
duplicate_block(cms/djangoapps/contentstore/utils.py), builddest_usage_keyfrom the parent's course or library instead of the source location. - In the xblock handler (
xblock_storage_handlers/view_handlers.py), add_check_duplicate_source_view_access, which checkscourses.view_courseon the source when AuthZ is enabled for it, andhas_studio_read_accessotherwise. - Keep the existing write-access check on the destination.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix: reject duplicating xblocks across courses
fix: reject duplicating xblocks across courses
fix: create duplicated xblocks in the destination course
fix: create duplicated xblocks in the destination course
fix: create duplicated xblocks in the destination course
fix: create duplicated xblocks in the destination course
[-]Reject duplicating XBlocks across courses[/-][+]Duplicating XBlocks across courses creates the block in the source course[/+]fix: create duplicated xblocks in the destination course
fix: create duplicated xblocks in the destination course
fix: create duplicated xblocks in the destination course (#39409)