Daniel West
Daniel West

Reputation: 1808

Guide to Securing JQuery AJAX Code?

I am creating a web application that uses JQuery's AJAX calls as it deals with all of the browser inconsistencies.

However, as the code is very much easily readable from the browser I have has concerns about what security measures I can use to protect the web application from attack.

I will be obviously doing authentication checks for the server side code to ensure that they have access to the data that they are trying to access. However, I have also been trying to look into ways of stopping CSRF attacks as well as looking into ways of 'obscuring' the code so it is not easily readable via View Source in the browser.

What steps should I be taking to ensure that security is at a good level?

Also is injecting data into a jquery script via PHP a bad idea?

Thanks!

Upvotes: 2

Views: 1339

Answers (1)

Andrew
Andrew

Reputation: 1071

There's no easy answer to your main question. You should read the OWASP guide on CSRF prevention and go from there.

And there's plenty of options out there for obfuscating javascript, but none of them will increase the security of your code. If an attacker really wanted to read your obfuscated code, he could just pick through it by hand or write a parser for it and simply de-obfuscate it. Not a viable security technique.

Also is injecting data into a jquery script via PHP a bad idea?

As long as you have no problem with the world seeing that data, no it is not a bad idea. If the data is sensitive, you'll probably want to keep it server-side, or hash it with a salt and then insert the hashed value into the script. Of course, this hash is rather unusable client-side because you must not include your salt in anything client-side (this would defeat the purpose of obfuscating the data in the first place). If you want to make use of that data, you'll need to ajax it back to your server and process it there.

Upvotes: 2

Related Questions