Updated on 2026-10-10 GMT+08:00

Enabling Cookie Security Attributes

The cookie security attribute function is designed to enhance the security of web service cookies. It automatically adds the HttpOnly and Secure attributes (both set to true) to cookies returned by the origin server. This helps prevent security risks such as cross-site scripting (XSS) attacks, cookie hijacking, and man-in-the-middle (MITM) attacks that tamper with cookies. It also ensures compliance with security regulations and prevents web security scanners like AppScan, AWVS, and NSFOCUS from flagging the lack of security configuration fields such as HttpOnly and Secure in cookies as security threats.

If you set Client Protocol to HTTPS, you can enable Cookie Security Attributes. If you enable this, the HttpOnly and Secure attributes of cookies will be set to true.

Principles

WAF cookie security attributes function operates through Layer 7 response rewriting. It does not change the service logic of the origin server or generate cookies. Instead, it automatically enhances the security of the Set-Cookie response headers returned by the origin server to the client. This is a passive hardening measure and does not affect the request forwarding efficiency.

Figure 1 shows the process.

Figure 1 Process for cookie security attributes to take effect
The details are as follows:
  1. The client initiates an HTTPS request.
  2. WAF receives the request and checks for attacks and compliance risks.
  3. WAF forwards the normal service requests to the origin server.
  4. The origin server processes the request.
  5. The origin server returns response data containing the Set-Cookie response header. (Cookies are inserted by the backend web server through framework configuration or Set-Cookie instructions.)
  6. WAF blocks the origin server's response, parses the Set-Cookie response header, and checks whether the Cookie contains the HttpOnly and Secure attributes.
    • If the cookie already contains the corresponding attributes, WAF does not modify the response and directly forwards it.
    • If the cookie does not contain the corresponding attributes, WAF automatically adds the attributes, without changing core information such as the cookie value and validity period.
  7. WAF forwards the enhanced response data to the client. The client browser identifies and applies the HttpOnly and Secure attributes.

Typical Application Scenarios

  • All HTTPS web services, such as e-commerce websites, management backends, payment systems, and user login websites
  • Services that require security scanning, DJCP compliance, and PCI DSS certification
  • Services that store login status and sensitive user information in cookies

Constraints

Function

Constraint

Access mode restrictions

  • Cloud CNAME access and dedicated mode access: This function is supported.
  • Cloud load balancer access: This function is not supported. Cookies are written in response packets. With ELB load balancer access, WAF cannot modify the original response packets returned by the origin server or add the cookie security flag.

Other

If the Client Protocol is set to HTTP, the Cookie Security Attributes function is disabled by default and cannot be enabled.

Prerequisites

You have selected Dedicated or Cloud CNAME and added the website you want to protect to WAF.

Enabling Cookie Security Attributes

  1. Log in to the WAF console.
  2. Click in the upper left corner and select a region or project.
  3. (Optional) If you have enabled the enterprise project function, in the upper part of the navigation pane on the left, select your enterprise project from the Filter by enterprise project drop-down list. Then, WAF will display the related security data in the enterprise project on the page.
  4. In the navigation pane on the left, choose Assets > Protected Objects.
  5. On the Protected Objects page, click the target domain name.
  6. In the Advanced Settings area, click next to Cookie Security Attributes to enable it.

    Figure 2 Cookie Security Attributes

    After completing the above configuration, access the protected domain name through a browser, open the developer tool, and check whether the HttpOnly and Secure attributes of the cookie are set to true.