[Security] Implement suggestion of @jakzal & add tests