CRM_Utils_SameSite
in package
SameSite Utility Class.
Determines if the current User Agent can handle the SameSite=None
parameter
by mapping against known incompatible clients.
Sample code:
// Get User Agent string. $rawUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $userAgent = mb_convert_encoding($rawUserAgent, 'UTF-8');
// Get boolean representing User Agent compatibility. $shouldUseSameSite = CRM_Utils_SameSite::shouldSendSameSiteNone($userAgent);
Based on code provided by "The Chromium Projects".
Tags
Table of Contents
Methods
- shouldSendSameSiteNone() : bool
- Determine if the current User Agent can handle the `SameSite=None` parameter.
- dropsUnrecognizedSameSiteCookies() : bool
- Detect versions of UC Browser on Android prior to version 12.13.2.
- hasWebKitSameSiteBug() : bool
- Detect versions of Safari and embedded browsers on MacOS 10.14 and all browsers on iOS 12.
- isChromiumBased() : false|int
- Detect if browser is Chromium based.
- isChromiumVersionAtLeast() : bool|int
- Detect if Chromium version meets requirements.
- isIosVersion() : bool
- Detect iOS version.
- isMacEmbeddedBrowser() : false|int
- Detect MacOS embedded browser.
- isMacosxVersion() : bool
- Detect MacOS version.
- isSafari() : bool
- Detect MacOS Safari.
- isSameSiteNoneIncompatible() : bool
- Detect classes of browsers known to be incompatible.
- isUcBrowser() : false|int
- Detect UCBrowser.
- isUcBrowserVersionAtLeast() : bool|int
- Detect if UCBrowser version meets requirements.
Methods
shouldSendSameSiteNone()
Determine if the current User Agent can handle the `SameSite=None` parameter.
public
static shouldSendSameSiteNone(string $userAgent) : bool
Parameters
- $userAgent : string
Return values
bool —True if the User Agent is compatible, FALSE otherwise.
dropsUnrecognizedSameSiteCookies()
Detect versions of UC Browser on Android prior to version 12.13.2.
private
static dropsUnrecognizedSameSiteCookies(string $userAgent) : bool
Older versions will reject a cookie with SameSite=None
. This behavior was
correct according to the version of the cookie specification at that time,
but with the addition of the new "None" value to the specification, this
behavior has been updated in newer versions of UC Browser.
Parameters
- $userAgent : string
-
The User Agent.
Return values
boolhasWebKitSameSiteBug()
Detect versions of Safari and embedded browsers on MacOS 10.14 and all browsers on iOS 12.
private
static hasWebKitSameSiteBug(string $userAgent) : bool
These versions will erroneously treat cookies marked with SameSite=None
as if they were marked SameSite=Strict
.
Parameters
- $userAgent : string
-
The User Agent.
Return values
boolisChromiumBased()
Detect if browser is Chromium based.
private
static isChromiumBased(string $userAgent) : false|int
Parameters
- $userAgent : string
-
The User Agent.
Return values
false|intisChromiumVersionAtLeast()
Detect if Chromium version meets requirements.
private
static isChromiumVersionAtLeast(int $major, string $userAgent, string $operator) : bool|int
Parameters
- $major : int
-
The major version to test.
- $userAgent : string
-
The User Agent.
- $operator : string
Return values
bool|intisIosVersion()
Detect iOS version.
private
static isIosVersion(int $major, string $userAgent) : bool
Parameters
- $major : int
-
The major version to test.
- $userAgent : string
-
The User Agent.
Return values
boolisMacEmbeddedBrowser()
Detect MacOS embedded browser.
private
static isMacEmbeddedBrowser(string $userAgent) : false|int
Parameters
- $userAgent : string
-
The User Agent.
Return values
false|intisMacosxVersion()
Detect MacOS version.
private
static isMacosxVersion(int $major, int $minor, string $userAgent) : bool
Parameters
- $major : int
-
The major version to test.
- $minor : int
-
The minor version to test.
- $userAgent : string
-
The User Agent.
Return values
boolisSafari()
Detect MacOS Safari.
private
static isSafari(string $userAgent) : bool
Parameters
- $userAgent : string
-
The User Agent.
Return values
boolisSameSiteNoneIncompatible()
Detect classes of browsers known to be incompatible.
private
static isSameSiteNoneIncompatible(string $userAgent) : bool
Parameters
- $userAgent : string
-
The User Agent.
Return values
bool —True if the User Agent is determined to be incompatible, FALSE otherwise.
isUcBrowser()
Detect UCBrowser.
private
static isUcBrowser(string $userAgent) : false|int
Parameters
- $userAgent : string
-
The User Agent.
Return values
false|intisUcBrowserVersionAtLeast()
Detect if UCBrowser version meets requirements.
private
static isUcBrowserVersionAtLeast(int $major, int $minor, int $build, string $userAgent) : bool|int
Parameters
- $major : int
-
The major version to test.
- $minor : int
-
The minor version to test.
- $build : int
-
The build version to test.
- $userAgent : string
-
The User Agent.