I'm trying to find if there's a good way to prevent CSRF on a javascript widget embedded on customers' websites.
The widget would enable end users to make requests against our customers' accounts via JSONP to a a PHP server which proxies those requests to our (non-public) API.
To this point, I haven't come up with a surefire way to ensure all requests are coming from only our customers' websites. Some ideas I've had:
- Tokens generated on the server side and passed back along with each subsequent JSONP request (not sure how to authenticate the initial request though, since the first token would be readable in JS and anyone could request the 'next' token)
- Checking the Referer header (unreliable, can be spoofed or simply not passed by the browser)
- Using SSL (would of course help but not solve the problem of CSRF)
Is this at all possible? I've come across Fotomoto's widget which seems to allow the same type of functionality we are looking for, but am not sure how they're doing it.