@microsoft/omnichannel-chat-widget 1.8.1-main.65a1ab5 → 1.8.1-main.83a55ab

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.
Files changed (41) hide show
  1. package/lib/cjs/common/Constants.js +1 -0
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +4 -0
  3. package/lib/cjs/common/telemetry/TelemetryManager.js +4 -4
  4. package/lib/cjs/common/telemetry/loggers/appInsightsLogger.js +4 -5
  5. package/lib/cjs/common/utils/xssUtils.js +79 -0
  6. package/lib/cjs/common/utils.js +3 -0
  7. package/lib/cjs/components/errorboundary/ErrorBoundary.js +68 -0
  8. package/lib/cjs/components/livechatwidget/LiveChatWidget.js +12 -2
  9. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +4 -0
  10. package/lib/cjs/components/livechatwidget/common/startChat.js +1 -7
  11. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +30 -1
  12. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +12 -3
  13. package/lib/cjs/components/ooohpanestateful/OOOHPaneStateful.js +23 -2
  14. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +14 -5
  15. package/lib/cjs/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.js +1 -0
  16. package/lib/cjs/firstresponselatency/util.js +5 -3
  17. package/lib/esm/common/Constants.js +1 -0
  18. package/lib/esm/common/telemetry/TelemetryConstants.js +4 -0
  19. package/lib/esm/common/telemetry/TelemetryManager.js +4 -4
  20. package/lib/esm/common/telemetry/loggers/appInsightsLogger.js +4 -5
  21. package/lib/esm/common/utils/xssUtils.js +72 -0
  22. package/lib/esm/common/utils.js +3 -0
  23. package/lib/esm/components/errorboundary/ErrorBoundary.js +59 -0
  24. package/lib/esm/components/livechatwidget/LiveChatWidget.js +13 -3
  25. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +4 -0
  26. package/lib/esm/components/livechatwidget/common/startChat.js +1 -7
  27. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +28 -0
  28. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +12 -3
  29. package/lib/esm/components/ooohpanestateful/OOOHPaneStateful.js +23 -2
  30. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +14 -5
  31. package/lib/esm/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.js +1 -0
  32. package/lib/esm/firstresponselatency/util.js +5 -3
  33. package/lib/types/common/Constants.d.ts +1 -0
  34. package/lib/types/common/telemetry/TelemetryConstants.d.ts +4 -0
  35. package/lib/types/common/telemetry/loggers/appInsightsLogger.d.ts +1 -1
  36. package/lib/types/common/utils/xssUtils.d.ts +29 -0
  37. package/lib/types/components/errorboundary/ErrorBoundary.d.ts +14 -0
  38. package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +1 -0
  39. package/lib/types/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.d.ts +2 -1
  40. package/lib/types/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +1 -0
  41. package/package.json +2 -2
@@ -16,14 +16,14 @@ var AllowedKeys;
16
16
  AllowedKeys["ElapsedTimeInMilliseconds"] = "DurationInMilliseconds";
17
17
  })(AllowedKeys || (AllowedKeys = {}));
18
18
  let initializationPromise = null;
19
- export const appInsightsLogger = (appInsightsKey, disableCookiesUsage) => {
19
+ export const appInsightsLogger = appInsightsKey => {
20
20
  const isValidKey = key => {
21
21
  const INSTRUMENTATION_KEY_PATTERN = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
22
22
  const INSTRUMENTATION_KEY_REGEX = new RegExp(`^${INSTRUMENTATION_KEY_PATTERN}$`);
23
23
  const CONNECTION_STRING_REGEX = new RegExp(`^InstrumentationKey=${INSTRUMENTATION_KEY_PATTERN};IngestionEndpoint=https://[a-zA-Z0-9\\-\\.]+\\.applicationinsights\\.azure\\.com/.*`);
24
24
  return INSTRUMENTATION_KEY_REGEX.test(key) || CONNECTION_STRING_REGEX.test(key);
25
25
  };
26
- const initializeAppInsights = async (appInsightsKey, disableCookiesUsage) => {
26
+ const initializeAppInsights = async appInsightsKey => {
27
27
  if (!window.appInsights && appInsightsKey) {
28
28
  if (!isValidKey(appInsightsKey)) {
29
29
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
@@ -45,8 +45,7 @@ export const appInsightsLogger = (appInsightsKey, disableCookiesUsage) => {
45
45
  connectionString: appInsightsKey
46
46
  } : {
47
47
  instrumentationKey: appInsightsKey
48
- }),
49
- disableCookiesUsage: disableCookiesUsage
48
+ })
50
49
  };
51
50
 
52
51
  // Initialize Application Insights instance
@@ -73,7 +72,7 @@ export const appInsightsLogger = (appInsightsKey, disableCookiesUsage) => {
73
72
  };
74
73
  const logger = async () => {
75
74
  if (!initializationPromise) {
76
- initializationPromise = initializeAppInsights(appInsightsKey, disableCookiesUsage);
75
+ initializationPromise = initializeAppInsights(appInsightsKey);
77
76
  }
78
77
  await initializationPromise;
79
78
  return window.appInsights;
@@ -0,0 +1,72 @@
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
+ /&gt;.*&lt;/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
+ };
@@ -385,6 +385,9 @@ export const getConversationDetailsCall = async function (facadeChatSDK) {
385
385
 
386
386
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
387
387
  export const checkContactIdError = e => {
388
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
389
+ Event: TelemetryEvent.CheckContactIdError
390
+ });
388
391
  if ((e === null || e === void 0 ? void 0 : e.message) === ChatSDKErrorName.AuthContactIdNotFoundFailure) {
389
392
  const contactIdNotFoundErrorEvent = {
390
393
  eventName: BroadcastEvent.ContactIdNotFound,
@@ -0,0 +1,59 @@
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,7 +1,8 @@
1
- import React, { useReducer, useState } from "react";
1
+ import React, { useEffect, useReducer, useState } from "react";
2
2
  import { ChatAdapterStore } from "../../contexts/ChatAdapterStore";
3
3
  import { ChatContextStore } from "../../contexts/ChatContextStore";
4
4
  import { ChatSDKStore } from "../../contexts/ChatSDKStore";
5
+ import ErrorBoundary from "../errorboundary/ErrorBoundary";
5
6
  import { FacadeChatSDK } from "../../common/facades/FacadeChatSDK";
6
7
  import { FacadeChatSDKStore } from "../../contexts/FacadeChatSDKStore";
7
8
  import LiveChatWidgetStateful from "./livechatwidgetstateful/LiveChatWidgetStateful";
@@ -10,6 +11,8 @@ import { getLiveChatWidgetContextInitialState } from "../../contexts/common/Live
10
11
  import { getMockChatSDKIfApplicable } from "./common/getMockChatSDKIfApplicable";
11
12
  import { isNullOrUndefined } from "../../common/utils";
12
13
  import overridePropsOnMockIfApplicable from "./common/overridePropsOnMockIfApplicable";
14
+ import { registerTelemetryLoggers } from "./common/registerTelemetryLoggers";
15
+ import { logWidgetLoadWithUnexpectedError } from "./common/startChatErrorHandler";
13
16
  export const LiveChatWidget = props => {
14
17
  var _props$mock, _props$featureConfigP, _props$chatConfig, _props$chatConfig$Liv;
15
18
  const reducer = createReducer();
@@ -37,7 +40,14 @@ export const LiveChatWidget = props => {
37
40
  "isSDKMocked": !isNullOrUndefined(props === null || props === void 0 ? void 0 : (_props$mock2 = props.mock) === null || _props$mock2 === void 0 ? void 0 : _props$mock2.type)
38
41
  }, disableReauthentication));
39
42
  }
40
- return /*#__PURE__*/React.createElement(FacadeChatSDKStore.Provider, {
43
+ useEffect(() => {
44
+ registerTelemetryLoggers(props, dispatch);
45
+ }, [dispatch]);
46
+ return /*#__PURE__*/React.createElement(ErrorBoundary, {
47
+ onError: error => {
48
+ logWidgetLoadWithUnexpectedError(error);
49
+ }
50
+ }, /*#__PURE__*/React.createElement(FacadeChatSDKStore.Provider, {
41
51
  value: [facadeChatSDK, setFacadeChatSDK]
42
52
  }, /*#__PURE__*/React.createElement(ChatSDKStore.Provider, {
43
53
  value: chatSDK
@@ -45,6 +55,6 @@ export const LiveChatWidget = props => {
45
55
  value: [adapter, setAdapter]
46
56
  }, /*#__PURE__*/React.createElement(ChatContextStore.Provider, {
47
57
  value: [state, dispatch]
48
- }, /*#__PURE__*/React.createElement(LiveChatWidgetStateful, props)))));
58
+ }, /*#__PURE__*/React.createElement(LiveChatWidgetStateful, props))))));
49
59
  };
50
60
  export default LiveChatWidget;
@@ -67,6 +67,10 @@ const getChatReconnectContext = async (facadeChatSDK, chatConfig, props, isAuthe
67
67
  // AuthToken will be reset later at start chat
68
68
  removeAuthTokenProvider(facadeChatSDK.getChatSDK());
69
69
  }
70
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
71
+ Event: TelemetryEvent.GetChatReconnectContextSDKCallSucceeded,
72
+ Description: "Reconnect context SDK call succeeded"
73
+ });
70
74
  return reconnectChatContext;
71
75
  }
72
76
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -307,13 +307,7 @@ const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, s
307
307
 
308
308
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
309
309
  const setCustomContextParams = async (state, props) => {
310
- var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates8, _persistedState$domai8;
311
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
312
- const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
313
- //Should not set custom context for auth chat
314
- if (isAuthenticatedChat) {
315
- return;
316
- }
310
+ var _state$domainStates8, _persistedState$domai8;
317
311
  if (state !== null && state !== void 0 && (_state$domainStates8 = state.domainStates) !== null && _state$domainStates8 !== void 0 && _state$domainStates8.customContext) {
318
312
  var _state$domainStates9;
319
313
  optionalParams = Object.assign({}, optionalParams, {
@@ -141,6 +141,34 @@ const logWidgetLoadCompleteWithError = ex => {
141
141
  ElapsedTimeInMilliseconds: TelemetryTimers === null || TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg3 = TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg3 === void 0 ? void 0 : _TelemetryTimers$Widg3.milliSecondsElapsed
142
142
  });
143
143
  };
144
+ export const logWidgetLoadWithUnexpectedError = ex => {
145
+ var _TelemetryTimers$Widg4;
146
+ // eslint-disable-line @typescript-eslint/no-explicit-any
147
+ const details = {
148
+ message: (ex === null || ex === void 0 ? void 0 : ex.message) || "An unexpected error occurred",
149
+ stack: (ex === null || ex === void 0 ? void 0 : ex.stack) || "No stack trace available"
150
+ };
151
+ let additionalDetails = "";
152
+ try {
153
+ additionalDetails = JSON.stringify(details);
154
+ } catch (error) {
155
+ additionalDetails = "Failed to stringify error details";
156
+ }
157
+
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ const exDetails = {
160
+ Exception: `Widget load with unexpected error: ${additionalDetails}`
161
+ };
162
+ if (ex !== null && ex !== void 0 && ex.httpResponseStatusCode) {
163
+ exDetails.HttpResponseStatusCode = ex.httpResponseStatusCode;
164
+ }
165
+ TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.ERROR, {
166
+ Event: TelemetryEvent.WidgetLoadFailed,
167
+ Description: "Widget load with unexpected error",
168
+ ExceptionDetails: exDetails,
169
+ ElapsedTimeInMilliseconds: TelemetryTimers === null || TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg4 = TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg4 === void 0 ? void 0 : _TelemetryTimers$Widg4.milliSecondsElapsed
170
+ });
171
+ };
144
172
 
145
173
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
174
  const forceEndChat = facadeChatSDK => {
@@ -48,7 +48,6 @@ 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";
52
51
  import { setPostChatContextAndLoadSurvey } from "../common/setPostChatContextAndLoadSurvey";
53
52
  import { startProactiveChat } from "../common/startProactiveChat";
54
53
  import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
@@ -75,6 +74,7 @@ export const LiveChatWidgetStateful = props => {
75
74
  const [facadeChatSDK] = useFacadeSDKStore();
76
75
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
76
  const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = useState(undefined);
77
+ const [conversationId, setConversationId] = useState("");
78
78
  const {
79
79
  Composer
80
80
  } = Components;
@@ -220,7 +220,6 @@ export const LiveChatWidgetStateful = props => {
220
220
  state.domainStates.confirmationPaneConfirmedOptionClicked = false;
221
221
  state.domainStates.confirmationState = ConfirmationState.NotSet;
222
222
  setupClientDataStore();
223
- registerTelemetryLoggers(props, dispatch);
224
223
  createInternetConnectionChangeHandler(state);
225
224
  dispatch({
226
225
  type: LiveChatWidgetActionType.SET_WIDGET_ELEMENT_ID,
@@ -570,6 +569,14 @@ export const LiveChatWidgetStateful = props => {
570
569
  });
571
570
  });
572
571
 
572
+ // Retrieve convId
573
+ BroadcastService.getMessageByEventName(BroadcastEvent.UpdateConversationDataForTelemetry).subscribe(msg => {
574
+ var _msg$payload11, _msg$payload11$liveWo;
575
+ 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) {
576
+ setConversationId(msg.payload.liveWorkItem.conversationId);
577
+ }
578
+ });
579
+
573
580
  // Check for TPC and log in telemetry if blocked
574
581
  isCookieAllowed();
575
582
  return () => {
@@ -912,6 +919,8 @@ export const LiveChatWidgetStateful = props => {
912
919
  }, 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, {
913
920
  setPostChatContext: setPostChatContextRelay,
914
921
  prepareEndChat: prepareEndChatRelay
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))))));
922
+ }))), !((_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, {
923
+ customerVoiceSurveyCorrelationId: conversationId
924
+ }))), 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))))));
916
925
  };
917
926
  export default LiveChatWidgetStateful;
@@ -1,12 +1,13 @@
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";
5
4
  import { OutOfOfficeHoursPane } from "@microsoft/omnichannel-chat-components";
6
5
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
7
6
  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.";
10
11
  export const OutOfOfficeHoursPaneStateful = props => {
11
12
  var _props$styleProps;
12
13
  useEffect(() => {
@@ -45,8 +46,28 @@ export const OutOfOfficeHoursPaneStateful = props => {
45
46
  ElapsedTimeInMilliseconds: uiTimer.milliSecondsElapsed
46
47
  });
47
48
  }, []);
49
+
50
+ // Enhanced titleText sanitization
48
51
  if (controlProps !== null && controlProps !== void 0 && controlProps.titleText) {
49
- controlProps.titleText = DOMPurify.sanitize(controlProps.titleText);
52
+ const {
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
+ }
50
71
  }
51
72
  return /*#__PURE__*/React.createElement(OutOfOfficeHoursPane, {
52
73
  componentOverrides: props.componentOverrides,
@@ -9,13 +9,14 @@ 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 > 4 && arguments[4] !== undefined ? arguments[4] : false;
12
+ const generateSurveyInviteLink = function (surveyInviteLink, isEmbed, locale, compact, customerVoiceSurveyCorrelationId) {
13
+ let showMultiLingual = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 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()
18
+ showmultilingual: (showMultiLingual ?? false).toString(),
19
+ cvResponsePageRequestId: customerVoiceSurveyCorrelationId
19
20
  });
20
21
  return `${surveyInviteLink}&${surveyLinkParams.toString()}`;
21
22
  };
@@ -31,9 +32,9 @@ export const PostChatSurveyPaneStateful = props => {
31
32
  // Bot survey enabled
32
33
  state.appStates.postChatParticipantType === ParticipantType.Bot) {
33
34
  // Only Bot has engaged
34
- surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.botSurveyInviteLink, surveyMode, state.domainStates.postChatContext.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true);
35
+ surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.botSurveyInviteLink, surveyMode, state.domainStates.postChatContext.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
35
36
  } else {
36
- surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.surveyInviteLink, surveyMode, state.domainStates.postChatContext.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true);
37
+ surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.surveyInviteLink, surveyMode, state.domainStates.postChatContext.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
37
38
  }
38
39
  if (props.copilotSurveyContext) {
39
40
  surveyInviteLink = `${surveyInviteLink}&mcs_additionalcontext=${JSON.stringify(props.copilotSurveyContext)}`;
@@ -96,6 +97,14 @@ export const PostChatSurveyPaneStateful = props => {
96
97
  message: "Customer Voice form response error."
97
98
  }
98
99
  });
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
+ });
99
108
  }
100
109
  });
101
110
  }, []);
@@ -3,4 +3,5 @@ export let CustomerVoiceEvents;
3
3
  CustomerVoiceEvents["ResponsePageLoaded"] = "ResponsePageLoaded";
4
4
  CustomerVoiceEvents["FormResponseSubmitted"] = "FormResponseSubmitted";
5
5
  CustomerVoiceEvents["FormResponseError"] = "FormResponseError";
6
+ CustomerVoiceEvents["FormsError"] = "FormsError";
6
7
  })(CustomerVoiceEvents || (CustomerVoiceEvents = {}));
@@ -64,11 +64,13 @@ export const polyfillMessagePayloadForEvent = (activity, payload, conversationId
64
64
  };
65
65
  };
66
66
  export const getScenarioType = activity => {
67
- var _activity$from3, _activity$channelData4, _activity$channelData5;
68
- if ((activity === null || activity === void 0 ? void 0 : (_activity$from3 = activity.from) === null || _activity$from3 === void 0 ? void 0 : _activity$from3.role) === Constants.userMessageTag) {
67
+ var _activity$from3, _activity$channelData4;
68
+ const role = activity === null || activity === void 0 ? void 0 : (_activity$from3 = activity.from) === null || _activity$from3 === void 0 ? void 0 : _activity$from3.role;
69
+ const tags = activity === null || activity === void 0 ? void 0 : (_activity$channelData4 = activity.channelData) === null || _activity$channelData4 === void 0 ? void 0 : _activity$channelData4.tags;
70
+ if (role === Constants.userMessageTag) {
69
71
  return ScenarioType.UserSendMessageStrategy;
70
72
  }
71
- if (activity !== null && activity !== void 0 && (_activity$channelData4 = activity.channelData) !== null && _activity$channelData4 !== void 0 && (_activity$channelData5 = _activity$channelData4.tags) !== null && _activity$channelData5 !== void 0 && _activity$channelData5.includes(Constants.systemMessageTag)) {
73
+ if (tags && tags.includes(Constants.systemMessageTag) || role === Constants.channelMessageTag) {
72
74
  return ScenarioType.SystemMessageStrategy;
73
75
  }
74
76
  return ScenarioType.ReceivedMessageStrategy;
@@ -3,6 +3,7 @@ export declare class Constants {
3
3
  static readonly magicCodeResponseBroadcastChannel = "MagicCodeResponseChannel";
4
4
  static readonly systemMessageTag = "system";
5
5
  static readonly userMessageTag = "user";
6
+ static readonly channelMessageTag = "channel";
6
7
  static readonly historyMessageTag = "history";
7
8
  static readonly agentEndConversationMessageTag = "agentendconversation";
8
9
  static readonly supervisorForceCloseMessageTag = "supervisorforceclosedconversation";
@@ -94,6 +94,8 @@ export declare enum TelemetryEvent {
94
94
  DisconnectEndChatSDKCallFailed = "DisconnectEndChatSDKCallFailed",
95
95
  GetChatReconnectContextSDKCallStarted = "GetChatReconnectContextSDKCallStarted",
96
96
  GetChatReconnectContextSDKCallFailed = "GetChatReconnectContextSDKCallFailed",
97
+ CheckContactIdError = "checkContactIdError",
98
+ GetChatReconnectContextSDKCallSucceeded = "GetChatReconnectContextSDKCallSucceeded",
97
99
  ParseAdaptiveCardFailed = "ParseAdaptiveCardFailed",
98
100
  ClientDataStoreProviderFailed = "ClientDataStoreProviderFailed",
99
101
  InMemoryDataStoreFailed = "InMemoryDataStoreFailed",
@@ -161,6 +163,7 @@ export declare enum TelemetryEvent {
161
163
  CustomerVoiceResponsePageLoaded = "CustomerVoiceResponsePageLoaded",
162
164
  CustomerVoiceFormResponseSubmitted = "CustomerVoiceFormResponseSubmitted",
163
165
  CustomerVoiceFormResponseError = "CustomerVoiceFormResponseError",
166
+ CustomerVoiceFormsError = "CustomerVoiceFormsError",
164
167
  BotAuthActivityEmptySasUrl = "BotAuthActivityEmptySasUrl",
165
168
  SetBotAuthProviderFetchConfig = "SetBotAuthProviderFetchConfig",
166
169
  SetBotAuthProviderHideCard = "SetBotAuthProviderHideCard",
@@ -238,6 +241,7 @@ export declare enum TelemetryEvent {
238
241
  UXNotificationPaneCompleted = "UXNotificationPaneCompleted",
239
242
  UXOutOfOfficeHoursPaneStart = "UXOutOfOfficeHoursPaneStart",
240
243
  UXOutOfOfficeHoursPaneCompleted = "UXOutOfOfficeHoursPaneCompleted",
244
+ XSSTextDetected = "XSSTextDetected",
241
245
  UXPostChatLoadingPaneStart = "UXPostChatLoadingPaneStart",
242
246
  UXPostChatLoadingPaneCompleted = "UXPostChatLoadingPaneCompleted",
243
247
  UXPrechatPaneStart = "UXPrechatPaneStart",
@@ -4,7 +4,7 @@ declare global {
4
4
  appInsights?: any;
5
5
  }
6
6
  }
7
- export declare const appInsightsLogger: (appInsightsKey: string, disableCookiesUsage: boolean) => IChatSDKLogger;
7
+ export declare const appInsightsLogger: (appInsightsKey: string) => IChatSDKLogger;
8
8
  export interface ICustomProperties {
9
9
  [key: string]: any;
10
10
  }
@@ -0,0 +1,29 @@
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
+ };
@@ -0,0 +1,14 @@
1
+ import React, { Component } from 'react';
2
+ interface ErrorBoundaryProps {
3
+ children: React.ReactNode | (() => React.ReactNode);
4
+ onError?: (error: Error) => void;
5
+ }
6
+ interface ErrorBoundaryState {
7
+ hasError: boolean;
8
+ }
9
+ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
10
+ constructor(props: ErrorBoundaryProps);
11
+ componentDidCatch(error: Error): void;
12
+ render(): false | React.JSX.Element;
13
+ }
14
+ export default ErrorBoundary;
@@ -4,3 +4,4 @@ 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;
@@ -1,5 +1,6 @@
1
1
  export declare enum CustomerVoiceEvents {
2
2
  ResponsePageLoaded = "ResponsePageLoaded",
3
3
  FormResponseSubmitted = "FormResponseSubmitted",
4
- FormResponseError = "FormResponseError"
4
+ FormResponseError = "FormResponseError",
5
+ FormsError = "FormsError"
5
6
  }
@@ -2,4 +2,5 @@ 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;
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.8.1-main.65a1ab5",
3
+ "version": "1.8.1-main.83a55ab",
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.1",
90
+ "@microsoft/omnichannel-chat-sdk": "^1.11.2",
91
91
  "@opentelemetry/api": "^1.9.0",
92
92
  "abort-controller": "^3",
93
93
  "abort-controller-es5": "^2.0.1",