Setting Cookies Without Explicit HttpOnly Flag Configuration
Laravel applications create cookies using response()->cookie() or Cookie facade methods without specifying the HttpOnly parameter, defaulting to insecure configurations. The cookie() helper accepts multiple parameters: cookie($name, $value, $minutes, $path, $domain, $secure, $httpOnly, $raw, $sameSite), but developers commonly use only the first three: response()->cookie('user_pref', $value, 60) omitting security flags. When httpOnly parameter is not explicitly set to true, cookies become accessible via document.cookie in JavaScript, enabling XSS attacks to steal session tokens. Laravel's default behavior varies by configuration, but in many setups, cookies created without explicit flags inherit application-wide settings from config/session.php which may be misconfigured or may not apply to non-session cookies. The vulnerability manifests in various contexts: authentication tokens stored in cookies for remember-me functionality without HttpOnly protection, API tokens or JWT stored client-side accessible to JavaScript, user preference cookies that inadvertently contain sensitive data, and temporary data storage cookies used during multi-step processes. Developers often overlook HttpOnly when setting cookies manually, focusing on functionality rather than security, or copy code examples that demonstrate cookie usage without security considerations. The risk is compounded when applications have XSS vulnerabilities: attackers inject JavaScript that reads document.cookie extracting all non-HttpOnly cookies including session identifiers, then exfiltrate stolen cookies to attacker-controlled servers enabling session hijacking.