Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set the domain of the SOI cookie #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ For detailed explanations, please visit the [documentation](https://oil.axelspri
| advanced_settings | Replaces the No Button with an advanced settings button, displaying the Cookie Preference Center. The CPC enables the user to choose their own level of privacy. These settings are stored in the oil cookie (both SOI and POI) as well. | False
| advanced_settings_purposes_default | All purposes in the advanced settings layer should be activated by default | false
| config_version | Specifies the version of your OIL configuration. It will be stored with the consent cookie to track which explicit configuration version consent was granted for.| None
| cookie_domain | Specifies the domain to write the cookie to. Can be used to set the cookie on a valid parent domain: e.g sub.example.com -> .example.com. | Current hostname
| cookie_expires_in_days | Value in days until the domain cookie used to save the users decision in days | 31
| cpc_type | Specifies the type (the layout) of the Cookie Preference Center. Currently, two types are supported: 'standard' and 'tabs'. Depending on this parameter additional label configuration may be necessary. See section <<Full Label Configuration>> for details. | standard
| customPurposes | Array of custom purposes defined by publisher. IDs for custom purposes may range from 25-88. | None
Expand Down
1 change: 1 addition & 0 deletions docs/src/docs/03-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ This is a full list of configurable options.
| advanced_settings_purposes_default | All purposes in the advanced settings layer should be activated by default | false
| config_version | Specifies the version of your OIL configuration. It will be stored with the consent cookie to track which explicit configuration version consent was granted for.| None
| cookie_expires_in_days | Value in days until the domain cookie used to save the users decision in days | 31
| cookie_domain | Specifies the domain to write the cookie to. Can be used to set the cookie on a valid parent domain: e.g sub.example.com -> .example.com. | Current hostname
| cpc_type | Specifies the type (the layout) of the Cookie Preference Center. Currently, two types are supported: 'standard' and 'tabs'. Depending on this parameter additional label configuration may be necessary. See section <<Full Label Configuration>> for details. | standard
| customPurposes | Array of custom purposes defined by publisher. IDs for custom purposes may range from 25-88. | None
| customVendorListUrl | Custom vendor list ('non IAB vendors') to use, will be loaded at the same time as the iabVendorList. | None
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/core/core_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export function getCookieExpireInDays() {
return getConfigValue(OIL_CONFIG.ATTR_COOKIE_EXPIRES_IN_DAYS, 31);
}

export function getCookieDomain() {
return getConfigValue(OIL_CONFIG.ATTR_COOKIE_DOMAIN, '');
}

export function getLocaleVariantName() {
const defaultLocaleId = 'enEN_01';
let localeVariantName = getLocale();
Expand Down
1 change: 1 addition & 0 deletions src/scripts/core/core_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const OIL_CONFIG = {
ATTR_HUB_LOCATION: 'poi_hub_location', // complete hub location, gets generated
ATTR_PREVIEW_MODE: 'preview_mode',
ATTR_COOKIE_EXPIRES_IN_DAYS: 'cookie_expires_in_days',
ATTR_COOKIE_DOMAIN: 'cookie_domain',
ATTR_TIMESTAMP: 'timestamp',
ATTR_PRIVACY_PAGE_URL: 'privacy_page_url',
ATTR_POI_GROUP_NAME: 'poi_group_name',
Expand Down
10 changes: 6 additions & 4 deletions src/scripts/core/core_cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logInfo } from './core_log';
import {
getConfigVersion,
getCookieExpireInDays,
getCookieDomain,
getCustomPurposes,
getDefaultToOptin,
isInfoBannerOnly,
Expand All @@ -27,10 +28,10 @@ export function setSessionCookie(name, value) {
Cookie.set(name, value);
}

export function setDomainCookie(name, value, expires_in_days) {
export function setDomainCookie(name, value, expires_in_days, domain) {
// decoded consent data must not be written to the cookie
delete value.consentData;
Cookie.set(name, value, { expires: expires_in_days });
Cookie.set(name, value, { expires: expires_in_days, domain: domain });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before i merge this, what happens when domain is an empty string? Would it perhaps be better to leave out the domain parameter altogether in that case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nevermind my write access was revoked

}

export function getOilCookie(cookieConfig) {
Expand Down Expand Up @@ -94,7 +95,7 @@ export function setSoiCookieWithPoiCookieData(poiCookieJson) {
configVersion: configVersion
};

setDomainCookie(cookieConfig.name, cookie, cookieConfig.expires);
setDomainCookie(cookieConfig.name, cookie, cookieConfig.expires, cookieConfig.domain);
resolve(cookie);
}).catch(error => reject(error));
});
Expand Down Expand Up @@ -129,7 +130,7 @@ export function buildSoiCookie(privacySettings) {
export function setSoiCookie(privacySettings) {
return new Promise((resolve, reject) => {
buildSoiCookie(privacySettings).then((cookie) => {
setDomainCookie(OIL_DOMAIN_COOKIE_NAME, cookie, getCookieExpireInDays());
setDomainCookie(OIL_DOMAIN_COOKIE_NAME, cookie, getCookieExpireInDays(), getCookieDomain());
resolve(cookie);
}).catch(error => reject(error));
});
Expand Down Expand Up @@ -272,6 +273,7 @@ function getOilCookieConfig() {
return {
name: OIL_DOMAIN_COOKIE_NAME,
expires: getCookieExpireInDays(),
domain: getCookieDomain(),
defaultCookieContent: {
opt_in: false,
version: OilVersion.get(),
Expand Down