---
updatedAt: 2025-08-04T21:36:24.000Z
agentTools:
  projectIndex: https://docs.brightsec.com/llms.txt
---

# Missing 'secure' Flag in Cookie

<HTMLBlock>{`
<table id="simple-table">
   <style>
 #simple-table {
    border-collapse: separate;
    width: 100%;
    display: block;
    display: table;
  }
#simple-table th {
    padding: 1.5%;
    text-align: left;
    vertical-align: text-top;
    background-color: #B2D6DA;
  </style>
  <body>
    <tr>
        <th><strong>Details</strong></th>
    </tr>
</table>
  </body>
`}</HTMLBlock>

<HTMLBlock>{`
Severity: <b><font color="#173eb3">Low</font></b><br />
Test Name: <b>Cookie Security</b><br />
Test ID: <b>cookie_security</b>
`}</HTMLBlock>

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Description</strong></th>
    </tr>
</table>
`}</HTMLBlock>

An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to the user's web browser. The browser may store it and send it back with later requests to the same server. Typically, it is used to tell if two requests came from the same browser (keeping a user logged-in, for example).

One of the ways to protect sensitive cookies is to ensure that they are sent securely and are not accessed by unintended parties or scripts: use the `Secure` attribute. A cookie with the `Secure` attribute is sent to the server only with an encrypted request over the HTTPS protocol, never with unsecured HTTP (except on localhost). It prevents attackers from accessing cookies easily by intercepting unsecured HTTP requests with plaintext cookies. Insecure sites (with `http:` in the URL) cannot set cookies with the Secure attribute.

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Impact</strong></th>
    </tr>
</table>
`}</HTMLBlock>

This vulnerability allows an attacker to read the application data.

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Locations</strong></th>
    </tr>
</table>
`}</HTMLBlock>

The issue can be found in the **source code** on the **server side**.

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Remediation suggestions</strong></th>
    </tr>
</table>
`}</HTMLBlock>

It is necessary to configure (enable) the `Secure` attribute for sensitive cookies.

* .NET
  * *"Web.config"* :\`\`\`\
    \<system.web>
    ...
    ```
    ```
  <httpCookies requireSSL="true" />
  \</system.web>
  <br />

````
    * C# :
```js
Response.Cookies.Add(
        new HttpCookie("key", "value")
        {
            .....
            Secure = true
        });
````

* PHP

  * *"php.ini"* :

  ```
  session.cookie_secure = True
  ```

  * During a script (parameter `$secure` should be set to `true`):

  ```
  void session_set_cookie_params ( int $lifetime  [, string $path  [, string $domain [, bool $secure= false  [, bool $httponly= false  ]]]] )
  ```

  * Application cookies (parameter `$secure` should be set to `true`):

  ```
  bool setcookie ( string $name  [, string $value  [, int $expire= 0  [, string $path  [, string $domain  [, bool $secure= false  [, bool $httponly= false  ]]]]]] )
  ```

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Classifications</strong></th>
    </tr>
</table>
`}</HTMLBlock>

* CWE-614
* CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:N

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>References</strong></th>
    </tr>
</table>
`}</HTMLBlock>

* <https://owasp.org/www-community/controls/SecureCookieAttribute>
* <https://cwe.mitre.org/data/definitions/614.html>