Slashdot Log In
Is Your AJAX App Secure?
Posted by
CmdrTaco
on Wed Apr 05, 2006 09:13 AM
from the something-to-think-about dept.
from the something-to-think-about dept.
ShaolinTiger writes "An article looking in detail at some of the security problems with AJAX, how to find them and how to approach them or fix them. Security with AJAX is of course an important consideration as it's asychronous and a malicious user could write data back to your database if implemented incorrectly."
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
JUG (Score:4, Insightful)
(http://slashdot.org/~eldavojohn/ | Last Journal: Tuesday October 16, @03:26PM)
In the article, he addresses a token used to generate random strings: And I think one of the most commonly used Universally Unique IDentifiers (UUID) generators is Java UUID Generator (JUG) [safehaus.org] which can be used by any type of application that can communicate with Java libraries (most apps capable of XML messaging can anyways).
Of course, this can be no better than pseudorandom [wikipedia.org] as we all remember from our courses.
Re:JUG (Score:5, Informative)
So when you're writing a command to make a request, you pass your request into your pre-written function which has any request-related security processes written into it. This way things are reasonably seamless in that you don't have to worry about security every time. I think.
ny (Score:4, Insightful)
(http://nerds.palmdrive.net/)
This is an issue that has not changed one bit since the dawn of the web: Everything that comes in your server through an HTTP(S) request is to be assumed 'insecure' by definition. The only assumption one can make about such data is that it comes from a specific user if a proper session id is provided, nothing else.
This is a very very very common misconception in almost every application I have worked on. People (devs) seems all to think that a javascript consistency check is all it takes to ensure the user will not submit an amount too high, or anything else for that matter.
The approach is flawed because of one thing: Everything that runs out of your box can be fooled with. And JavaScript is so easy to fool with that it is a shame that ANYONE would rely on any piece of JavaScript without any security/safety check on the server side.
AJAX is just another extension based on the same principle. Anyone can fool an HTTP request. Anyone can fool a Browser. Anyone can execute arbitrary Javascript code in your browser to modify its behavior: Just type the code in the address bar.
This issue is just insane!
Is Your AJAX App Secure?: As secure as any webapp. Consistency and security checks needs to be made on every data coming in your system. Short of that, it is just swiss cheese: Full of holes.
it's not secure, check out googe maps (Score:1, Funny)
Tinfoil Response (Score:4, Funny)
(Last Journal: Thursday May 05 2005, @07:40AM)
Please please please, buy a new house, or next time the Google Spyplane comes to take pictures, teepee your neighborhood with Tinfoil, I'm sure your neighbors will understand once you explain it to them.
How is this different (Score:5, Insightful)
(http://elmuerte.com/)
Re:How is this different (Score:5, Insightful)
(http://www.mjoelkbar.net/ | Last Journal: Wednesday April 20 2005, @09:29AM)
Re:How is this different (Score:5, Informative)
You are absolutely correct. The example the author provides of the .len paramter not being checked by the web app is a prime example of the kinds of problems that plague any web application, AJAX or not. Input validation, session validation, user authentication and so forth are required by EVERY web application. This part particularly irritated me:
That is true of most common methods of session management. For instance, PHP's very own built-in session management, which many people use, uses nothing more than a cookie value to manage the session. If you want to secure any web-app that uses sessions through cookies (again, AJAX or not) you'd better be using an HTTPS connection and cookies that are flagged to only be transmitted across a secure connection, and the author never touches on this point.
Add to that the whole nonsense about POST being "more secure" or "harder to fake" and it becomes clear that these are the words of a novice web programmer. And clearly this article illustrates nothing more than a web programmer's first experiences with examining the security of a web app.
But, he's linked to slashdot's main page, with plenty of AdSense links... so good for him.
semantics of GET and POST (Score:5, Insightful)
(Last Journal: Saturday November 03, @09:51AM)
Your remark really concludes this topic, and I think any further remarks are redundant. I just want to point out that in the HTTP specification (RFC 2616) section 13.9, it says the following about GET requests:
And in section 9.5, about POST requests:
Thus, the only semantic difference between GET and POST is only on side effects. There is no sense in saying one is more secure than another, or one is easier to fake than another.
If we think of a web server as a function, GET requests means that, let y1 = f(x1) and y2 = f(x2), then x1 = x2 implies y1 = y2. POST requests means there exists y1 and y2, y1 != y2, such that y1 = f(x) and y2 = f(x) for some two applications of f with x. Here y, y1 and y2 are the "web pages" (more generally, resources), and x1, x2, x are the HTTP requests.
Of course, for a practical, dynamic website, the functional property does not usually hold, and that's why we have "cahce control", which attempts to establish what functional property holds under certain conditions.
Obligatory (Score:4, Funny)
(http://aol.com/)
But we already know this... (Score:2, Insightful)
(http://www.snappyjack.com/)
I am sure that some people can learn a little about security from this article but if you learn anything new reading this, you should go to any sites you have written in the past and take them down right away because chances are you already have a security hole. I recall quite recently a friend of mine was quite shocked that his AJAX application could perform sql injection attacks on his database, on looking at his code he was entirely trusting everything that came to it, I almost slapped him for that mistake.
AJAX App Secure? (Score:3, Funny)
Code cleanliness is next to Dev godliness.
Challenges of AJAX (Score:4, Interesting)
(http://www.process64.com/)
That statement is a little misleading, as security is not directly related to requests being asynchronous. I think what the poster meant is that being asynchronous, AJAX application make lots of calls to the back end. In a non-AJAX app, typically you fetch the data during the page load. In AJAX app, users request sections of the page to be refreshed, meaning a lot more finely grained methods to the backend are exposed.
non-AJAX:
LoadMainPage()
AJAX:
LoadTitles()
LoadSections()
LoadSummary()
Enough already (Score:1, Flamebait)
(http://www.diamondcellar.com/)
And no, I'm not a hater. I personally count Ruby amongst my programming languages of choice and I have written a couple of Rails applications that my company currently has in production. But the AJAX hype is getting tired.
Isn't that always a threat? (Score:5, Insightful)
(http://www.codemonkeyramblings.com/)
Poor article. (Score:1)
Then, instead of discussing how to, i dunno, say, actually _check_ your input, it rambles through various techniques of that stalwart of crappy coders: security by obscurity.
Every solution posited finishes with "Hey, people could still crack this easily, but it makes it that bit more annoying".
Time here would be much better spent reading some Shiflett (for php newbs of the world), or any "Security goofs 101 and how to _actually_ avoid them", not this "vaguely obfuscate stuff, and use POST" recommendation.
1/10
Something new ? (Score:1)
(http://127.0.1.1/ | Last Journal: Tuesday October 03 2006, @08:10AM)
Asynchronous? (Score:2)
(http://www.alioth.net/ | Last Journal: Friday November 09, @03:53PM)
Maybe I'm stupid (Score:2)
(http://slashdot.org/)
asynchronous? (Score:2)
(http://assambassador.com/)
Sequence numbering? For sure? (Score:2)
(http://www.candysporks.org/)
How is this not security through obscurity? The only difference between guessing this sequence number and guessing the session ID in a cookie is only that of duration, but one sniff on the wire and you got it.
Overall, the hype on AJAX security stems from people not treating the AJAX requests any differently from non-AJAX requests. Trusting your input is mistake #1 regardless of where or how it comes.
And we'll rehash this entire deal in a few years when AJAX is replaced with something else of equal buzzwordthyness.
Re:Sequence numbering? For sure? (Score:4, Informative)
Not quite. The article does a horrible job in explaining it, but basically, one problem is that if an attacker can induce you to view a page containing JavaScript, that JavaScript can execute GET and POST requests under your authority.
So, for example, if the attacker knows that you use Foo Webapp, then he can put up a page on his own site that executes requests corersponding to that web application, and send you a link saying "hey, look at this!" or whatever.
Here's the thing - because it's your browser making the requests, and because those requests are going to Foo WebApp's domain, your browser will send your cookies along with the request, proving that it's you.
What this means is that you not only have to prove that it's you making the request, you also have to prove that it's a request you meant to make. User authentication alone is not enough.
The typical solution to this is to additionally include another random cookie-type value as a hidden field in every form you generate. Because your attacker doesn't have access to the pages you are viewing, he won't have access to that value, so he can't construct forms that submit that value to Foo WebApp. In this way, you can reliably determine that it's a valid form submission that comes from your own web application.
None of this, of course, is dependent upon Ajax being used. Ajax is a red herring here. This security concern applies to all web applications, whether or not they use Ajax.
POST is more secure, WTF? (Score:1)
What? (Score:1)
What difference should AJAX make with security? Zero.
All security should be applied on the server-side portion of your AJAX application. The same way any other web application is secured. End of question.
Can someone explain...? (Score:2)
-matthew
This is security advice? (Score:2)
(http://www.monkeyengines.co.uk/)
Using POST instead of GET and checking for User Agents and Referer headers won't do much to make your web application anymore secure. It's the web equivalent of hiding the keys under the doormat. Sure, it's better than leaving your door wide open, but it's not security in any meaningful sense of the word.
The way to secure AJAX is the same way classic CGI transactions are secured; through sessions, passwords and SSL.
without RTFA .... (Score:1)
(http://www.cyclomedia.co.uk/ | Last Journal: Tuesday December 12 2006, @06:48AM)
2. use regular expressions, strip out the naugty chars from your inputs where you can, like newlines, even semicolons (no one i know has a semi colon in their name, date of birth or email address), and HTML encode your data BEFORE you try to save it to your db, gets rid of the double quotes AND saves time encoding it for every page write.
3. generate unique ids. easy way: generate a long random number, and then add the date and time of the request to the end. sure the right hand half is somewhat guessable but it ensures uniqueness*, which is always handy.
4. FFS dont assume that a user will only click links, anything that comes from the get or post needs double checking against the user's permissions. a lot of security flaws have been found this way: log in, view your bank account, change the url from viewuseraccount.asp?id=1234 to viewuseraccount.asp?1235
5. dont have "website.com/admin/"
6. dont use "UPDATE" or "INSERT" or "DELETE" querys
7. etc.
*nearly, unless you get slashdotted i suppose, then i expect your server will go down before the left (random) half also provides a collision anyway
Stupid comment (Score:2)
(http://www.keirstead.org/)
The fact that it is asychronous has absolutely nothing at all to do with whether or not it has the ability to write back to the database.
You can have AJAX calls that write to the database, and ones that don't, both being asychronous. Also you can have sychronous AJAX calls (is this just "JAX"???) that write to the database.
Anyway - its pretty much the same considerations you should take when writing any web application. Verify all inputs, period.
Network security 101 (Score:4, Informative)
Without AJAX: A web application serves pages via single HTTP calls, possibly with one or more parameters, per page.
- Hackers can try getting into your system via this web application by tweaking the parameters, URL, HTTP headers, etc of the requests used to retrive pages
With AJAX: A web application serves pages via a single HTTP call, possible with one or more parameters, per page. Additionaly, JavaScript embedded in the page will, typically in response to user input, send extra HTTP requests to get more information (mostly in XML or plain text format).
- Hackers can try getting into your system via this web application by tweaking the parameters, URL, HTTP headers, etc of the requests used to retrive pages or extra information.
Same principle for both, it's just that with AJAX there is a bigger number of entry points (more "handlers" for HTTP requests) since asynchronous HTTP requests from the Javascript code also require server-side code to process those requests (and generate responses).
Can you trust that nobody will try to get into your system by hand-executing an HTTP Request to a request handler that's supposed to only be called by Javascript code? Of course not!
It's the same reason why when an HTTP form is submited to the server you still check (on the server side) the validity of the information submited for that form even though your Javascript validator also does a full validation of the form before allowing the user to submit it.
Programmers that don't implement checks on information submited to the server and/or feed it directly to interpreted language engines (such as SQL query executers) without escaping or protecting it (in some other way) will ALWAYS leave gaping security holes open, AJAX or no AJAX.
An incompetent programmer is always an incompetent programmer.
buzzword wins, flawless victory (Score:1)
(Last Journal: Wednesday August 13 2003, @07:35PM)
"AJAX" alternative? (Score:3, Interesting)
(http://www.swiftlead.com/)
BLURG is not necessarily asynchronous: you may be updating only a small part of the page, but doing it synchronously.
BLURG does not require XML. In fact you could be returning HTML, Javascript, CSV, JSON, etc.
BLURG does not even require the XmlHttpRequest feature and BLURG techniques have been in use far before the existance of this feature.
Can we please come up with a better name for BLURG, one that covers the more general programing techniques involved? Something for us people to use that is NOT just the trendy new thing known as AJAX? Something that we can use that will let others like us know that we have been aware of these techniques even before the term AJAX was coined?
For now I will call it BLURG...
Cross site request forgery (Score:3, Informative)
Most secure AJAX app evah (Score:1)
- This SQL string is submitted in a form and executed as an SQL query directly without any checks or anything.
- The db user executing the query has enough rights to read / edit / delete all databases on the server.
- Everything the query returns is serialised and passed back to JavaScript to parse and display.
That's an actual case in an actual web application, though the guy had long experience with SQL he was new with AJAX apps, so we caught that in the code audit.
Now he knows that's a Really Bad Idea to do, I wonder how many boys and girls out there don't.
I'm pretty sure... (Score:2)
(http://www.cse.unsw.edu.au/~alau/)
But most of all, samy is my hero [namb.la].
all of my servlets (Score:2)
(Last Journal: Saturday October 07 2006, @07:46PM)
AJAX like all JS should be supplimental at best (Score:1)
(http://www.nocturnal.org/)
depends on which 'side' you are on (Score:1)
Isn't that supposed to be, "...if implemented correctly"
Validation (Score:1)
(http://gospel.booleangate.org/)
While not fool proof, making sure that what you got back from the server is JSON, and not a string of malicious code is paramount.
And guess what, such things already exist [json.org].
Granted, this doesn't prevent someone from embedding that same malicious code in valid object code that appears identical to what you expect as a server result, but its a huge step in the right direction.
I have to say, stupid stupid stupid (Score:2)
(Last Journal: Wednesday January 26 2005, @05:18AM)
Browser.... asynch request
erm, questions?
The point has nothing to do with 'asynch' but more to do with programmers think that the average user cannot produce requests to these server objects easily, despite being simple http calls...
so there. all bollocks.
code to learn, right. (Score:1)
I totally agree about that.