Optimal Sanitization Synthesis for Secure Web Applications