Home » Web Insights | Beau Brownlee

The Javascript Injection Problem

20 January 2009 3,363 views No Comment

What is it?

Javascript injection is a commonly ignored security issue. Basically it is the idea that you can execute javascript in your address bar, or one of the numerous plugins that accompany web browsers such as greasemonkey, to change the DOM in any way you wish. So whats the big deal? Well the bottom line is that there really shouldn’t be a big deal. This should not affect your web application in any way if you develop it right. However, there is alot of problems if you don’t understand the weakness.

A Scenario

I recently was working with a e-commerce form. The form had alot of hidden inputs and one of them being “price”. The issue with this is the fact that it is very easy to change
anything in the DOM. For instance, lets say you are a user that is using the ecommerce form to purchase something. You see in the code that you have:

  1. <form method='post' action='process.php'>
  2. <input type='hidden' name='price' id='price' />
  3. <input type='submit' value='Buy' />

Assuming (of course) there is more fields in this form; the most interesting one – as a hacker – would be the “price” field. This indicates that the processing script depends on the html field (which is coming from the client) to process the price. So we (the hacker) now have a way to change this. Simply type:

  1. javascript: document.getElementById('price').value = .01

in the address bar and hit “enter”. This changes the price from 300 to .01 and since the server script depends on this field, you will be charged 1 penny instead of $300. This is great news if your a hacker, but very bad news if your the web developer.

The Ramifications

The ramifications for a developer is that you must take care to only receive data from the client that you absolutely need from the client. There is a lot of data that should be managed by sessions or database and not be sent to the client as this could be easily be modified by anyone.

Share and Enjoy:
  • Google Bookmarks
  • TwitThis
  • Tumblr
  • Digg
  • LinkedIn
  • del.icio.us
  • Facebook
  • Mixx
  • StumbleUpon
  • blogmarks

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.