Feeds

Aspect-oriented programming and security

Working together

Intelligent flash storage arrays

Real Example: Adding Input Validation to a Legacy Application

Of course, using AOP to its full potential on existing applications would entail a near rewrite of the application - something that is often not feasible. What should be more interesting to the security community is how to use AOP in an existing code base for security functions that are not already implemented.

Let's take a look at an existing Customer Relationship Management (CRM) application that has several Cross-site Scripting (XSS) vulnerabilities. When I try to enter in a new sales lead in one of the web forms with the description <script>alert(document.cookie)</script>.

I get:

This form is vulnerable to XSS. Since I know there are several parts to the code that share this vulnerability, I decide that I want to protect the NewLead object in the business layer by adding input validation to any time that a setter method on a String attribute is called. Here is a snippet of the NewLead class that has several setter methods:

I created the following code in programming language AspectJ, which can be easily integrated into existing Java applications - to mitigate the XSS in the application. Don't worry if this looks confusing. I'll explain the example in detail:

public aspect InputValidator-

An Aspect in AspectJ closely resembles a class. It can have instance variables and methods inside of it. There are some key differences, however, including pointcuts and advice.

pointcut myPointcut(String argument): execution(* NewLeadBean.set*(String)) && args(argument)-

A pointcut in AOP defines where we want our aspects to interact with the rest of the code. In this case, our pointcut myPoint() is invoked anytime anyone calls setName(), setSalesStage(), etc. from the NewLeadBean class. The syntax NewLead.set*(String) is intuitive: any method that is part of the NewLead class, begins with "set", and has a single string parameter.

The && args(argument) part is saying that we want to save the string parameter to a variable named argument (e.g. if somebody called myNewLeadObject.setName("rohit") then rohit would be saved to the variable argument). Pointcuts can get quite complicated - for a detailed discussion please see the AspectJ programming guide[4].

before (String argument): myPointcut(argument)

This is what we call "advice". It is saying, before the invocation of myPointcut (i.e. before NewLead.set*() is called), execute the following code. Note we could also have specified after or around (i.e. both before and after) innovation of the pointcut. The argument is the string that's passed in as a parameter. This example shows that we are taking the string argument (in our case, "rohit") and checking it to see if it passes white-list validation [7] with a regular expression checker. If I had entered in something along the lines of <script>alert(document.cookie)</script> as the name of my sales lead, I would have seen the following page on screen:

This shows that the aspect successfully stopped the attack.

Remote control for virtualized desktops

More from The Register

next story
PEAK APPLE: iOS 8 is least popular Cupertino mobile OS in all of HUMAN HISTORY
'Nerd release' finally staggers past 50 per cent adoption
Microsoft to bake Skype into IE, without plugins
Redmond thinks the Object Real-Time Communications API for WebRTC is ready to roll
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
Mozilla: Spidermonkey ATE Apple's JavaScriptCore, THRASHED Google V8
Moz man claims the win on rivals' own benchmarks
Yes, Virginia, there IS a W3C HTML5 standard – as of now, that is
You asked for it! You begged for it! Then you gave up! And now it's HERE!
FTDI yanks chip-bricking driver from Windows Update, vows to fight on
Next driver to battle fake chips with 'non-invasive' methods
DEATH by PowerPoint: Microsoft warns of 0-day attack hidden in slides
Might put out patch in update, might chuck it out sooner
Ubuntu 14.10 tries pulling a Steve Ballmer on cloudy offerings
Oi, Windows, centOS and openSUSE – behave, we're all friends here
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
Protecting users from Firesheep and other Sidejacking attacks with SSL
Discussing the vulnerabilities inherent in Wi-Fi networks, and how using TLS/SSL for your entire site will assure security.