Summary
The Moodle Custom Certificate plugin contains an insecure direct object reference that lets a teacher with mod/customcert:manage capability in any one course read and overwrite certificate elements from other courses.
By passing arbitrary element IDs to specific callbacks and web services, an attacker can silently access or tamper with certificates outside their authorized course context, leading to cross-course information disclosure and data integrity violations.
Affected context
This vulnerability occurs in Moodle installations using the Custom Certificate (moodle-mod_customcert) plugin where:
- Teachers are granted the
mod/customcert:managecapability in at least one course - The
core_get_fragmentcallbackeditelementandmod_customcert_save_elementweb service are exposed as part of normal plugin operation - Backend logic assumes that a valid element ID is sufficient to authorize access, without confirming that the element belongs to the teacher's current course context
In such setups, any user with manage permissions for certificates in one course may be able to interact with certificate elements belonging to other courses.
Exploit preconditions
- Attack surface: Moodle web UI and web service endpoints exposed by the Custom Certificate plugin.
- Required access: An authenticated user with the
mod/customcert:managecapability in at least one course. - Trigger point:
- Invoking the
editelementcore_get_fragmentcallback while supplying anelementidfrom another course. - Calling the
mod_customcert_save_elementweb service with anelementidthat belongs to a different course. - Why exploitation is possible: The server-side handlers trust the provided
elementidand do not enforce that it belongs to the course context in which the user is authorized. As a result, authorization is checked only at the capability level and not bound to the specific resource, creating an insecure direct object reference (CWE-639).
Why this happens
The core bug is a missing contextual authorization check on resource identifiers (certificate element IDs) in server-side logic.
Instead of confirming that the elementid being accessed or modified belongs to a course where the user holds the relevant capability, the code treats any valid elementid as accessible once the user has mod/customcert:manage somewhere.
This maps directly to CWE-639: Authorization Bypass Through User-Controlled Key, where object-level access control is tied to a user-supplied identifier without verifying that the object resides in a context the user is permitted to access.
The abstract pattern is: "Check who the user is and what general role they have, but fail to check which specific object they are trying to access."
Potential impact
- A teacher may read certificate element configuration from courses they are not assigned to.
- Certificate layouts, text, and other element data in unrelated courses can be silently overwritten.
- Cross-course leakage of sensitive or exam-related certificate content may occur.
- Integrity of certificates across the Moodle site can be compromised, undermining trust in issued credentials.
- Administrative overhead due to undetected or difficult-to-trace certificate modifications in multiple courses.
General mitigation guidance
Effective mitigation focuses on enforcing strict object-level authorization and reducing reliance on user-controlled identifiers:
- Ensure every access to a certificate element first resolves it in a context-bound way (e.g., load element, then verify it belongs to a course where the user holds the required capability before proceeding).
- Centralize authorization checks for plugin entities so all read/write operations go through a single, well-reviewed access-control layer.
- Avoid treating numeric or opaque IDs from the client as sufficient evidence of access; always re-derive the relevant context (course, module instance) on the server.
- Prefer design patterns where the course or module context is derived from the session or URL structure and used to constrain the set of valid resource IDs.
- Apply the principle of least privilege to Moodle roles and capabilities, granting
mod/customcert:manageonly where necessary and auditing its use regularly.
How teams detect issues like this
Organizations can detect and monitor for similar authorization weaknesses through:
- Static analysis: Rules that flag controller or web-service functions which:
- Accept object IDs (
elementid,id, etc.) from clients. - Perform read/write actions on those objects without verifying their association with a context where the user has explicit capability.
- Code review patterns: During plugin or customization reviews, look for:
- Direct database lookups by ID followed immediately by business logic without subsequent context checks.
- Access control that only checks roles or capabilities at a high level, not tied to the specific course or module instance.
- Runtime monitoring: Log and periodically review cross-course access patterns such as:
- A single user editing certificate elements associated with many unrelated courses.
- Anomalous spikes in updates to certificate elements across courses.
- Automated policy enforcement: Incorporate Moodle-specific security linting or general authorization-check patterns into CI pipelines so newly introduced handlers and web services are checked for object-level access control.

