
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
user-consent
Advanced tools
A brand agnostic approach to CCPA and GDPR user consent using OneTrust.
Include code in your application (as the first script in the <head>
block).
<head>
<!-- place this at or near the top -->
<script src="path/to/this-script.js" type="text/javascript"></script>
<script>
(function initalizeUserConsent(win) {
win.WM.UserConsent.init({
cookieDomain: '.your-brand.com',
domId: 'ONETRUST-GUID-HERE',
src: '//domain.com/path/to/one-trust-script.js'
});
})(window);
</script>
<!-- other head tags -->
</head>
Or by pre-defining the config, which will allow the code to self-initialize.
<head>
<!-- place this at or near the top -->
<script>
window.WM = window.WM || {};
window.WM.UserConsentConfig = {
cookieDomain: '.your-brand.com',
domId: 'ONETRUST-GUID-HERE',
src: '//domain.com/path/to/one-trust-script.js'
};
</script>
<script src="path/to/this-script.js" type="text/javascript"></script>
<!-- other head tags -->
</head>
Both methods are equavalent to the code, so just use whichever works best for your situation.
The required configuration values are:
".cnn.com"
(note the leading .
).Some other important configuration values are:
countryCode
, this is the default. Note that either passing in the GeoIP-derived current country code directly (via the countryCode
option below) or getting it from a session cookie on the response is required for User-Consent to work properly. The session cookie method is easily added to both Akamai and Fastly CDN configurations.ccCookie
option (above).addScript
MethodReplace scripts implemented like this:
<script src="//domain.com/path/to/script.js" onload="myLoadEventHandler()"></script>
With something like this:
<script>
window.WM.addScript({
async: true,
onload: function (e) {
myLoadEventHandler();
},
src: '//domain.com/path/to/script.js'
}, ['perf-general']);
})(window, document);
</script>
Any script tag properties can be passed in the object for the first parameter,
just as you would use with a script tag created via.
document.createElement('script')
.
The second parameter should be an array of strings specifying the list of the consent categories required for this script to be invoked. If more than one are included, all must have consent.
There is an optional third parameter, which (if specified) is the DOM node on the page to append the script to. This is not normally needed.
Note that the function returns boolean true
if consent exists and the script
tag was added or boolean false
if consent was not granted.
addScriptElement
MethodVery similar to addScript
above, the addScriptElement
call will conditionally
add a script tag based on consent. The difference is instead of the first parameter
being an object consisting of script properties, it is a script element created by
your code but not yet added to the DOM.
For example, if you have something like this in your code:
var scpt = doc.getElementsByTagName('script')[0],
elem = doc.createElement('script');
elem.id = 'quantScript';
elem.async = true;
elem.type = 'text/javascript';
elem.src = doc.location.protocol === 'https:' ? config.runtime.quantcast.sslSrc : config.runtime.quantcast.src;
scpt.parentNode.appendChild(elem);
You would replace that with this:
var scpt = doc.getElementsByTagName('script')[0],
elem = doc.createElement('script');
elem.id = 'quantScript';
elem.async = true;
elem.type = 'text/javascript';
elem.src = doc.location.protocol === 'https:' ? config.runtime.quantcast.sslSrc : config.runtime.quantcast.src;
window.WM.UserConsent.addScriptElement(elem, config.runtime.quantcast.ucStates, scpt.parentNode);
Here we see that the first parameter is simply the script element created within
the code, but the instead of adding it directly to the DOM, we use addScriptElement
.
Note that the second parameter and optional third parameter are identical to addScript
.
Also note that the function returns true
or false
, similar to addScript
.
inUserConsentState
If you simple need to make code conditional on a consent state, you can also do
that by using inUserConsentState
with a conditional. For example, let's say you have
a block of code like the following:
doThingA();
doGeneralPerfThing();
doThingB();
if (doSocialMediaIdentityThing() === 'success') {
doThingC();
} else {
doThingD();
}
You could re-write that to use consent with logic like the following:
doThingA();
if (window.WM.UserConsent.inUserConsentState(['perf-general'])) {
doGeneralPerfThing();
}
doThingB();
if (window.WM.UserConsent.inUserConsentState(['social-vendor'])) {
if (doSocialMediaIdentityThing() === 'success') {
doThingC();
} else {
doThingD();
}
} else {
doThingD();
}
In all the examples above, consent is specified as an array of strings.
Consent must exist for ALL the consent types specified for consent to be
successful. If the consent array is empty ([]
), it will always be true.
Note that a special consent string exists called "iab"
. If this string
appears in the consent array, and IAB is used in the current region
(notably GDPR), then consent will be granted, as it is assumed that the
code being invoked will correctly be using CMP to manage consent internally
on it's own in an IAB-compliant way.
Ideally, scripts should be managed via an upstream configuration file - similar to:
// global config for application
{
"someThirdParty": {
"src": "//domain.com/path/to/script.js",
"ucStates": ["perf-vendor"]
}
}
<script>
window.WM.UserConsent.addScript({ src: Config.someThirdParty.src }, Config.someThirdParty.ucStates);
</script>
If using ES6-style import
, replace something like this:
<script>
import 'usabilla';
// Do stuff with usabilla
</script>
With something like:
<script>
if (window.WM.UserConsent.inUserConsentState(['perf-general'])) {
import 'usabilla';
// Do stuff with usabilla
}
</script>
While we don't recommend it, as it makes future category changes difficult to migrate and makes some script behavior a bit unpredictable, you can also continue to use the OneTrust method with text/plain and optanon category class:
<script type="text/plain" class="optanon-category-pf" src="//domain.com/path/to/script.js"></script>
If you previously implemented OneTrust within your application for GDPR compliance, you will need to remove that script as the bootstrap
script will include it for you.
Passing a query parameter of wmuc_debug=1
in the query string of your page URL will
enable "debug" mode. This will output extra details to the Javascript console which may
assist you in determining exactly what was or wasn't loaded and why.
User-Consent makes the following functions available...
window.WM.UserConsentConfig
(see "Adding the library" above).true
if the current user's region is a match.true
once the User-Consent is ready to process consent. Note that this does NOT imply that OneTrust has been loaded!true
if the user is in a region with IAB enabled.FAQs
A library for managing User-Consent within WM.
We found that user-consent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.