28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Application Filters<br />

Platform-Level <strong>Defense</strong>s • Chapter 9 389<br />

You also can implement filters in the Web application’s programming language or<br />

framework. The architecture is similar to that of Web server plug-ins: Modular code executes<br />

as requests <strong>and</strong> responses pass through a series of phases. You can use the ASP.NET System.<br />

Web.IHttpModule interface <strong>and</strong> the javax.servlet.Filter interface to implement the filter pattern.<br />

You can then add them to an application without code changes <strong>and</strong> activate them<br />

declaratively in the application configuration file. Figure 9.8 shows an example code snippet<br />

of the doFilter method of a custom J2EE Filter class. This method is called for each request/<br />

response pair due to a request for a J2EE Web resource ( JSP file, servlet, etc.).<br />

Figure 9.8 Code Snippet of a Custom J2EE Filter Class<br />

public class SqlInjDetectionFilter implements Filter {<br />

}<br />

public void doFilter(ServletRequest req, ServletResponse res,<br />

{<br />

chain filterChain) throws IOException, ServletException<br />

// Check request data for malicious characters<br />

doDetectSqlI(req, res);<br />

// Call next filter in the chain<br />

chain.doFilter(servletRequest, servletResponse);<br />

}<br />

In terms of runtime protection, application filters are really nice because they can be<br />

developed independent of the application, deployed as a st<strong>and</strong>-alone .dll or .jar file,<br />

<strong>and</strong> turned on immediately. This means this solution can be deployed more quickly in<br />

certain organizations because Web server configuration changes are not required (in many<br />

organizations, application developers do not have access to the Web servers <strong>and</strong> so must<br />

coordinate with the Web server team to make the configuration changes associated with a<br />

Web server filter). Because these filters are implemented in the same programming language<br />

as the application, they can extend or closely wrap existing application behavior. For this<br />

same reason, their utility is limited to applications built on the same framework (refer to the<br />

Tools <strong>and</strong> Traps sidebar, “Protecting Web Applications with ASP.NET <strong>and</strong> IIS,” for<br />

information on how you can overcome this limitation).<br />

Similar to Web server filters, application filters allow you to add security features, such as<br />

malicious request detection, prevention, <strong>and</strong> logging, to vulnerable Web applications. Because<br />

they can be written in feature-rich object-oriented languages such as Java <strong>and</strong> C#, they are<br />

usually less complex to code <strong>and</strong> do not introduce new vulnerability classes such as buffer<br />

overflows. OWASP Stinger <strong>and</strong> Secure Parameter Filter (SPF) are free application filters that

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!