Skip to content

Kirby 6.0.0

cookie

Configure the behavior of HTTP cookies

Values of HTTP cookies set by the Kirby backend are signed (or authenticated) to prevent easy tampering. Generating these signatures (so-called HMACs) requires a key that should be stable and consistent on the server, but still independent from other sites or setups and ideally private and hard to guess. The key is set to a fixed string by default, so you should define your own key that will be used instead:

return [
  'cookie' => [
    'key' => '...'
  ]
];

The cookie key should be a long string of random characters.

You can read more about the security impact of this option in the security guide.

Kirby signs each cookie value with an HMAC-SHA256 signature based on the cookie key. When you read a cookie with Cookie::get(), Kirby verifies the signature and returns null for cookies whose value has been modified.

Cookies set with Cookie::set() get these attributes by default:

Attribute Default
HttpOnly always
SameSite Lax
Secure on HTTPS requests
Path /

Kirby's session cookie uses the same HttpOnly, SameSite and Secure attributes. With the Secure attribute, browsers only send the cookie over encrypted connections. If a cookie that you set on an HTTPS page must also be readable on plain HTTP pages, turn the attribute off for this cookie:

Cookie::set('name', 'value', ['secure' => false]);