There is a request on a project which maps the following case:
The client can save Google Analytics tracking code using a page. This code then, is inserted at runtime into the master's page website dynamically.
The part of inserting the script into the master's page was an easy one. One thing that I'm struggling with is the requirement of creating a page where the user can past the Google Analytics javascript code and save it to a sql server table.
Not the page itself but the security concerns. If I let the user to input any javascript code, save it to a database, then this code is inject at runtime into the master's page, I believe there's a HUGE security breach right there.
My question is, how can I implement this with security but still let the freedom for the user to insert the script? Is there a way to check if the script inserted is a real google analytics and not some malicious script? I have done a lot of research but could not find anything usefull, so I believe SO is my last option.