Refactor JS injection protection