Description
Choose the permission passed to Subject.isPermitted, checkPermission or checkCallingOrSelfPermission from the operation and target. A permission name taken from the request may check the wrong permission.
Potential impact
A caller who passes the wrong check may gain access to internal functions or protected data.
Remediation
Use a constant permission for a fixed operation. If part of the name must vary, check request parameters, Intent extras or IPC input against an allow-list. Verify the caller’s UID, package or signature where the platform requires it.
Examples
Before
String action = request.getParameter("action");
if (subject.isPermitted("account:read:" + action)) {
doIt();
}
After
String action = request.getParameter("action");
if (Set.of("profile", "settings").contains(action)
&& subject.isPermitted("account:read:" + action)) {
doIt();
}
The example accepts profile and settings. Reject a missing action before calling contains on the set from Set.of. The operation and object used in doIt() must match the permission checked.