Sha256: 4147025e48e23e53931010605f1aadcaf76ab08f8c000aa057cf3af0d97b4032

Contents?: true

Size: 1.81 KB

Versions: 11

Compression:

Stored size: 1.81 KB

Contents

## Cookies

SecureHeaders supports `Secure`, `HttpOnly` and [`SameSite`](https://tools.ietf.org/html/draft-west-first-party-cookies-07) cookies. These can be defined in the form of a boolean, or as a Hash for more refined configuration.

__Note__: Regardless of the configuration specified, Secure cookies are only enabled for HTTPS requests.

#### Defaults

By default, all cookies will get both `Secure`, `HttpOnly`, and `SameSite=Lax`.

```ruby
config.cookies = {
  secure: true, # defaults to true but will be a no op on non-HTTPS requests
  httponly: true, # defaults to true
  samesite: {  # defaults to set `SameSite=Lax`
    lax: true
  }
}
```

#### Boolean-based configuration

Boolean-based configuration is intended to globally enable or disable a specific cookie attribute. *Note: As of 4.0, you must use OPT_OUT rather than false to opt out of the defaults.*

```ruby
config.cookies = {
  secure: true, # mark all cookies as Secure
  httponly: SecureHeaders::OPT_OUT, # do not mark any cookies as HttpOnly
}
```

#### Hash-based configuration

Hash-based configuration allows for fine-grained control.

```ruby
config.cookies = {
  secure: { except: ['_guest'] }, # mark all but the `_guest` cookie as Secure
  httponly: { only: ['_rails_session'] }, # only mark the `_rails_session` cookie as HttpOnly
}
```

#### SameSite cookie configuration

SameSite cookies permit either `Strict` or `Lax` enforcement mode options.

```ruby
config.cookies = {
  samesite: {
    strict: true # mark all cookies as SameSite=Strict
  }
}
```

`Strict`, `Lax`, and `None` enforcement modes can also be specified using a Hash.

```ruby
config.cookies = {
  samesite: {
    strict: { only: ['session_id_duplicate'] },
    lax: { only: ['_guest', '_rails_session', 'device_id'] },
    none: { only: ['_tracking', 'saml_cookie', 'session_id'] },
  }
}
```

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
secure_headers-7.0.0 docs/cookies.md
secure_headers-6.7.0 docs/cookies.md
secure_headers-6.6.0 docs/cookies.md
secure_headers-6.5.0 docs/cookies.md
secure_headers-6.4.0 docs/cookies.md
secure_headers-6.3.4 docs/cookies.md
secure_headers-6.3.3 docs/cookies.md
secure_headers-6.3.2 docs/cookies.md
secure_headers-6.3.1 docs/cookies.md
secure_headers-6.3.0 docs/cookies.md
secure_headers-6.2.0 docs/cookies.md