00:00

#0104

Admin Resource Leak

Medium+100 XPA01:2021 Broken Access ControlCWE-639
BOLAIDORAuthorizationPrivilege Escalation

Scenario

An internal notes service stores both public and admin-only notes. The getAdminNote endpoint accepts a requesting user ID and a note ID.

Notes flagged with adminOnly: true should be restricted to users with the admin role. However, the current implementation returns every note regardless of the adminOnly flag.

Regular users can read sensitive admin notes by simply guessing or enumerating note IDs.

Mixing public and privileged resources in the same endpoint without role checks is a common mistake. It allows regular users to access admin-only data simply by knowing or guessing an ID.

Your Tasks

  1. Fix getAdminNote so that adminOnly notes are only returned when the requesting user has role: 'admin'.
  2. Throw 'Forbidden' when a non-admin user requests an adminOnly note.
  3. Throw 'Not found' when the note or user does not exist.
  4. Return the note object for authorised requests.

Examples

Example 1Blocked — regular user accessing admin note

getAdminNote('alice', 'note-secret', notes, users)
// note-secret has adminOnly: true, alice has role: 'user'
// → throws Error('Forbidden')

Example 2Allowed — admin accessing admin note

getAdminNote('superadmin', 'note-secret', notes, users)
// superadmin has role: 'admin'
// → returns note object

Constraints

  • Only edit the function body — do not change the function signature.
  • Throw exactly 'Forbidden' and 'Not found'.
  • Non-adminOnly notes must remain accessible to all authenticated users.

Hint

References

solution.js
Ln 1, Col 1UTF-8JavaScript
Sandbox ready
0/0/0not run