The vulnerability arises from the handling of the 'returnurl' parameter. In the vulnerable versions, cohort/upload_form.php's cohort_upload_form::definition() function explicitly added a hidden 'returnurl' form field (with PARAM_URL type) that accepted user-controlled input. This parameter was then passed to cohort/upload.php, where it was used to construct a redirect URL without proper validation. The PARAM_URL type alone does not enforce internal URL restrictions, allowing external redirects. The patch removed this field entirely, confirming its role in the vulnerability. While upload.php's parameter retrieval (optional_param('returnurl')) was part of the chain, the root cause lies in the form's exposure of this unvalidated parameter.