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

Adds option to disable luigiCookie #3946

Merged
merged 26 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
152d0f5
Adds option to disable luigiCookie
walmazacn Sep 24, 2024
72b5902
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Sep 25, 2024
8d6a12e
Adds cookie prop for container
walmazacn Sep 25, 2024
34a4d82
Merge branch '3942-option-to-disable-luigicookie' of https://github.c…
walmazacn Sep 25, 2024
3de82f3
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Sep 25, 2024
8414709
Fixes failing test
walmazacn Sep 25, 2024
19b242c
Merge branch '3942-option-to-disable-luigicookie' of https://github.c…
walmazacn Sep 25, 2024
2cfd899
Merge branch 'main' into 3942-option-to-disable-luigicookie
ndricimrr Sep 25, 2024
a2f5a1e
Fixes code review issues
walmazacn Sep 26, 2024
145f060
Merge branch '3942-option-to-disable-luigicookie' of https://github.c…
walmazacn Sep 26, 2024
57c74db
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Sep 26, 2024
214717a
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Sep 26, 2024
4d3e448
Fixes code review issues
walmazacn Sep 26, 2024
87664a4
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Sep 27, 2024
5e750d6
Merge branch 'main' into 3942-option-to-disable-luigicookie
ndricimrr Sep 27, 2024
2c876c6
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Sep 30, 2024
89b3f9c
Fixes code review issues
walmazacn Sep 30, 2024
81d8d30
Fixes Prettier issues
walmazacn Sep 30, 2024
e547b80
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Sep 30, 2024
7fa63d7
Merge branch '3942-option-to-disable-luigicookie' of https://github.c…
walmazacn Sep 30, 2024
daceecf
Adds correct type
walmazacn Sep 30, 2024
82ae9da
Update docs/general-settings.md
walmazacn Sep 30, 2024
20758bd
Update container/test-app/iframe/iframe-cookies.html
walmazacn Sep 30, 2024
6a01df8
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Oct 1, 2024
c279a8b
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Oct 1, 2024
08822c9
Merge branch 'main' into 3942-option-to-disable-luigicookie
walmazacn Oct 2, 2024
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
5 changes: 4 additions & 1 deletion client/src/lifecycleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class LifecycleManager extends LuigiClientBase {
helpers.setLuigiCoreDomain(e.origin);
this.luigiInitialized = true;
this._notifyInit(e.origin);
this._tpcCheck();
helpers.sendPostMessageToLuigiCore({ msg: 'luigi.init.ok' });
});

Expand Down Expand Up @@ -135,10 +136,12 @@ class LifecycleManager extends LuigiClientBase {
},
'*'
);
this._tpcCheck();
}

_tpcCheck() {
if (this.currentContext?.internal?.thirdPartyCookieCheck?.disabled) {
ndricimrr marked this conversation as resolved.
Show resolved Hide resolved
return;
}
let tpc = 'enabled';
let cookies = document.cookie;
let luigiCookie;
Expand Down
3 changes: 3 additions & 0 deletions container/src/LuigiContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
pathParams: { type: 'Object', reflect: false, attribute: 'path-params' },
sandboxRules: { type: 'Array', reflect: false, attribute: 'sandbox-rules' },
searchParams: { type: 'Object', reflect: false, attribute: 'search-params' },
skipCookieCheck: { type: 'Boolean', reflect: false, attribute: 'skip-cookie-check' },
skipInitCheck: { type: 'Boolean', reflect: false, attribute: 'skip-init-check' },
theme: { type: 'String', reflect: false, attribute: 'theme' },
userSettings: { type: 'Object', reflect: false, attribute: 'user-settings' },
Expand Down Expand Up @@ -79,6 +80,7 @@
export let pathParams: any;
export let sandboxRules: string[];
export let searchParams: any;
export let skipCookieCheck: boolean;
export let skipInitCheck: boolean;
export let theme: string;
export let userSettings: any;
Expand Down Expand Up @@ -113,6 +115,7 @@
pathParams &&
sandboxRules &&
searchParams &&
skipCookieCheck &&
skipInitCheck &&
theme &&
userSettings
Expand Down
20 changes: 19 additions & 1 deletion container/src/services/container.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export class ContainerService {
{
msg: LuigiInternalMessageID.SEND_CONTEXT_HANDSHAKE,
context: targetCnt.context || {},
internal: {},
internal: {
thirdPartyCookieCheck: {
disabled: this.handleCookieCheck(targetCnt)
ndricimrr marked this conversation as resolved.
Show resolved Hide resolved
}
},
authData: targetCnt.authData || {}
},
'*'
Expand Down Expand Up @@ -192,6 +196,20 @@ export class ContainerService {
registerContainer(thisComponent: HTMLElement): void {
this.getContainerManager().container.push(thisComponent);
}

private handleCookieCheck(targetCnt): boolean {
let skipCookieCheck = false;

if (targetCnt.getAttribute) {
if (typeof targetCnt.getAttribute('skip-cookie-check') === 'string') {
skipCookieCheck = targetCnt.getAttribute('skip-cookie-check') === 'true';
} else if (typeof targetCnt.skipCookieCheck !== 'undefined') {
skipCookieCheck = targetCnt.skipCookieCheck;
}
}

return skipCookieCheck;
}
}

export const containerService = new ContainerService();
13 changes: 11 additions & 2 deletions container/test/services/container.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('getContainerManager messageListener', () => {
gtcSpy.mockRestore();
});

it('test get context message', () => {
it('test get context message', () => {
ndricimrr marked this conversation as resolved.
Show resolved Hide resolved
const event = {
source: cw,
data: {
Expand All @@ -87,7 +87,16 @@ describe('getContainerManager messageListener', () => {
cw.postMessage = postMessageMock;

// Define the message to send and target Origin
const message = {"context": {}, "internal": {}, "msg": "luigi.init", "authData":{}};
const message = {
"authData":{},
"context": {},
"internal": {
"thirdPartyCookieCheck": {
"disabled": false
}
},
"msg": "luigi.init"
};
const targetOrigin = "*";

// Call the method that should trigger postMessage
Expand Down
6 changes: 6 additions & 0 deletions container/typings/LuigiContainer.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export default class LuigiContainer extends HTMLElement {
*/
activeFeatureToggleList: string[];

/**
* If set to true, skips third party cookie check
* @since NEXT_RELEASE_CONTAINER
*/
skipCookieCheck: boolean;

/**
* If set to true, skips handshake and ready event is fired immediately
* @since 1.0.0
Expand Down
1 change: 1 addition & 0 deletions core/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
isNavigateBack,
viewStackSize: preservedViews.length,
clientPermissions: iframeConf.nextViewUrl ? iframeConf.nextClientPermissions : iframeConf.clientPermissions,
thirdPartyCookieCheck: await LuigiConfig.getConfigValue('settings.thirdPartyCookieCheck'),
userSettings: hasUserSettings ? userSettingGroups[userSettingsGroupName] : null,
anchor: LuigiRouting.getAnchor(),
cssVariables: await LuigiTheming.getCSSVariables()
Expand Down
9 changes: 7 additions & 2 deletions docs/general-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ settings: {
hideAutomatically: true
},
thirdPartyCookieCheck = {
//disabled: true,
//thirdPartyCookieScriptLocation: 'https://domain/init.html',
thirdPartyCookieErrorHandling: () => {
const alert = {
Expand Down Expand Up @@ -298,15 +299,19 @@ This function is called with the following parameters:

## Third-party cookies support check

You can check whether the user's browser supports third-party cookies by defining a **thirdPartyCookieCheck** object which expects a function called **thirdPartyCookieErrorHandling** and an optional **thirdPartyCookiesScriptLocation** parameter. When **thirdPartyCookiesScriptLocation** is set, the Luigi Core application checks third-party cookie support only once and not on every micro frontend call. If it is *not* set, the Luigi Core application checks third-party cookie support whenever a micro frontend is loaded.
You can check whether the user's browser supports third-party cookies by defining a **thirdPartyCookieCheck** object which expects a function called **thirdPartyCookieErrorHandling** and optional **disabled** and **thirdPartyCookiesScriptLocation** parameters. When **thirdPartyCookiesScriptLocation** is set, the Luigi Core application checks third-party cookie support only once and not on every micro frontend call. If it is *not* set, the Luigi Core application checks third-party cookie support whenever a micro frontend is loaded.
walmazacn marked this conversation as resolved.
Show resolved Hide resolved

To detect whether the user's browser supports the mechanism, use the script in the [`third-party-cookies`](https://github.com/SAP/luigi/tree/main/core/third-party-cookies) catalog. Deploy this file on a domain different from your main application's and set **thirdPartyCookieScriptLocation** to the `init.html` file. During initialization, Luigi detects cookies support and produces an alert if cookies are disabled in the user's browser.

### Parameters

#### thirdPartyCookieCheck
- **type**: object
- **description**: object defined in the general settings part of the Luigi configuration file, containing the **thirdPartyCookieErrorHandling** function and an optional **thirdPartyCookiesScriptLocation** parameter.
- **description**: object defined in the general settings part of the Luigi configuration file, containing the **thirdPartyCookieErrorHandling** function and optional **disabled** and **thirdPartyCookiesScriptLocation** parameters.

#### disabled
- **type**: boolean
- **description**: if set to true **thirdPartyCookieCheck** is ignored.

#### thirdPartyCookieErrorHandling
- **type**: function
Expand Down
10 changes: 10 additions & 0 deletions docs/luigi-container-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global

* **since**: 1.0.0

### skipCookieCheck

If set to true, skips third party cookie check

Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)

**Meta**

* **since**: NEXT_RELEASE_CONTAINER

### skipInitCheck

If set to true, skips handshake and ready event is fired immediately
Expand Down