In plain English: A cookie without Secure can be sent over plain HTTP. A
cookie without HttpOnly can be read by JavaScript. Session and authentication
cookies should set both flags.
Why it matters: Without Secure, a cookie can leak over an insecure
connection. Without HttpOnly, a cross-site scripting bug can steal the cookie.
setcookie('session', $id);
setcookie('session', $id, ['secure' => true]);
session_set_cookie_params(['httponly' => true]);
setcookie('session', $id, [
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);
session_set_cookie_params([
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);
Secure means the browser only sends the cookie over HTTPS. HttpOnly means
JavaScript cannot read it. SameSite controls when the browser sends the cookie
with cross-site requests; Lax is a common default.
setcookie() and setrawcookie() with missing or disabled secure and
httponly optionssession_set_cookie_params() with missing or disabled secure and
httponly optionshttponly and httpOnly
are recognizedtrue.secure => true and httponly => true.samesite => 'Lax' or 'Strict' where appropriate.SameSite is recommended but not required by this rule.E0058 has no configuration options and is enabled by default.