May
3rd

Testing for Security in the Age of Ajax Programming

Ajax programming is one of the most exciting new technologies in recent history. Ajax (Asynchronous Javascript and XML) allows a web page to refresh a small portion of its data from a web server, rather than being forced to reload and redraw the entire page as in traditional web programming. Since they can make frequent, small updates, web applications written with Ajax programming can present user interfaces that are more like desktop applications, which are more natural and intuitive interfaces for most users. However, just like Uncle Ben said to Peter Parker (aka Spider-Man™)(1), with great power comes great responsibility. Web applications have become prime targets for malicious users and hackers performing SQL injection and similar attacks.

The flexibility and creativity that Ajax programming affords the developer also places a corresponding burden on him to ensure that his code is secure against these new threats. Also, since delivering a secure application is part of delivering a quality application, the burden is probably felt even greater by the Quality Assurance (QA) team. The QA team will now need to develop an entirely new set of functional, performance and security testing methods in order to thoroughly test the quality of applications using Ajax programming against SQL injection attacks and other security concerns.

It’s in the Code

As an example, consider a hypothetical gourmet food e-commerce web site. This site displays a map of the world to the user, and as the user navigates the mouse pointer over each country, the page uses Ajax programming to connect back to the web server and retrieve a list of goods originating in that country. The following C# code snippet shows the web method in which the database is queried:

[System.Web.Services.WebMethod]
public System.Collections.IEnumerable GetProducts(string country)
{
// update the select command to use the country parameter
this.SqlDataSource1.SelectCommand = “SELECT * FROM [Product] WHERE Country = ‘” + country + “‘”;
// query the database and return the results
return this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
}

Some readers may notice a glaring security hole in this code. The database query is being constructed on the fly with un-validated user input being sent directly to the database. This insecure programming technique creates a vulnerability to SQL injection attacks, which are potentially devastating to the web application and its users. SQL injection vulnerabilities allow attackers to execute their own SQL queries and commands against the database, rather than those that the developers of the web site intended. The entire database, including customer names, addresses, and credit card numbers, could be downloaded by such a command. The prices of the products could be modified. The entire database itself could be permanently deleted. Clearly, this is a very serious issue. If the developer fails to notice the problem, the next line of defense is the QA team.

The average developer will probably do a quick, cursory test of the application before passing it to the QA department, without checking thoroughly for SQL injection vulnerabilities or other important problems. Instead, he will mouse over a few countries on the map, check that the displayed results match those in the database, and then pass the code off. The average QA engineer typically will be much more thorough. He will mouse over every country on the map and check that the results match. He might even set up an automated test script that will mouse over every single pixel on the screen, and he will check to see if there are any errors in the Ajax programming or underlying page code. But, even this extreme level of thoroughness won’t be enough to find the SQL injection vulnerability. By using a web browser (or automated script recorded from a web browser) as his test tool, the tester has limited his potential requests to only those which the browser can send, and the browser is itself limited by the source code of the web page. In the example above, the browser would be limited to sending only valid country parameters to the GetProducts method, since only valid countries are present in the page code. In other words, no matter where the user (or QA engineer) navigates with the mouse, the only parameters that would be sent are “GBR”, “FRA”, “USA”, etc. Using only these valid, well-formed parameters will never reveal the SQL injection vulnerability. To do that, the QA team needs to expand their arsenal of test tools beyond browsers alone.

Since browsers are so limited, hackers generally don’t use them to break into web applications or execute their SQL injection attacks and other hacks. They use tools that operate at a much lower level, tools that are capable of sending raw HTTP requests to an address and displaying the raw HTTP response. Netcat is a popular tool for this purpose, as is telnet, which has the benefit of being installed by default with virtually every modern operating system. So, instead of opening a browser, navigating to a page, and viewing the rendered HTML response, the hacker types:

nc 172.16.60.250 80 GET / HTTP/1.0

and then receives the response:

HTTP/1.1 200 OK Server: Microsoft-IIS/5.0 Date: Wed, 10 May 2006 18:04:56 GMT …

While interacting with Ajax programming may not seem like it would generate a round-trip request to the server since it doesn’t refresh the entire page, under the covers it’s doing exactly that. Like programming in standard hyperlink navigation or form submission, Ajax programming actions always have an HTTP request and response. So, armed with his low-level HTTP requestor tool, the hacker is now free to make attacks on the application that could never be possible with a browser alone. Instead of sending “GBR” or “FRA”, he could send “XXX”, or “!@#$%”, or “x’ OR ‘1′ = ‘1″, which in this case would successfully exploit the SQL injection vulnerability.

Thinking like a Hacker

In order to successfully defend against the hacker using SQL injection or some other attack, the QA engineer has to think like the hacker. Since the hacker doesn’t restrict himself to using just a browser to attack a web application (with or without Ajax programming), neither should the QA engineer use just a browser to test it. At a minimum, the application should be tested with the same type of raw HTTP tool that the hacker uses. An even better approach is to use an automated security analysis tool that performs these tests. Automated tools can make thousands of test requests in an hour; work that would take a QA engineer a week or more to perform manually. Additionally, these tools generally have an extensive set of techniques that they use to detect security defects such as SQL injection vulnerabilities QA engineers would unlikely be aware of these techniques unless they had a background in information security. There are several excellent security analysis tools available commercially.

Additional resources for learning about web application security and security analysis tools include the Web Application Security Consortium (WASC) (www.webappsec.org), the Open Web Application Security Project (OWASP)(www.owasp.org), and the SANS (SysAdmin, Audit, Network, Security) Institute (www.sans.org).
It seems likely that Web applications using Ajax programming are the future of web development. The robust user interface that web pages comprised of Ajax programming can provide represents a huge leap in usability over traditional web pages. But, this power comes with a price: the programmers and QA engineers must move beyond browsers alone when testing the application. Security vulnerabilities can lurk in code that is accessible only by specialized low-level request tools. Hackers will be more than willing to use these tools against your web applications, so your QA team must use the same tactics to find the vulnerabilities first.

May
2nd

Cross-Site Request Forgery

In order to protect websites, it is essential to know how it is going to be attacked. One such awareness is to know how to cure cross-site request forgery problem. Though website security may appear hyped, the type of attack that could be made possible justifies the security concerns.

Today let us take a look at a very simple yet effective method to prevent attack in most Ajax based websites and applications:

Cross-Site Request Forgery

When the website starts trusting the user, it is practically the end of the website’s security.
Cross-Site Request Forgery works by accessing your account through your cookie. All the hacker has to do is to embed a picture with a code so that the website will allow the hacker to perform specific actions.

There is actually a basic protection in Ajax that will prevent others from using the above hack. JavaScript by behavior does not allow any image file to be used that easy. However, most of the Ajax based websites rely on user generated content. Because of this function, developers have no choice but to execute authentication.

When you execute constant authentication it will always expose the website’s cookie. For security reasons we cannot do away with authentication and leave it open since everyone would virtually access even the most secured information. To protect the website and online application, instead of single cookie authentication, why not make it a double submit cookie authentication. This trick is possible only in an Ajax based application so hackers will have to work double time to think about the work around for this trick.

There are two ways of protecting your cookie authentication. First, developers can run simple authentication, which is usually before the post. The security measure does not end there. Once authentication has stopped, another function is launched which has stricter version of the rules. It has specific rules that virtually prohibits from suspicious looking cookies to access the website.

There is another version of cookie authentication which also ensures that the website is protected from undesirable cookies. Instead of checking for cookies as they come, developers can develop a website that cookie authentication is requested by the incoming application.

Developers are also required verify incoming cookie to have the value that the server is looking for before any request for information or function is made. This ensures that only trusted domains will access the website which has the actual value the website is looking for. The good thing about this function is that it automatically enables JavaScript in websites and functions that are trying to access the server and application. JavaScript by default will never allow any image linking much less cross-site request forgery.

These two security measures, makes sure that the website is safe enough to accept any cookies and weed out all the possible intruders. Although JavaScript does not allow image linking, there are still other ways of accessing cookie and ultimately hack the website. We will look at most of them one by one in order to protect the newest language that proves RIA could work even better.

May
2nd

History of Ajax Components

Introduction

Ajax is the acronym for Asynchronous JavaScript and XML. However, rather than functioning as an acronym it better describes a technique for producing faster, more interactive, and usable web pages that don’t require re-loading every time a user changes a request. This is accomplished by increasing web page responsive-ness through the exchange of small pieces of data by an invisible server. The prerequisites of Ajax are a collaboration of HXTML (Extensible Hypertext Markup Language), CSS (Cascading Style Sheets) that help represent the markup language, client-sided description languages like JavaScript, objects like XMLHTTPRequest that allow the asynchronous transfer of data, and the formatting provided by XML (Extensible Markup Language).
Again, Ajax is a technique, not an object. Jesse James Garrett coined Ajax in 2005 in a presentation to clients. The components that make up Ajax existed well before they were implemented to increase web page usability. This article will describe the development of the components that make up Ajax and their uses.

Background

As aforementioned, the components that provide the framework for Ajax execution include the following: 1) HXTML, that blends HTML and XML functions, 2) Cascading Style Sheets (CSS) that present markup languages intelligibly and style web content, 3) client-sided description languages like JavaScript, 4) XMLHTTPRequest objects.
HTML (Hypertext Markup Language) is the primary markup language for web pages. Markup languages represent text and extra information about the text that corresponds to structure and presentation. Originally conceived by the on-line publishing industry to interact with manuscripts, markup languages transitioned into the digital age through HTML. HTML describes the structure of certain web page text and further complements that description with interactive forms and objects that affect web browser behavior.
XML (Extensible Markup Language) is considered a general-purpose markup language. XML is an open, standard language that facilitates data sharing across information systems, particularly those connected via the Internet. The latest version of HXTML 1.1 became a W3C (World Wide Web Conference) recommendation and, therefore, an industry standard in 2001.
CSS (Cascading Style Sheets) display the presentation of markup written document. This style sheet language, which is also standardized by W3C, presents structured documents whose content is reusable in a variety of contexts. Content can be attached to different logics to create different presentations of the same data. Style sheets have existed since the 1970’s and SGML (Standard Generalized Markup Language). CSS Level 1 became usable in 1996. By 1998, CSS Level 2 was W3C recommended. As of 2006, CSS Level 3 is still under development. The main CSS contribution allows a document’s style to be influenced by multiple style sheets. The cascading effect comes from the ability of style sheets to ‘cascade’ from one another, inheriting a stylistic mixture determined by the site designer and user.
Javascript is a scripting language created to enable prototype-based programming. It is most popularly used for web sites. Its only similarity with Java the programming language is its C syntax. Javascript was developed in 1995 and trademarked by Sun Microsystems. It was licensed for use with Netscape Communications when Netscape began to support Java technology in its Netscape Navigator web browser. Currently, Javascript also operates for other entities like the Mozilla Foundation. As of 2006, the latest model of this scripting language is Javascript 1.7.
XMLHTTPRequest object allows for the asynchronous exchange of data between the server and the client. It is an API (application program interface) that uses Javascript to transfer text data like XML using HTTP (hypertext transfer protocol) thereby establishing independent communication between the server-side and client-side of a web page. Microsoft developed it in 2000 as a part of Outlook Web Access. Mozilla incorporated XMLHTTPRequest in 2002 and Apple incorporated it into Safari 2.1 soon after.

Uses

The uses of these Ajax components work together to allow for automatic, user-based alterations of web pages. As an application of HTML in XML, XHTML allows for automated web processing through the use of the standard XML library. CSS is primarily used to stylize web pages and making them more easily understandable to users. Javascript allows accessibility to the DOM (Direct Object Model) to allow for dynamic information presentation and increased interactivity. The DOM is a standard object model that renders HTML, XML and other related formats. XMLHTTPRequest is important in Ajax web development techniques to increase web page responsiveness and interactivity. For example, it is currently used in Google’s Gmail services and MapQuest among other highly interactive sites.

Points of Interest

The technologies outlined above work together to comprise Ajax programming. The primary benefits of this suite of technologies allow users to access and create web applications more quickly with a level of responsiveness usually attributed to desktop applications. This increased responsiveness is coupled with increased interactivity that doesn’t make it necessary for the web page to reload every time a user makes a new request of the web application.

May
1st

Enhancing JSON Security

More and more Ajax developers are choosing JSON for their data transfer instead of XML. Although XML has been the pillar of Ajax (X is for XML), JSON has become the choice of most developers because it was particularly built for JavaScript. Compared to XML, JSON is lighter and will work faster compared to XML. This lightweight function enables Ajax based websites and applications to run faster.

The reason why JSON is very efficient in data transmission is its ability to function in itself. By this function we mean that JSON has the ability to “EXECUTE” without the aid of other functions. XML is only a format which will be used to transmit data and files, but JSON is very effective in terms self execution.

Instead of using additional codes and functions from the framework and the server, JSON will basically work on itself and EXECUTE when available. The combination of JavaScript and JSON wherein they function independently and work at the same time makes JSON a perfect pairing for Ajax.

However, the fact that JSON is self executing has made JSON one of the most popular tools for hacking Ajax websites and applications. In previous blogs, we have pointed out one of the biggest problems in Ajax is Cross Site Request Forgery or CSRF. With this function, the hacker has the ability to control not only the data of the program but with the general functions as well. All the hacker has to do is to upload a file with a malicious JSON code and let it run through. In no time at all, JSON should be able to access the server and take over the controls and functions of the applications.

When you opt to use JSON in your Ajax based site or application, be sure to build JSON in a very secure environment. You have to use this especially when your application’s content is based on the user uploads. Anyone who has basic knowledge of JSON and simple application could easily hack the system and extract the content of your server and objects transmitted.

To ensure your JSON is secured, consider registering the types of JavaScript class that goes inside your system. The server will screen everything that goes in and if something is not according to the class that you specified, it will flag and will give you the ability to review the incoming content.

Another trick that you can use in your JSON is to register it according to the class type you specified and then brace it with another function. Imagine JSON being wrapped with another function so that it will not be detected by the hacker. They will just keep on guessing the exact class of JSON you will be using which could take forever. You will have to manually encode each JSON which could take some time. However, considering the security it will add, the time spent in securing data is worth it.

Always secure your JSON, it is the most convenient data mark-up you will use but it is prone to different security problems that you should cover up before implementation.

May
1st

Ajax Frameworks

Introduction

Ajax frameworks support Ajax technologies to build dynamic, client-side web sites. On dynamic web pages, users can make requests of a database contained on a server. Within an Ajax framework the data is sent to or read by the server through the use of JavaScript. This allows users to make specific requests that are processed and implemented using dynamic factors like specific user input, time of day or search history to determine the content of the web page. While Ajax is primarily a client-side set of technologies, the Ajax framework facilitates server-side processing such as the finding and storage of data. The goal of the Ajax framework is to function as a communication layer between user and server. This framework, which is specially designed to handle Ajax requests, lets Ajax perform its function of reducing user wait time while the web page accesses the server.
This article will discuss the development of the Ajax framework as described by Jesse James Garrett, the man who gave it its name. A brief description of different types of frameworks will follow. This discussion will define direct Ajax frameworks, Ajax component frameworks, and server-driven Ajax frameworks. Finally, this article will suggest other Ajax frameworks that are server independent.

Background

In 2005, Jesse James Garret wrote an article for his company Adaptive Path entitled “Ajax: A New Approach to Web Applications” where the components and goals of Ajax were defined. In it, he describes the discrepancy between desktop applications and web applications. The impetus behind Ajax was to provide web pages with the technology to make them as rich and responsive as desktop applications. The most powerful real-time manifestation of this responsiveness is how Ajax technologies don’t require complete web page reloading every time a new request is made or new data is entered. J.J. Garret defines Ajax as many existing technologies powerfully coming together to create a new user experience.
The components include the following: 1) a presentation based on industry standards using XHTML (Extensible Hypertext Markup Language) and CSS (Cascading Style Sheets). 2) Dynamic and interactive application of DOMs (direct object model). A DOM is a standardized API (application programming interface) that, when implemented in a web browser, allows scripts to access browser elements. DOMs are particularly useful when updating the content, structure and style of HTML or XML documents. 3) Data, contained in databases, must be employed and available for communication and execution of requests. 4) XMLHttpRequest objects conduct asynchronous data retrieval. 5) JavaScript is required to bind all requests so they are intelligible across all Ajax components and multiple platforms.
Ajax frameworks are designed to support these technological requirements and requests. A framework facilitates Ajax programming because for the client uses the highly intelligible and translatable JavaScript to make requests of the server. Meanwhile it searches data, processes request and communicates them to the server through the browser.

Uses

There are three main types of Ajax frameworks. The first are “direct object frameworks”. The second types are “Ajax component frameworks”. The third types are “server driven Ajax frameworks”. The following is a brief description of each one.
Direct object frameworks are usually smaller than the rest. They are used primarily for web site development as opposed to web application development. This is the difference between, for example, on-line shopping site versus a web application like web-based e-mail. Developers must command Ajax, HTML and CSS in this framework, since developers design the pages in HTML and the framework deals with APIs (application programming interfaces) written in HTML. These APIs facilitate communication across browsers.
Ajax component frameworks are larger and generally apply to web applications. They use pre-made components to generate and apply HTML. Ajax component frameworks allow for more rapid development and require less control. Certain structures like grids and tabs are provided, but user input forms must be written in HTML/CSS through Ajax techniques. Other incarnations of this framework only require general XML or JavaScript literacy. Component frameworks provide customized APIs, allow dynamic program control based on user input, and create new components based on existing ones.
Server-driven Ajax frameworks use components developed by the server using server-side languages. User requests are communicated to the server through Ajax techniques. This requires the developer to be literate in both Ajax and server-side code. These frameworks are more useful for server-side developers. However, they can be busy and overloaded since one function may require many server-side requests. Frameworks running through browsers, unlike server-driven frameworks, provide greater scalability. Server-driven frameworks require developers to know which parts of the presentation the client handles and which are handled by the server. JavaServer Faces and Google’s GWT (Google Web Toolkit) are examples of server-driven frameworks.

Points of Interest

Ajax frameworks provide a complete library to construct web applications through the Ajax engine, i.e. the suite of technologies that facilitates communication between user requests and server without the lag-time and work it takes to re-load the entire page. Other types of Ajax frameworks include JavaScript and server technology independent frameworks, .NET frameworks, and PYTHON frameworks.