mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 08:05:19 +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.
|
* Return `undefined` if state is not known.
|
||||||
*/
|
*/
|
||||||
export function isCookiesTrackingDisabled() {
|
export function isCookiesTrackingDisabled() {
|
||||||
const state = cookies.get(GRANTED_COOKIE);
|
try {
|
||||||
|
const state = cookies.get(GRANTED_COOKIE);
|
||||||
|
|
||||||
if (state === 'yes') {
|
if (state === 'yes') {
|
||||||
return false;
|
return false;
|
||||||
} else if (state === 'no') {
|
} else if (state === 'no') {
|
||||||
return true;
|
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.
|
* Get an item from local storage safely.
|
||||||
*/
|
*/
|
||||||
export function getItem<T>(key: string, defaultValue: T): T {
|
export function getItem<T>(key: string, defaultValue: T): T {
|
||||||
if (typeof localStorage === 'undefined') {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (typeof localStorage === 'undefined') {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
const stored = localStorage.getItem(key);
|
const stored = localStorage.getItem(key);
|
||||||
return stored ? (JSON.parse(stored) as T) : defaultValue;
|
return stored ? (JSON.parse(stored) as T) : defaultValue;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -21,11 +20,10 @@ export function getItem<T>(key: string, defaultValue: T): T {
|
|||||||
* Set an item in local storage safely.
|
* Set an item in local storage safely.
|
||||||
*/
|
*/
|
||||||
export function setItem(key: string, value: unknown) {
|
export function setItem(key: string, value: unknown) {
|
||||||
if (typeof localStorage === 'undefined') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (typeof localStorage === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
localStorage.setItem(key, JSON.stringify(value));
|
localStorage.setItem(key, JSON.stringify(value));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error && error.name === 'SecurityError') {
|
if (error instanceof Error && error.name === 'SecurityError') {
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ export function ElementWebframe(props: ContentKitClientElementProps<ContentKitWe
|
|||||||
}
|
}
|
||||||
|
|
||||||
const message = event.data;
|
const message = event.data;
|
||||||
|
|
||||||
|
if (!URL.canParse(event.origin)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const origin = new URL(event.origin);
|
const origin = new URL(event.origin);
|
||||||
|
|
||||||
// For security reasons, only iframe from our integrations domains are allowed
|
// For security reasons, only iframe from our integrations domains are allowed
|
||||||
|
|||||||
Reference in New Issue
Block a user