ADC

Cookie consistency check

The Cookie Consistency check examines cookies returned by users to verify that they match the cookies that your website set for that user. If a modified cookie is found, it is stripped from the request before the request is forwarded to the web server. You can also configure the Cookie Consistency check to transform all of the server cookies that it processes, by encrypting the cookies, proxying the cookies, or adding flags to the cookies. This check applies to requests and responses.

An attacker would normally modify a cookie to gain access to sensitive private information by posing as a previously authenticated user, or to cause a buffer overflow. The Buffer Overflow check protects against attempts to cause a buffer overflow by using a long cookie. The Cookie Consistency check focuses on the first scenario.

If you use the wizard or GUI, in the Modify Cookie Consistency Check dialog box, on the General tab you can enable or disable the following actions:

  • Block
  • Log
  • Learn
  • Statistics
  • Transform. If enabled, the Transform action modifies all cookies as specified in the following settings:
    • Encrypt Server Cookies. Encrypt cookies set by your web server, except for any listed in the Cookie Consistency check relaxation list, before forwarding the response to the client. Encrypted cookies are decrypted when the client sends a subsequent request, and the decrypted cookies are reinserted into the request before it is forwarded to the protected web server. Specify one of the following types of encryption:
      • None. Do not encrypt or decrypt cookies. The default.
      • Decrypt only. Decrypt encrypted cookies only. Do not encrypt cookies.
      • Encrypt session only. Encrypt session cookies only. Do not encrypt persistent cookies. Decrypt any encrypted cookies.
      • Encrypt all. Encrypt both session and persistent cookies. Decrypt any encrypted cookies. Note: When encrypting cookies, the Web App Firewall adds the HttpOnly flag to the cookie. This flag prevents scripts from accessing and parsing the cookie. The flag therefore prevents a script-based virus or trojan from accessing a decrypted cookie and using that information to breach security. This is done regardless of the Flags to Add in Cookies parameter settings, which are handled independently of the Encrypt Server Cookies parameter settings.
  • Proxy Server Cookies. Proxy all non-persistent (session) cookies set by your web server, except for any listed in the Cookie Consistency check relaxation list. Cookies are proxied by using the existing Web App Firewall session cookie. The Web App Firewall strips session cookies set by the protected web server and saves them locally before forwarding the response to the client. When the client sends a subsequent request, the Web App Firewall reinserts the session cookies into the request before forwarding it to the protected web server. Specify one of the following settings:
    • None. Do not proxy cookies. The default.
    • Session only. Proxy session cookies only. Do not proxy persistent cookies Note: If you disable cookie proxying after having enabled it (set this value to None after it was set to Session only), cookie proxying is maintained for sessions that were established before you disabled it. You can therefore safely disable this feature while the Web App Firewall is processing user sessions.
  • Flags to Add in Cookies. Add flags to cookies during transformation. Specify one of the following settings:
    • None. Do not add flags to cookies. The default.
    • HTTP only. Add the HttpOnly flag to all cookies. Browsers that support the HttpOnly flag do not allow scripts to access cookies that have this flag set.
    • Secure. Add the Secure flag to cookies that are to be sent only over an SSL connection. Browsers that support the Secure flag do not send the flagged cookies over an insecure connection.
    • All. Add the HttpOnly flag to all cookies, and the Secure flag to cookies that are to be sent only over an SSL connection.

If you use the command-line interface, you can enter the following commands to configure the Cookie Consistency Check:

  • set appfw profile <name> -cookieConsistencyAction [**block**] [**learn**] [**log**] [**stats**] [**none**]
  • set appfw profile <name> -cookieTransforms ([**ON**] | [**OFF**])
  • set appfw profile <name> -cookieEncryption ([**none**] | [**decryptOnly**] | [**encryptSession**] | [**encryptAll**])
  • set appfw profile <name> -cookieProxying ([**none**] | [**sessionOnly**])
  • set appfw profile <name> -addCookieFlags ([**none**] | [**httpOnly**] | [**secure**] | [**all**])

To specify relaxations for the Cookie Consistency check, you must use the GUI. On the Checks tab of the Modify Cookie Consistency Check dialog box, click Add to open the Add Cookie Consistency Check Relaxation dialog box, or select an existing relaxation and click Open to open the Modify Cookie Consistency Check Relaxation dialog box. Either dialog box provides the same options for configuring a relaxation.

Following are examples of Cookie Consistency check relaxations:

  • Logon Fields. The following expression exempts all cookie names beginning with the string logon_ followed by a string of letters or numbers that is at least two characters long and no more than fifteen characters long:

     ^logon_[0-9A-Za-z]{2,15}$
     <!--NeedCopy-->
    
  • Logon Fields (special characters). The following expression exempts all cookie names beginning with the string türkçe-logon_ followed by a string of letters or numbers that is at least two characters long and no more than fifteen characters long:

     ^txC3xBCrkxC3xA7e-logon_[0-9A-Za-z]{2,15}$
     <!--NeedCopy-->
    
  • Arbitrary strings. Allow cookies that contain the string sc-item_, followed by the ID of an item that the user has added to his shopping cart ([0-9A-Za-z]+), a second underscore (_), and finally the number of these items he wants ([1-9][0-9]?), to be user-modifiable:

     ^sc-item_[0-9A-Za-z]+_[1-9][0-9]?$
     <!--NeedCopy-->
    

Caution: Regular expressions are powerful. Especially if you are not thoroughly familiar with PCRE-format regular expressions, double-check any regular expressions you write. Make sure that they define exactly the URL you want to add as an exception, and nothing else. Careless use of wildcards, and especially of the dot-asterisk (.*) metacharacter/wildcard combination, can have results you do not want or expect, such as blocking access to web content that you did not intend to block or allowing an attack that the Cookie Consistency check would otherwise have blocked.

Cookie consistency check