A logic issue was addressed with improved restrictions. This issue is fixed in macOS Sonoma 14.4, macOS Ventura 13.7. An unprivileged app may be able to log keystrokes in other apps including those using secure input mode.
https://support.apple.com/kb/HT214084
https://support.apple.com/en-us/HT214084
https://support.apple.com/en-us/121234