ESDEV-2136 Port to maintenance and legacy

Moving security improvement changes from dev
(cherry picked from commit 6b572c4)