Twitter tests XSS attack prevention on its mobile website
Twitter has been testing and has now implemented Content Security Policy – a new standard developed by Mozilla to block cross site scripting (XSS) attacks – on its mobile website.
How does CSP work? “In a typical XSS attack, the attacker injects arbitrary Javascript into a page, which is then executed by an end-user,” explains Twitter. “When a website enables CSP, the browser ignores inline Javascript and only loads external assets from a set of whitelisted sites. Enabling CSP on our site was simply a matter of including the policy in the returned headers under the CSP defined key, ‘X-Content-Security-Policy’.”
“The policy also contains a ‘reporting URI’ to which the browser sends JSON reports of any violations. This feature not only assists debugging of the CSP rules, it also has the potential to alert a site’s owner to emerging threats.”
The testing executed in the last few weeks revealed situations that have triggered a report without being actually malicious attempts. For example, it turns out that a number of popular Firefox extensions insert Javascript on page load and that various ISP insert Javascript or change image tags so that they point to their caching servers. Twitter resolved this triggering problem by mandating SSL for Firefox 4 users.
Twitter engineers say that this is a big step towards thwarting XSS attacks, and that they hope other browsers will follow suit and adopt the standard. In the meantime, they plan to implement it across the rest of Twitter during the incoming months. “The simple option of being able to disable inline Javascript and limit external sources gives sites the ability to stop the vast majority of today’s attacks with minimal effort,” says Twitter.