@microsoft/omnichannel-chat-widget 1.8.1-main.4fb8cb5 → 1.8.1-main.565f247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/common/telemetry/TelemetryConstants.js +0 -4
- package/lib/cjs/common/telemetry/TelemetryManager.js +2 -2
- package/lib/cjs/common/utils.js +0 -3
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +3 -7
- package/lib/cjs/components/livechatwidget/LiveChatWidget.js +2 -12
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +0 -4
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +1 -30
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +19 -31
- package/lib/cjs/components/ooohpanestateful/OOOHPaneStateful.js +2 -23
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +5 -14
- package/lib/cjs/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.js +0 -1
- package/lib/esm/common/telemetry/TelemetryConstants.js +0 -4
- package/lib/esm/common/telemetry/TelemetryManager.js +2 -2
- package/lib/esm/common/utils.js +0 -3
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +3 -7
- package/lib/esm/components/livechatwidget/LiveChatWidget.js +3 -13
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +0 -4
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +0 -28
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +19 -31
- package/lib/esm/components/ooohpanestateful/OOOHPaneStateful.js +2 -23
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +5 -14
- package/lib/esm/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.js +0 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +0 -4
- package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +0 -1
- package/lib/types/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.d.ts +1 -2
- package/lib/types/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +0 -1
- package/package.json +2 -2
- package/lib/cjs/common/utils/xssUtils.js +0 -79
- package/lib/cjs/components/errorboundary/ErrorBoundary.js +0 -68
- package/lib/esm/common/utils/xssUtils.js +0 -72
- package/lib/esm/components/errorboundary/ErrorBoundary.js +0 -59
- package/lib/types/common/utils/xssUtils.d.ts +0 -29
- package/lib/types/components/errorboundary/ErrorBoundary.d.ts +0 -14
|
@@ -48,6 +48,7 @@ import { initCallingSdk } from "../common/initCallingSdk";
|
|
|
48
48
|
import { initConfirmationPropsComposer } from "../common/initConfirmationPropsComposer";
|
|
49
49
|
import { initWebChatComposer } from "../common/initWebChatComposer";
|
|
50
50
|
import { registerBroadcastServiceForStorage } from "../../../common/storage/default/defaultCacheManager";
|
|
51
|
+
import { registerTelemetryLoggers } from "../common/registerTelemetryLoggers";
|
|
51
52
|
import { setPostChatContextAndLoadSurvey } from "../common/setPostChatContextAndLoadSurvey";
|
|
52
53
|
import { startProactiveChat } from "../common/startProactiveChat";
|
|
53
54
|
import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
|
|
@@ -55,7 +56,7 @@ import useChatContextStore from "../../../hooks/useChatContextStore";
|
|
|
55
56
|
import useFacadeSDKStore from "../../../hooks/useFacadeChatSDKStore";
|
|
56
57
|
let uiTimer;
|
|
57
58
|
export const LiveChatWidgetStateful = props => {
|
|
58
|
-
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$
|
|
59
|
+
var _props$webChatContain, _props$styleProps, _props$webChatContain2, _props$webChatContain3, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain7, _state$appStates14, _props$webChatContain9, _props$webChatContain10, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _props$webChatContain11, _props$webChatContain12, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _props$webChatContain17, _props$webChatContain18, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
|
|
59
60
|
useEffect(() => {
|
|
60
61
|
uiTimer = createTimer();
|
|
61
62
|
TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
|
|
@@ -74,13 +75,10 @@ export const LiveChatWidgetStateful = props => {
|
|
|
74
75
|
const [facadeChatSDK] = useFacadeSDKStore();
|
|
75
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
77
|
const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = useState(undefined);
|
|
77
|
-
const [conversationId, setConversationId] = useState("");
|
|
78
78
|
const {
|
|
79
79
|
Composer
|
|
80
80
|
} = Components;
|
|
81
81
|
const canStartProactiveChat = useRef(true);
|
|
82
|
-
const bubbleBackground = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : (_props$webChatContain3 = _props$webChatContain2.webChatStyles) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.bubbleBackground) ?? ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : (_props$webChatContain5 = _props$webChatContain4.adaptiveCardStyles) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.background) ?? defaultAdaptiveCardStyles.background;
|
|
83
|
-
const bubbleTextColor = ((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : (_props$webChatContain7 = _props$webChatContain6.webChatStyles) === null || _props$webChatContain7 === void 0 ? void 0 : _props$webChatContain7.bubbleTextColor) ?? ((_props$webChatContain8 = props.webChatContainerProps) === null || _props$webChatContain8 === void 0 ? void 0 : (_props$webChatContain9 = _props$webChatContain8.adaptiveCardStyles) === null || _props$webChatContain9 === void 0 ? void 0 : _props$webChatContain9.color) ?? defaultAdaptiveCardStyles.color;
|
|
84
82
|
|
|
85
83
|
// Process general styles
|
|
86
84
|
const generalStyles = {
|
|
@@ -89,7 +87,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
89
87
|
|
|
90
88
|
//Scrollbar styles
|
|
91
89
|
const scrollbarProps = Object.assign({}, defaultScrollBarProps, props === null || props === void 0 ? void 0 : props.scrollBarProps);
|
|
92
|
-
const sendBoxTextArea = props === null || props === void 0 ? void 0 : (_props$
|
|
90
|
+
const sendBoxTextArea = props === null || props === void 0 ? void 0 : (_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : (_props$webChatContain3 = _props$webChatContain2.sendBoxTextBox) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.textarea;
|
|
93
91
|
|
|
94
92
|
// In case the broadcast channel is already initialized elsewhere; One tab can only hold 1 instance
|
|
95
93
|
if ((props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.skipBroadcastChannelInit) !== true) {
|
|
@@ -222,6 +220,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
222
220
|
state.domainStates.confirmationPaneConfirmedOptionClicked = false;
|
|
223
221
|
state.domainStates.confirmationState = ConfirmationState.NotSet;
|
|
224
222
|
setupClientDataStore();
|
|
223
|
+
registerTelemetryLoggers(props, dispatch);
|
|
225
224
|
createInternetConnectionChangeHandler(state);
|
|
226
225
|
dispatch({
|
|
227
226
|
type: LiveChatWidgetActionType.SET_WIDGET_ELEMENT_ID,
|
|
@@ -571,14 +570,6 @@ export const LiveChatWidgetStateful = props => {
|
|
|
571
570
|
});
|
|
572
571
|
});
|
|
573
572
|
|
|
574
|
-
// Retrieve convId
|
|
575
|
-
BroadcastService.getMessageByEventName(BroadcastEvent.UpdateConversationDataForTelemetry).subscribe(msg => {
|
|
576
|
-
var _msg$payload11, _msg$payload11$liveWo;
|
|
577
|
-
if ((_msg$payload11 = msg.payload) !== null && _msg$payload11 !== void 0 && (_msg$payload11$liveWo = _msg$payload11.liveWorkItem) !== null && _msg$payload11$liveWo !== void 0 && _msg$payload11$liveWo.conversationId) {
|
|
578
|
-
setConversationId(msg.payload.liveWorkItem.conversationId);
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
|
|
582
573
|
// Check for TPC and log in telemetry if blocked
|
|
583
574
|
isCookieAllowed();
|
|
584
575
|
return () => {
|
|
@@ -625,8 +616,8 @@ export const LiveChatWidgetStateful = props => {
|
|
|
625
616
|
});
|
|
626
617
|
}
|
|
627
618
|
if (state.appStates.conversationState === ConversationState.InActive) {
|
|
628
|
-
var _props$
|
|
629
|
-
if ((props === null || props === void 0 ? void 0 : (_props$
|
|
619
|
+
var _props$webChatContain4, _props$webChatContain5;
|
|
620
|
+
if ((props === null || props === void 0 ? void 0 : (_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : (_props$webChatContain5 = _props$webChatContain4.renderingMiddlewareProps) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.hideSendboxOnConversationEnd) !== false) {
|
|
630
621
|
setWebChatStyles(styles => {
|
|
631
622
|
return {
|
|
632
623
|
...styles,
|
|
@@ -670,12 +661,12 @@ export const LiveChatWidgetStateful = props => {
|
|
|
670
661
|
}
|
|
671
662
|
}, [state.appStates.unreadMessageCount]);
|
|
672
663
|
useEffect(() => {
|
|
673
|
-
var _props$
|
|
664
|
+
var _props$webChatContain6;
|
|
674
665
|
setWebChatStyles({
|
|
675
666
|
...webChatStyles,
|
|
676
|
-
...((_props$
|
|
667
|
+
...((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.webChatStyles)
|
|
677
668
|
});
|
|
678
|
-
}, [(_props$
|
|
669
|
+
}, [(_props$webChatContain7 = props.webChatContainerProps) === null || _props$webChatContain7 === void 0 ? void 0 : _props$webChatContain7.webChatStyles]);
|
|
679
670
|
useEffect(() => {
|
|
680
671
|
//Confirmation pane dismissing through OK option, so proceed with end chat
|
|
681
672
|
if (state.domainStates.confirmationState === ConfirmationState.Ok) {
|
|
@@ -774,12 +765,12 @@ export const LiveChatWidgetStateful = props => {
|
|
|
774
765
|
|
|
775
766
|
// if props state gets updates we need to update the renderingMiddlewareProps in the state
|
|
776
767
|
useEffect(() => {
|
|
777
|
-
var _props$
|
|
768
|
+
var _props$webChatContain8;
|
|
778
769
|
dispatch({
|
|
779
770
|
type: LiveChatWidgetActionType.SET_RENDERING_MIDDLEWARE_PROPS,
|
|
780
|
-
payload: (_props$
|
|
771
|
+
payload: (_props$webChatContain8 = props.webChatContainerProps) === null || _props$webChatContain8 === void 0 ? void 0 : _props$webChatContain8.renderingMiddlewareProps
|
|
781
772
|
});
|
|
782
|
-
}, [(_props$
|
|
773
|
+
}, [(_props$webChatContain9 = props.webChatContainerProps) === null || _props$webChatContain9 === void 0 ? void 0 : _props$webChatContain9.renderingMiddlewareProps]);
|
|
783
774
|
useEffect(() => {
|
|
784
775
|
TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
|
|
785
776
|
Event: TelemetryEvent.UXLiveChatWidgetCompleted,
|
|
@@ -822,7 +813,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
822
813
|
const webChatProps = initWebChatComposer(props, state, dispatch, facadeChatSDK, endChatRelay);
|
|
823
814
|
const downloadTranscriptProps = createDownloadTranscriptProps(props.downloadTranscriptProps, {
|
|
824
815
|
...(defaultWebChatContainerStatefulProps === null || defaultWebChatContainerStatefulProps === void 0 ? void 0 : defaultWebChatContainerStatefulProps.webChatStyles),
|
|
825
|
-
...((_props$
|
|
816
|
+
...((_props$webChatContain10 = props.webChatContainerProps) === null || _props$webChatContain10 === void 0 ? void 0 : _props$webChatContain10.webChatStyles)
|
|
826
817
|
}, props.webChatContainerProps);
|
|
827
818
|
const livechatProps = {
|
|
828
819
|
...props,
|
|
@@ -848,11 +839,6 @@ export const LiveChatWidgetStateful = props => {
|
|
|
848
839
|
setOcUserAgent(facadeChatSDK.getChatSDK());
|
|
849
840
|
const directLine = ((_livechatProps$webCha = livechatProps.webChatContainerProps) === null || _livechatProps$webCha === void 0 ? void 0 : _livechatProps$webCha.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine;
|
|
850
841
|
const userID = directLine.getState ? directLine === null || directLine === void 0 ? void 0 : directLine.getState("acs.userId") : "teamsvisitor";
|
|
851
|
-
const styleOptions = React.useMemo(() => ({
|
|
852
|
-
...webChatStyles,
|
|
853
|
-
bubbleBackground,
|
|
854
|
-
bubbleTextColor
|
|
855
|
-
}), [webChatStyles, bubbleBackground, bubbleTextColor]);
|
|
856
842
|
|
|
857
843
|
// WebChat's Composer can only be rendered if a directLine object is defined
|
|
858
844
|
return directLine && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, `
|
|
@@ -891,7 +877,11 @@ export const LiveChatWidgetStateful = props => {
|
|
|
891
877
|
}`}
|
|
892
878
|
`), /*#__PURE__*/React.createElement(DraggableChatWidget, chatWidgetDraggableConfig, /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
893
879
|
userID: userID,
|
|
894
|
-
styleOptions:
|
|
880
|
+
styleOptions: {
|
|
881
|
+
...webChatStyles,
|
|
882
|
+
bubbleBackground: ((_props$webChatContain11 = props.webChatContainerProps) === null || _props$webChatContain11 === void 0 ? void 0 : (_props$webChatContain12 = _props$webChatContain11.webChatStyles) === null || _props$webChatContain12 === void 0 ? void 0 : _props$webChatContain12.bubbleBackground) ?? ((_props$webChatContain13 = props.webChatContainerProps) === null || _props$webChatContain13 === void 0 ? void 0 : (_props$webChatContain14 = _props$webChatContain13.adaptiveCardStyles) === null || _props$webChatContain14 === void 0 ? void 0 : _props$webChatContain14.background) ?? defaultAdaptiveCardStyles.background,
|
|
883
|
+
bubbleTextColor: ((_props$webChatContain15 = props.webChatContainerProps) === null || _props$webChatContain15 === void 0 ? void 0 : (_props$webChatContain16 = _props$webChatContain15.webChatStyles) === null || _props$webChatContain16 === void 0 ? void 0 : _props$webChatContain16.bubbleTextColor) ?? ((_props$webChatContain17 = props.webChatContainerProps) === null || _props$webChatContain17 === void 0 ? void 0 : (_props$webChatContain18 = _props$webChatContain17.adaptiveCardStyles) === null || _props$webChatContain18 === void 0 ? void 0 : _props$webChatContain18.color) ?? defaultAdaptiveCardStyles.color
|
|
884
|
+
},
|
|
895
885
|
directLine: directLine
|
|
896
886
|
}), /*#__PURE__*/React.createElement(Stack, {
|
|
897
887
|
id: widgetElementId,
|
|
@@ -922,8 +912,6 @@ export const LiveChatWidgetStateful = props => {
|
|
|
922
912
|
}, livechatProps.callingContainerProps)), !((_livechatProps$contro11 = livechatProps.controlProps) !== null && _livechatProps$contro11 !== void 0 && _livechatProps$contro11.hideWebChatContainer) && shouldShowWebChatContainer(state) && (decodeComponentString((_livechatProps$compon9 = livechatProps.componentOverrides) === null || _livechatProps$compon9 === void 0 ? void 0 : _livechatProps$compon9.webChatContainer) || /*#__PURE__*/React.createElement(WebChatContainerStateful, livechatProps)), !((_livechatProps$contro12 = livechatProps.controlProps) !== null && _livechatProps$contro12 !== void 0 && _livechatProps$contro12.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_livechatProps$compon10 = livechatProps.componentOverrides) === null || _livechatProps$compon10 === void 0 ? void 0 : _livechatProps$compon10.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
|
|
923
913
|
setPostChatContext: setPostChatContextRelay,
|
|
924
914
|
prepareEndChat: prepareEndChatRelay
|
|
925
|
-
}))), !((_livechatProps$contro13 = livechatProps.controlProps) !== null && _livechatProps$contro13 !== void 0 && _livechatProps$contro13.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_livechatProps$compon11 = livechatProps.componentOverrides) === null || _livechatProps$compon11 === void 0 ? void 0 : _livechatProps$compon11.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, livechatProps.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_livechatProps$compon12 = livechatProps.componentOverrides) === null || _livechatProps$compon12 === void 0 ? void 0 : _livechatProps$compon12.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, livechatProps.postChatSurveyPaneProps, livechatProps.chatSDK,
|
|
926
|
-
customerVoiceSurveyCorrelationId: conversationId
|
|
927
|
-
}))), createFooter(livechatProps, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_livechatProps$compon13 = livechatProps.componentOverrides) === null || _livechatProps$compon13 === void 0 ? void 0 : _livechatProps$compon13.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, livechatProps.emailTranscriptPane))))));
|
|
915
|
+
}))), !((_livechatProps$contro13 = livechatProps.controlProps) !== null && _livechatProps$contro13 !== void 0 && _livechatProps$contro13.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_livechatProps$compon11 = livechatProps.componentOverrides) === null || _livechatProps$compon11 === void 0 ? void 0 : _livechatProps$compon11.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, livechatProps.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_livechatProps$compon12 = livechatProps.componentOverrides) === null || _livechatProps$compon12 === void 0 ? void 0 : _livechatProps$compon12.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, livechatProps.postChatSurveyPaneProps, livechatProps.chatSDK))), createFooter(livechatProps, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_livechatProps$compon13 = livechatProps.componentOverrides) === null || _livechatProps$compon13 === void 0 ? void 0 : _livechatProps$compon13.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, livechatProps.emailTranscriptPane))))));
|
|
928
916
|
};
|
|
929
917
|
export default LiveChatWidgetStateful;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
|
|
2
2
|
import React, { useEffect } from "react";
|
|
3
3
|
import { createTimer, findAllFocusableElement } from "../../common/utils";
|
|
4
|
+
import DOMPurify from "dompurify";
|
|
4
5
|
import { OutOfOfficeHoursPane } from "@microsoft/omnichannel-chat-components";
|
|
5
6
|
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
6
7
|
import { defaultGeneralStyleProps } from "./common/defaultStyleProps/defaultgeneralOOOHPaneStyleProps";
|
|
7
|
-
import { detectAndCleanXSS } from "../../common/utils/xssUtils";
|
|
8
8
|
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
9
9
|
let uiTimer;
|
|
10
|
-
const OOOHPaneTitleText = "Thanks for contacting us. You have reached us outside of our operating hours. An agent will respond when we open.";
|
|
11
10
|
export const OutOfOfficeHoursPaneStateful = props => {
|
|
12
11
|
var _props$styleProps;
|
|
13
12
|
useEffect(() => {
|
|
@@ -46,28 +45,8 @@ export const OutOfOfficeHoursPaneStateful = props => {
|
|
|
46
45
|
ElapsedTimeInMilliseconds: uiTimer.milliSecondsElapsed
|
|
47
46
|
});
|
|
48
47
|
}, []);
|
|
49
|
-
|
|
50
|
-
// Enhanced titleText sanitization
|
|
51
48
|
if (controlProps !== null && controlProps !== void 0 && controlProps.titleText) {
|
|
52
|
-
|
|
53
|
-
cleanText,
|
|
54
|
-
isXSSDetected
|
|
55
|
-
} = detectAndCleanXSS(controlProps.titleText);
|
|
56
|
-
if (!isXSSDetected) {
|
|
57
|
-
// replace with the sanitized text
|
|
58
|
-
controlProps.titleText = cleanText;
|
|
59
|
-
} else {
|
|
60
|
-
TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.WARN, {
|
|
61
|
-
Event: TelemetryEvent.XSSTextDetected,
|
|
62
|
-
Description: "Potential XSS attempt detected in titleText",
|
|
63
|
-
CustomProperties: {
|
|
64
|
-
originalText: controlProps.titleText.substring(0, 100),
|
|
65
|
-
// Log first 100 chars for analysis
|
|
66
|
-
cleanedText: cleanText.substring(0, 100)
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
controlProps.titleText = OOOHPaneTitleText;
|
|
70
|
-
}
|
|
49
|
+
controlProps.titleText = DOMPurify.sanitize(controlProps.titleText);
|
|
71
50
|
}
|
|
72
51
|
return /*#__PURE__*/React.createElement(OutOfOfficeHoursPane, {
|
|
73
52
|
componentOverrides: props.componentOverrides,
|
|
@@ -9,14 +9,13 @@ import { defaultGeneralPostChatSurveyPaneStyleProps } from "./common/defaultStyl
|
|
|
9
9
|
import { findAllFocusableElement } from "../../common/utils";
|
|
10
10
|
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
11
11
|
import isValidSurveyUrl from "./common/isValidSurveyUrl";
|
|
12
|
-
const generateSurveyInviteLink = function (surveyInviteLink, isEmbed, locale, compact
|
|
13
|
-
let showMultiLingual = arguments.length >
|
|
12
|
+
const generateSurveyInviteLink = function (surveyInviteLink, isEmbed, locale, compact) {
|
|
13
|
+
let showMultiLingual = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
14
14
|
const surveyLinkParams = new URLSearchParams({
|
|
15
15
|
embed: isEmbed.toString(),
|
|
16
16
|
compact: (compact ?? true).toString(),
|
|
17
17
|
lang: locale ?? "en-us",
|
|
18
|
-
showmultilingual: (showMultiLingual ?? false).toString()
|
|
19
|
-
cvResponsePageRequestId: customerVoiceSurveyCorrelationId
|
|
18
|
+
showmultilingual: (showMultiLingual ?? false).toString()
|
|
20
19
|
});
|
|
21
20
|
return `${surveyInviteLink}&${surveyLinkParams.toString()}`;
|
|
22
21
|
};
|
|
@@ -32,9 +31,9 @@ export const PostChatSurveyPaneStateful = props => {
|
|
|
32
31
|
// Bot survey enabled
|
|
33
32
|
state.appStates.postChatParticipantType === ParticipantType.Bot) {
|
|
34
33
|
// Only Bot has engaged
|
|
35
|
-
surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.botSurveyInviteLink, surveyMode, state.domainStates.postChatContext.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true
|
|
34
|
+
surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.botSurveyInviteLink, surveyMode, state.domainStates.postChatContext.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true);
|
|
36
35
|
} else {
|
|
37
|
-
surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.surveyInviteLink, surveyMode, state.domainStates.postChatContext.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true
|
|
36
|
+
surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.surveyInviteLink, surveyMode, state.domainStates.postChatContext.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true);
|
|
38
37
|
}
|
|
39
38
|
if (props.copilotSurveyContext) {
|
|
40
39
|
surveyInviteLink = `${surveyInviteLink}&mcs_additionalcontext=${JSON.stringify(props.copilotSurveyContext)}`;
|
|
@@ -97,14 +96,6 @@ export const PostChatSurveyPaneStateful = props => {
|
|
|
97
96
|
message: "Customer Voice form response error."
|
|
98
97
|
}
|
|
99
98
|
});
|
|
100
|
-
} else if (typeof data === "string" && data.startsWith(CustomerVoiceEvents.FormsError)) {
|
|
101
|
-
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.ERROR, {
|
|
102
|
-
Event: TelemetryEvent.CustomerVoiceFormsError,
|
|
103
|
-
Description: "Customer Voice failed to load with forms error.",
|
|
104
|
-
ExceptionDetails: {
|
|
105
|
-
message: `Customer Voice forms error details: ${data}`
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
99
|
}
|
|
109
100
|
});
|
|
110
101
|
}, []);
|
|
@@ -3,5 +3,4 @@ export let CustomerVoiceEvents;
|
|
|
3
3
|
CustomerVoiceEvents["ResponsePageLoaded"] = "ResponsePageLoaded";
|
|
4
4
|
CustomerVoiceEvents["FormResponseSubmitted"] = "FormResponseSubmitted";
|
|
5
5
|
CustomerVoiceEvents["FormResponseError"] = "FormResponseError";
|
|
6
|
-
CustomerVoiceEvents["FormsError"] = "FormsError";
|
|
7
6
|
})(CustomerVoiceEvents || (CustomerVoiceEvents = {}));
|
|
@@ -94,8 +94,6 @@ export declare enum TelemetryEvent {
|
|
|
94
94
|
DisconnectEndChatSDKCallFailed = "DisconnectEndChatSDKCallFailed",
|
|
95
95
|
GetChatReconnectContextSDKCallStarted = "GetChatReconnectContextSDKCallStarted",
|
|
96
96
|
GetChatReconnectContextSDKCallFailed = "GetChatReconnectContextSDKCallFailed",
|
|
97
|
-
CheckContactIdError = "checkContactIdError",
|
|
98
|
-
GetChatReconnectContextSDKCallSucceeded = "GetChatReconnectContextSDKCallSucceeded",
|
|
99
97
|
ParseAdaptiveCardFailed = "ParseAdaptiveCardFailed",
|
|
100
98
|
ClientDataStoreProviderFailed = "ClientDataStoreProviderFailed",
|
|
101
99
|
InMemoryDataStoreFailed = "InMemoryDataStoreFailed",
|
|
@@ -163,7 +161,6 @@ export declare enum TelemetryEvent {
|
|
|
163
161
|
CustomerVoiceResponsePageLoaded = "CustomerVoiceResponsePageLoaded",
|
|
164
162
|
CustomerVoiceFormResponseSubmitted = "CustomerVoiceFormResponseSubmitted",
|
|
165
163
|
CustomerVoiceFormResponseError = "CustomerVoiceFormResponseError",
|
|
166
|
-
CustomerVoiceFormsError = "CustomerVoiceFormsError",
|
|
167
164
|
BotAuthActivityEmptySasUrl = "BotAuthActivityEmptySasUrl",
|
|
168
165
|
SetBotAuthProviderFetchConfig = "SetBotAuthProviderFetchConfig",
|
|
169
166
|
SetBotAuthProviderHideCard = "SetBotAuthProviderHideCard",
|
|
@@ -241,7 +238,6 @@ export declare enum TelemetryEvent {
|
|
|
241
238
|
UXNotificationPaneCompleted = "UXNotificationPaneCompleted",
|
|
242
239
|
UXOutOfOfficeHoursPaneStart = "UXOutOfOfficeHoursPaneStart",
|
|
243
240
|
UXOutOfOfficeHoursPaneCompleted = "UXOutOfOfficeHoursPaneCompleted",
|
|
244
|
-
XSSTextDetected = "XSSTextDetected",
|
|
245
241
|
UXPostChatLoadingPaneStart = "UXPostChatLoadingPaneStart",
|
|
246
242
|
UXPostChatLoadingPaneCompleted = "UXPostChatLoadingPaneCompleted",
|
|
247
243
|
UXPrechatPaneStart = "UXPrechatPaneStart",
|
|
@@ -4,4 +4,3 @@ import { ILiveChatWidgetAction } from "../../../contexts/common/ILiveChatWidgetA
|
|
|
4
4
|
import { ILiveChatWidgetProps } from "../interfaces/ILiveChatWidgetProps";
|
|
5
5
|
export declare const handleStartChatError: (dispatch: Dispatch<ILiveChatWidgetAction>, facadeChatSDK: FacadeChatSDK, props: ILiveChatWidgetProps | undefined, ex: any, isStartChatSuccessful: boolean) => void;
|
|
6
6
|
export declare const logWidgetLoadComplete: (additionalMessage?: string) => void;
|
|
7
|
-
export declare const logWidgetLoadWithUnexpectedError: (ex: any) => void;
|
|
@@ -2,5 +2,4 @@ import { IPostChatSurveyPaneProps } from "@microsoft/omnichannel-chat-components
|
|
|
2
2
|
export interface IPostChatSurveyPaneStatefulProps extends IPostChatSurveyPaneProps {
|
|
3
3
|
isCustomerVoiceSurveyCompact?: boolean;
|
|
4
4
|
copilotSurveyContext?: Record<string, string>;
|
|
5
|
-
customerVoiceSurveyCorrelationId?: string;
|
|
6
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/omnichannel-chat-widget",
|
|
3
|
-
"version": "1.8.1-main.
|
|
3
|
+
"version": "1.8.1-main.565f247",
|
|
4
4
|
"description": "Microsoft Omnichannel Chat Widget",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"@azure/core-tracing": "^1.2.0",
|
|
88
88
|
"@microsoft/applicationinsights-web": "^3.3.6",
|
|
89
89
|
"@microsoft/omnichannel-chat-components": "1.1.12",
|
|
90
|
-
"@microsoft/omnichannel-chat-sdk": "^1.11.
|
|
90
|
+
"@microsoft/omnichannel-chat-sdk": "^1.11.1",
|
|
91
91
|
"@opentelemetry/api": "^1.9.0",
|
|
92
92
|
"abort-controller": "^3",
|
|
93
93
|
"abort-controller-es5": "^2.0.1",
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.detectAndCleanXSS = void 0;
|
|
7
|
-
var _dompurify = _interopRequireDefault(require("dompurify"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
/**
|
|
10
|
-
* Detects potential Cross-Site Scripting (XSS) attacks in text input and sanitizes the content.
|
|
11
|
-
*
|
|
12
|
-
* This function performs comprehensive XSS detection using pattern matching for common attack vectors
|
|
13
|
-
* and then sanitizes the input using DOMPurify with strict configuration. It's designed to protect
|
|
14
|
-
* against various XSS techniques including script injection, event handler injection, style-based
|
|
15
|
-
* attacks, and encoded payloads.
|
|
16
|
-
*
|
|
17
|
-
* Security patterns detected:
|
|
18
|
-
* - JavaScript protocol URLs (javascript:)
|
|
19
|
-
* - HTML event handlers (onmouseover, onclick, etc.)
|
|
20
|
-
* - Script tags (<script>)
|
|
21
|
-
* - CSS expression() functions
|
|
22
|
-
* - CSS url() functions
|
|
23
|
-
* - Position-based CSS attacks (position: fixed/absolute)
|
|
24
|
-
* - VBScript protocol URLs
|
|
25
|
-
* - Data URLs with HTML content
|
|
26
|
-
* - Fragment identifiers with escaped quotes
|
|
27
|
-
* - HTML entity-encoded angle brackets
|
|
28
|
-
*
|
|
29
|
-
* @param text - The input text to be analyzed and sanitized
|
|
30
|
-
* @returns An object containing:
|
|
31
|
-
* - cleanText: The sanitized version of the input text with all HTML tags and attributes removed
|
|
32
|
-
* - isXSSDetected: Boolean flag indicating whether potential XSS patterns were found in the original text
|
|
33
|
-
*/
|
|
34
|
-
const detectAndCleanXSS = text => {
|
|
35
|
-
// Comprehensive array of regular expressions to detect common XSS attack patterns
|
|
36
|
-
const xssPatterns = [/javascript\s*:/gi,
|
|
37
|
-
// JavaScript protocol URLs (with optional spaces)
|
|
38
|
-
/vbscript\s*:/gi,
|
|
39
|
-
// VBScript protocol URLs (with optional spaces)
|
|
40
|
-
/on\w+\s*=/gi,
|
|
41
|
-
// HTML event handlers (onmouseover, onclick, onload, etc.)
|
|
42
|
-
/<\s*script/gi,
|
|
43
|
-
// Script tag opening (with optional spaces)
|
|
44
|
-
/expression\s*\(/gi,
|
|
45
|
-
// CSS expression() function (IE-specific)
|
|
46
|
-
/url\s*\(/gi,
|
|
47
|
-
// CSS url() function
|
|
48
|
-
/style\s*=.*position\s*:\s*fixed/gi,
|
|
49
|
-
// CSS position fixed attacks
|
|
50
|
-
/style\s*=.*position\s*:\s*absolute/gi,
|
|
51
|
-
// CSS position absolute attacks
|
|
52
|
-
/data\s*:\s*text\s*\/\s*html/gi,
|
|
53
|
-
// Data URLs containing HTML
|
|
54
|
-
/#.*\\"/gi,
|
|
55
|
-
// Fragment identifiers with escaped quotes
|
|
56
|
-
/>.*</gi // HTML entity-encoded angle brackets indicating tag structure
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
// Check if any XSS patterns are detected in the input text
|
|
60
|
-
const isXSSDetected = xssPatterns.some(pattern => pattern.test(text));
|
|
61
|
-
|
|
62
|
-
// Clean the text using DOMPurify with strict config
|
|
63
|
-
const cleanText = _dompurify.default.sanitize(text, {
|
|
64
|
-
ALLOWED_TAGS: [],
|
|
65
|
-
// No HTML tags allowed in title
|
|
66
|
-
ALLOWED_ATTR: [],
|
|
67
|
-
KEEP_CONTENT: true,
|
|
68
|
-
// Keep text content
|
|
69
|
-
ALLOW_DATA_ATTR: false,
|
|
70
|
-
ALLOW_UNKNOWN_PROTOCOLS: false,
|
|
71
|
-
SANITIZE_DOM: true,
|
|
72
|
-
FORCE_BODY: false
|
|
73
|
-
});
|
|
74
|
-
return {
|
|
75
|
-
cleanText,
|
|
76
|
-
isXSSDetected
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
exports.detectAndCleanXSS = detectAndCleanXSS;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
16
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
17
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
18
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
19
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
21
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
-
const RenderChildrenFunction = _ref => {
|
|
23
|
-
let {
|
|
24
|
-
children
|
|
25
|
-
} = _ref;
|
|
26
|
-
return typeof children === 'function' ? children() : children;
|
|
27
|
-
};
|
|
28
|
-
let ErrorBoundary = /*#__PURE__*/function (_Component) {
|
|
29
|
-
_inherits(ErrorBoundary, _Component);
|
|
30
|
-
var _super = _createSuper(ErrorBoundary);
|
|
31
|
-
function ErrorBoundary(props) {
|
|
32
|
-
var _this;
|
|
33
|
-
_classCallCheck(this, ErrorBoundary);
|
|
34
|
-
_this = _super.call(this, props);
|
|
35
|
-
_this.state = {
|
|
36
|
-
hasError: false
|
|
37
|
-
};
|
|
38
|
-
return _this;
|
|
39
|
-
}
|
|
40
|
-
_createClass(ErrorBoundary, [{
|
|
41
|
-
key: "componentDidCatch",
|
|
42
|
-
value: function componentDidCatch(error) {
|
|
43
|
-
const {
|
|
44
|
-
onError
|
|
45
|
-
} = this.props;
|
|
46
|
-
this.setState({
|
|
47
|
-
hasError: true
|
|
48
|
-
});
|
|
49
|
-
if (onError) {
|
|
50
|
-
onError(error);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
key: "render",
|
|
55
|
-
value: function render() {
|
|
56
|
-
const {
|
|
57
|
-
children
|
|
58
|
-
} = this.props;
|
|
59
|
-
const {
|
|
60
|
-
hasError
|
|
61
|
-
} = this.state;
|
|
62
|
-
return !hasError && /*#__PURE__*/_react.default.createElement(RenderChildrenFunction, null, children);
|
|
63
|
-
}
|
|
64
|
-
}]);
|
|
65
|
-
return ErrorBoundary;
|
|
66
|
-
}(_react.Component);
|
|
67
|
-
var _default = ErrorBoundary;
|
|
68
|
-
exports.default = _default;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import DOMPurify from "dompurify";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Detects potential Cross-Site Scripting (XSS) attacks in text input and sanitizes the content.
|
|
5
|
-
*
|
|
6
|
-
* This function performs comprehensive XSS detection using pattern matching for common attack vectors
|
|
7
|
-
* and then sanitizes the input using DOMPurify with strict configuration. It's designed to protect
|
|
8
|
-
* against various XSS techniques including script injection, event handler injection, style-based
|
|
9
|
-
* attacks, and encoded payloads.
|
|
10
|
-
*
|
|
11
|
-
* Security patterns detected:
|
|
12
|
-
* - JavaScript protocol URLs (javascript:)
|
|
13
|
-
* - HTML event handlers (onmouseover, onclick, etc.)
|
|
14
|
-
* - Script tags (<script>)
|
|
15
|
-
* - CSS expression() functions
|
|
16
|
-
* - CSS url() functions
|
|
17
|
-
* - Position-based CSS attacks (position: fixed/absolute)
|
|
18
|
-
* - VBScript protocol URLs
|
|
19
|
-
* - Data URLs with HTML content
|
|
20
|
-
* - Fragment identifiers with escaped quotes
|
|
21
|
-
* - HTML entity-encoded angle brackets
|
|
22
|
-
*
|
|
23
|
-
* @param text - The input text to be analyzed and sanitized
|
|
24
|
-
* @returns An object containing:
|
|
25
|
-
* - cleanText: The sanitized version of the input text with all HTML tags and attributes removed
|
|
26
|
-
* - isXSSDetected: Boolean flag indicating whether potential XSS patterns were found in the original text
|
|
27
|
-
*/
|
|
28
|
-
export const detectAndCleanXSS = text => {
|
|
29
|
-
// Comprehensive array of regular expressions to detect common XSS attack patterns
|
|
30
|
-
const xssPatterns = [/javascript\s*:/gi,
|
|
31
|
-
// JavaScript protocol URLs (with optional spaces)
|
|
32
|
-
/vbscript\s*:/gi,
|
|
33
|
-
// VBScript protocol URLs (with optional spaces)
|
|
34
|
-
/on\w+\s*=/gi,
|
|
35
|
-
// HTML event handlers (onmouseover, onclick, onload, etc.)
|
|
36
|
-
/<\s*script/gi,
|
|
37
|
-
// Script tag opening (with optional spaces)
|
|
38
|
-
/expression\s*\(/gi,
|
|
39
|
-
// CSS expression() function (IE-specific)
|
|
40
|
-
/url\s*\(/gi,
|
|
41
|
-
// CSS url() function
|
|
42
|
-
/style\s*=.*position\s*:\s*fixed/gi,
|
|
43
|
-
// CSS position fixed attacks
|
|
44
|
-
/style\s*=.*position\s*:\s*absolute/gi,
|
|
45
|
-
// CSS position absolute attacks
|
|
46
|
-
/data\s*:\s*text\s*\/\s*html/gi,
|
|
47
|
-
// Data URLs containing HTML
|
|
48
|
-
/#.*\\"/gi,
|
|
49
|
-
// Fragment identifiers with escaped quotes
|
|
50
|
-
/>.*</gi // HTML entity-encoded angle brackets indicating tag structure
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
// Check if any XSS patterns are detected in the input text
|
|
54
|
-
const isXSSDetected = xssPatterns.some(pattern => pattern.test(text));
|
|
55
|
-
|
|
56
|
-
// Clean the text using DOMPurify with strict config
|
|
57
|
-
const cleanText = DOMPurify.sanitize(text, {
|
|
58
|
-
ALLOWED_TAGS: [],
|
|
59
|
-
// No HTML tags allowed in title
|
|
60
|
-
ALLOWED_ATTR: [],
|
|
61
|
-
KEEP_CONTENT: true,
|
|
62
|
-
// Keep text content
|
|
63
|
-
ALLOW_DATA_ATTR: false,
|
|
64
|
-
ALLOW_UNKNOWN_PROTOCOLS: false,
|
|
65
|
-
SANITIZE_DOM: true,
|
|
66
|
-
FORCE_BODY: false
|
|
67
|
-
});
|
|
68
|
-
return {
|
|
69
|
-
cleanText,
|
|
70
|
-
isXSSDetected
|
|
71
|
-
};
|
|
72
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
3
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
7
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
8
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
10
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
11
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
12
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
13
|
-
import React, { Component } from 'react';
|
|
14
|
-
const RenderChildrenFunction = _ref => {
|
|
15
|
-
let {
|
|
16
|
-
children
|
|
17
|
-
} = _ref;
|
|
18
|
-
return typeof children === 'function' ? children() : children;
|
|
19
|
-
};
|
|
20
|
-
let ErrorBoundary = /*#__PURE__*/function (_Component) {
|
|
21
|
-
_inherits(ErrorBoundary, _Component);
|
|
22
|
-
var _super = _createSuper(ErrorBoundary);
|
|
23
|
-
function ErrorBoundary(props) {
|
|
24
|
-
var _this;
|
|
25
|
-
_classCallCheck(this, ErrorBoundary);
|
|
26
|
-
_this = _super.call(this, props);
|
|
27
|
-
_this.state = {
|
|
28
|
-
hasError: false
|
|
29
|
-
};
|
|
30
|
-
return _this;
|
|
31
|
-
}
|
|
32
|
-
_createClass(ErrorBoundary, [{
|
|
33
|
-
key: "componentDidCatch",
|
|
34
|
-
value: function componentDidCatch(error) {
|
|
35
|
-
const {
|
|
36
|
-
onError
|
|
37
|
-
} = this.props;
|
|
38
|
-
this.setState({
|
|
39
|
-
hasError: true
|
|
40
|
-
});
|
|
41
|
-
if (onError) {
|
|
42
|
-
onError(error);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
key: "render",
|
|
47
|
-
value: function render() {
|
|
48
|
-
const {
|
|
49
|
-
children
|
|
50
|
-
} = this.props;
|
|
51
|
-
const {
|
|
52
|
-
hasError
|
|
53
|
-
} = this.state;
|
|
54
|
-
return !hasError && /*#__PURE__*/React.createElement(RenderChildrenFunction, null, children);
|
|
55
|
-
}
|
|
56
|
-
}]);
|
|
57
|
-
return ErrorBoundary;
|
|
58
|
-
}(Component);
|
|
59
|
-
export default ErrorBoundary;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detects potential Cross-Site Scripting (XSS) attacks in text input and sanitizes the content.
|
|
3
|
-
*
|
|
4
|
-
* This function performs comprehensive XSS detection using pattern matching for common attack vectors
|
|
5
|
-
* and then sanitizes the input using DOMPurify with strict configuration. It's designed to protect
|
|
6
|
-
* against various XSS techniques including script injection, event handler injection, style-based
|
|
7
|
-
* attacks, and encoded payloads.
|
|
8
|
-
*
|
|
9
|
-
* Security patterns detected:
|
|
10
|
-
* - JavaScript protocol URLs (javascript:)
|
|
11
|
-
* - HTML event handlers (onmouseover, onclick, etc.)
|
|
12
|
-
* - Script tags (<script>)
|
|
13
|
-
* - CSS expression() functions
|
|
14
|
-
* - CSS url() functions
|
|
15
|
-
* - Position-based CSS attacks (position: fixed/absolute)
|
|
16
|
-
* - VBScript protocol URLs
|
|
17
|
-
* - Data URLs with HTML content
|
|
18
|
-
* - Fragment identifiers with escaped quotes
|
|
19
|
-
* - HTML entity-encoded angle brackets
|
|
20
|
-
*
|
|
21
|
-
* @param text - The input text to be analyzed and sanitized
|
|
22
|
-
* @returns An object containing:
|
|
23
|
-
* - cleanText: The sanitized version of the input text with all HTML tags and attributes removed
|
|
24
|
-
* - isXSSDetected: Boolean flag indicating whether potential XSS patterns were found in the original text
|
|
25
|
-
*/
|
|
26
|
-
export declare const detectAndCleanXSS: (text: string) => {
|
|
27
|
-
cleanText: string;
|
|
28
|
-
isXSSDetected: boolean;
|
|
29
|
-
};
|