Security Fixes - Multiple Vulnerabilities

This function is used widely in the application which leads to SQL Injection & Cross Site Scripting.