This issue was addressed with additional entitlement checks. This issue is fixed in macOS Sonoma 14.5, macOS Ventura 13.6.7, macOS Monterey 12.7.5, iOS 16.7.8 and iPadOS 16.7.8. An unprivileged app may be able to log keystrokes in other apps including those using secure input mode.
https://support.apple.com/kb/HT214107
https://support.apple.com/kb/HT214106
https://support.apple.com/kb/HT214105
https://support.apple.com/kb/HT214100
https://support.apple.com/en-us/HT214107
https://support.apple.com/en-us/HT214106