mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Various fixes (#2683)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/react-contentkit': patch
|
||||
---
|
||||
|
||||
Fix potential invalid URL error in react-contentkit
|
||||
@@ -20,13 +20,21 @@ export function setCookiesTracking(enabled: boolean) {
|
||||
* Return `undefined` if state is not known.
|
||||
*/
|
||||
export function isCookiesTrackingDisabled() {
|
||||
const state = cookies.get(GRANTED_COOKIE);
|
||||
try {
|
||||
const state = cookies.get(GRANTED_COOKIE);
|
||||
|
||||
if (state === 'yes') {
|
||||
return false;
|
||||
} else if (state === 'no') {
|
||||
return true;
|
||||
if (state === 'yes') {
|
||||
return false;
|
||||
} else if (state === 'no') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
// If there is a security error, we consider cookies as disabled
|
||||
if (error instanceof Error && error.name === 'SecurityError') {
|
||||
return true;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
* Get an item from local storage safely.
|
||||
*/
|
||||
export function getItem<T>(key: string, defaultValue: T): T {
|
||||
if (typeof localStorage === 'undefined') {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof localStorage === 'undefined') {
|
||||
return defaultValue;
|
||||
}
|
||||
const stored = localStorage.getItem(key);
|
||||
return stored ? (JSON.parse(stored) as T) : defaultValue;
|
||||
} catch (error) {
|
||||
@@ -21,11 +20,10 @@ export function getItem<T>(key: string, defaultValue: T): T {
|
||||
* Set an item in local storage safely.
|
||||
*/
|
||||
export function setItem(key: string, value: unknown) {
|
||||
if (typeof localStorage === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof localStorage === 'undefined') {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === 'SecurityError') {
|
||||
|
||||
@@ -58,6 +58,11 @@ export function ElementWebframe(props: ContentKitClientElementProps<ContentKitWe
|
||||
}
|
||||
|
||||
const message = event.data;
|
||||
|
||||
if (!URL.canParse(event.origin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const origin = new URL(event.origin);
|
||||
|
||||
// For security reasons, only iframe from our integrations domains are allowed
|
||||
|
||||
Reference in New Issue
Block a user