Blog Feed Post

20 Lines or Less #53: Security, Security & more Security

What could you do with your code in 20 Lines or Less? That's the question I ask (sometimes?) every week for the DevCentral community, and every week I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting in over your head.

This week we've got three awesome examples of iRules that are designed to increase your application's security in less than 21 lines of code. Dealing with header size, cache control, and a Microsoft advisory, we get to see a couple of different ways in which iRules can save the day. This isn't a new theme. iRules can be an amazingly powerful security resource in the hands of someone with the security mindset to be aware of what is going on, and the F5/iRules knowledge to craft the solutions necessary to put in place the preventative measures necessary to thwart incoming attacks.

Preventing Overzealous Headers


To work around a recently released bug that allowed attackers to exploit excess parameters in an HTTP request, Aaron whipped up an iRule to count the parameters. User Wizdem had an excellent start, looking through the payload, but Aaron and Jason teamed up to make it more efficient and expanding it to look through the query string as well. If either of these have more than 100 parameters, it drops the request, assuming it to be an attack. Given that most requests shouldn't have anywhere near 100 parameters, that should be a pretty safe assumption, but your mileage may vary, as always. A very slick look at an iRule protecting against a known attack in a short period of time with only a few lines of code. This one looks longer than it is. Take out white space, comments, and log lines and you end up at 20. Honest.

   1: when HTTP_REQUEST {
   3:     # Check if the query string contains more than 100 parameters
   4:     if { [llength [split [HTTP::query] &]] > 100 } {
   5:         log local0.alert "Microsoft Security Advisory (2659883)\
   6:             IP Address [IP::client_addr]:[TCP::client_port] requested [HTTP::uri]"
   8:         # Drop the request
   9:         drop
  10:         return
  11:     }
  13:     # Collect up to 1Mb of POST data
  14:     if { [HTTP::method] equals "POST"}{ 
  15:         set clength 0
  16:     if {[HTTP::header "Content-Length"] ne "" && [HTTP::header "Content-Length"] <= 1048576 && [HTTP::header "Content-Length"] > 0}{ 
  17:            set clength [HTTP::header Content-Length]
  18:         } else { 
  19:             set clength 1048576 
  20:         }
  21:         HTTP::collect $clength
  22:     }
  23: }
  25: when HTTP_REQUEST_DATA {
  27:     # Check if the collected payload contains more than 100 parameters
  28:     if { [llength [split [HTTP::payload] &]] > 100 } {
  29:         log local0.alert "Microsoft Security Advisory (2659883)\
  30:             IP Address [IP::client_addr]:[TCP::client_port] requested [HTTP::uri]"
  32:         # Drop the request
  33:         drop
  34:     }
  35: }

Header Size Restrictions


Similar yet different, in this snippet the size of each header is inspected to ensure it is not over 1000 characters. While this is not necessarily a malicious attack it was causing problems for the OP in the thread, and Aaron was kind enough to lend an updated version to log the header lengths as they come through, since this thread was brought back up recently. In this incarnation the rule is only logging but it would be trivial to modify it to drop requests as necessary if you experience a particular client attempting to send through egregiously large headers in an attempt to cause problems.

   1: when HTTP_REQUEST {
   3:     # Check the total HTTP headers size
   4:     if {[string length [HTTP::request]] > 10000 }{
   6:         # Loop through the headers by name
   7:         foreach header {[HTTP::header names]} { 
   9:             # Check for a long header value
  10:             if {[string length [HTTP::header value $header]] > 1000 } { 
  11:                 log local0. "Header is long. Header Name: $header,\
  12:                     Length: [string length [HTTP::header value $header]], Value: [HTTP::header value $header]" 
  13:             }
  14:         }
  15:     }
  16: }

No-Cache ... For Real


In this post user Joanna shares the problem she's facing with us

"The problem is that Google Chrome will cache, in the current sessions memory only,  responses which have had the no-cache directive applied.  This means that after a user logs out of an application and walks away,  another user can come up to the computer,  press the back arrow and potentially see private information.  The way round this is to use the no-store directive with a couple of other headers thrown in for good measure. "

That is less than optimal...a browser that refuses to respect no-cache headers for secure pages. I'm not sure in what environments or across which versions this applies, but having a fix readily available is a good thing. Fortunately Joanna was kind enough to provide exactly that. With this simple iRule she was able to more firmly enforce her caching directives and create a more secure application in the process.

   1: when HTTP_RESPONSE {
   2:     # The purpose of this iRule event processing is to force no-store so that browsers will not store this content
   3:     # which would enable users to hit the 'back' button,  even after a logout,  and potentially see customer PII
   6:     if {[HTTP::header Content-Type] contains "html"} {
   7:         HTTP::header insert Pragma "no-cache"
   8:         HTTP::header insert Expires "Fri, 01 Jan 1990 00:00:00 GMT"
   9:        HTTP::header replace Cache-Control "no-cache,no-store,must-revalidate"
  10:     }
  11: }

There you have it, <= 60 lines of code to help make your iRuling life better, more interesting and in this case more secure, too. More iRules goodness is sure to follow in coming weeks.


Read the original blog entry...

More Stories By Colin Walker

Coming from a *Nix Software Engineering background, Colin is no stranger to long hours of coding, testing and deployment. His personal experiences such as on-stage performance and the like have helped to foster the evangelist in him. These days he splits his time between coding, technical writing and evangalism. He can be found on the road to just about anywhere to preach the good word about ADCs, Application Aware networking, Network Side Scripting and geekery in general to anyone that will listen.

Colin currently helps manage and maintain DevCentral (http://devcentral.f5.com). He is also a contributor in many ways, from Articles to Videos to numerous forum posts, to iRules coding and whatever else he can get his hands on that might benefit the community and allow it to continue to grow.

Latest Stories
So the dumpster is on fire. Again. The site's down. Your boss's face is an ever-deepening purple. And you begin debating whether you should join the #incident channel or call an ambulance to deal with his impending stroke. Yes, we know this is a developer's fault. There's plenty of time for blame later. Postmortems have a macabre name because they were once intended to be Viking-like funerals for someone's job. But we're civilized now. Sort of. So we call them post-incident reviews. Fires are ne...
Lori MacVittie is a subject matter expert on emerging technology responsible for outbound evangelism across F5's entire product suite. MacVittie has extensive development and technical architecture experience in both high-tech and enterprise organizations, in addition to network and systems administration expertise. Prior to joining F5, MacVittie was an award-winning technology editor at Network Computing Magazine where she evaluated and tested application-focused technologies including app secu...
CloudEXPO New York 2018, colocated with DevOpsSUMMIT and DXWorldEXPO New York 2018 will be held November 12-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI and Machine Learning to one location.
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of computational needs for many industries. Their solutions provide benefits across many environments, such as datacenter deployment, HPC, workstations, storage networks and standalone server installations. ICC has been in business for over 23 years and their phenomenal range of clients include multinational corporations, universities, and small busines...
This sixteen (16) hour course provides an introduction to DevOps, the cultural and professional movement that stresses communication, collaboration, integration and automation in order to improve the flow of work between software developers and IT operations professionals. Improved workflows will result in an improved ability to design, develop, deploy and operate software and services faster.
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
Authorization of web applications developed in the cloud is a fundamental problem for security, yet companies often build solutions from scratch, which is error prone and impedes time to market. This talk shows developers how they can (instead) build on-top of community-owned projects and frameworks for better security.Whether you build software for enterprises, mobile, or internal microservices, security is important. Standards like SAML, OIDC, and SPIFFE help you solve identity and authenticat...
The digital transformation is real! To adapt, IT professionals need to transform their own skillset to become more multi-dimensional by gaining both depth and breadth of a wide variety of knowledge and competencies. Historically, while IT has been built on a foundation of specialty (or "I" shaped) silos, the DevOps principle of "shifting left" is opening up opportunities for developers, operational staff, security and others to grow their skills portfolio, advance their careers and become "T"-sh...
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
Hackers took three days to identify and exploit a known vulnerability in Equifax’s web applications. I will share new data that reveals why three days (at most) is the new normal for DevSecOps teams to move new business /security requirements from design into production. This session aims to enlighten DevOps teams, security and development professionals by sharing results from the 4th annual State of the Software Supply Chain Report -- a blend of public and proprietary data with expert researc...
DXWorldEXPO LLC announced today that Nutanix has been named "Platinum Sponsor" of CloudEXPO | DevOpsSUMMIT | DXWorldEXPO New York, which will take place November 12-13, 2018 in New York City. Nutanix makes infrastructure invisible, elevating IT to focus on the applications and services that power their business. The Nutanix Enterprise Cloud Platform blends web-scale engineering and consumer-grade design to natively converge server, storage, virtualization and networking into a resilient, softwar...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...