A Pattern Based Approach to Secure Web Applications from XSS Attacks