@microsoft/teams-js 2.48.1 → 2.49.0-beta.0

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.
@@ -120,14 +120,6 @@ export declare const ORIGIN_LIST_FETCH_TIMEOUT_IN_MS: number;
120
120
  * Limited to Microsoft-internal use
121
121
  */
122
122
  export declare const validOriginsCdnEndpoint: URL;
123
- /**
124
- * @hidden
125
- * USer specified message origins should satisfy this test
126
- *
127
- * @internal
128
- * Limited to Microsoft-internal use
129
- */
130
- export declare const userOriginUrlValidationRegExp: RegExp;
131
123
  /**
132
124
  * @hidden
133
125
  * The protocol used for deep links into Teams
@@ -0,0 +1,47 @@
1
+ import { Debugger } from 'debug/src/browser';
2
+ /**
3
+ * @hidden
4
+ * @internal
5
+ * Limited to Microsoft-internal use.
6
+ *
7
+ * Implementation of URL pattern matching logic for validating origins against a list of allowed patterns.
8
+ */
9
+ export interface URLVerifier {
10
+ /**
11
+ * Checks if the given URL matches the pattern defined in the implementation.
12
+ * @param url - The URL to test against the pattern.
13
+ * @returns - True if the URL matches the pattern, false otherwise.
14
+ */
15
+ test: (url: URL) => boolean;
16
+ }
17
+ /**
18
+ * @param pattern - reference pattern
19
+ * @param host - candidate string
20
+ * @returns returns true if host matches pre-know valid pattern
21
+ *
22
+ * @example
23
+ * validateHostAgainstPattern('*.teams.microsoft.com', 'subdomain.teams.microsoft.com') returns true
24
+ * validateHostAgainstPattern('teams.microsoft.com', 'team.microsoft.com') returns false
25
+ *
26
+ * @internal
27
+ * Limited to Microsoft-internal use
28
+ */
29
+ export declare function validateHostAgainstPattern(pattern: string, host: string): boolean;
30
+ /**
31
+ * @hidden
32
+ * @internal
33
+ * Limited to Microsoft-internal use.
34
+ *
35
+ * Checks if the provided pattern is valid for checking against URLs.
36
+ * @param pattern - The pattern to validate.
37
+ * @returns - True if the pattern is valid, false otherwise.
38
+ */
39
+ export declare function isValidPatternUrl(pattern: string): boolean;
40
+ /**
41
+ * @hidden
42
+ * @internal
43
+ * Limited to Microsoft-internal use.
44
+ *
45
+ * Creates a URL verifier based on the provided pattern.
46
+ */
47
+ export declare function createURLVerifier(pattern: string, logger: Debugger): URLVerifier | undefined;
@@ -517,7 +517,7 @@ export declare function getFrameContext(): FrameContexts | undefined;
517
517
  * @param validMessageOrigins - Optionally specify a list of cross-frame message origins. This parameter is used if you know that your app
518
518
  * will be hosted on a custom domain (i.e., not a standard Microsoft 365 host like Teams, Outlook, etc.) Most apps will never need
519
519
  * to pass a value for this parameter.
520
- * Any domains passed in the array must have the https: protocol on the string otherwise they will be ignored. Example: https://www.example.com
520
+ * Any domains passed in the array must define a scheme to be able to be processed. Examples: https://www.example.com, chrome://
521
521
  * @returns Promise that will be fulfilled when initialization has completed, or rejected if the initialization fails or times out
522
522
  */
523
523
  export declare function initialize(validMessageOrigins?: string[]): Promise<void>;
@@ -20,7 +20,7 @@ export interface StageViewParams {
20
20
  /**
21
21
  * The chat or channel ID.
22
22
  */
23
- threadId: string;
23
+ threadId?: string;
24
24
  /**
25
25
  * The messageId identifies a particular channel meeting within the channel as specified by the threadId above. This should be used only when trying to open the stage view for a channel meeting. It will be a no-op for other scenarios
26
26
  */
@@ -1 +1 @@
1
- import*as t from"../artifactsForCDN/validDomains.json.js";const i="2.0.1",s="2.0.2",e="2.0.3",n="2.0.4",o="2.0.1",a="1.9.0",r="2.0.0",m="1.7.0",l="1.8.0",d="2.0.0",h="1.9.0",p=t.validOrigins,c=1500,f=new URL("https://res.cdn.office.net/teams-js/validDomains/json/validDomains.json"),j=/^https:\/\//,v="https",y="teams.microsoft.com",D="The library has not yet been initialized",T="The runtime has not yet been initialized",b="The runtime version is not supported",u="The call was not properly started";export{c as ORIGIN_LIST_FETCH_TIMEOUT_IN_MS,m as captureImageMobileSupportVersion,i as defaultSDKVersionForCompatCheck,u as errorCallNotStarted,D as errorLibraryNotInitialized,T as errorRuntimeNotInitialized,b as errorRuntimeNotSupported,d as getMediaCallbackSupportVersion,o as getUserJoinedTeamsSupportedAndroidClientVersion,n as imageOutputFormatsAPISupportVersion,a as locationAPIsRequiredVersion,l as mediaAPISupportVersion,e as nonFullScreenVideoModeAPISupportVersion,r as peoplePickerRequiredVersion,h as scanBarCodeAPIMobileSupportVersion,y as teamsDeepLinkHost,v as teamsDeepLinkProtocol,j as userOriginUrlValidationRegExp,f as validOriginsCdnEndpoint,p as validOriginsFallback,s as videoAndImageMediaAPISupportVersion};
1
+ import*as i from"../artifactsForCDN/validDomains.json.js";const t="2.0.1",e="2.0.2",s="2.0.3",n="2.0.4",o="2.0.1",a="1.9.0",r="2.0.0",m="1.7.0",l="1.8.0",d="2.0.0",h="1.9.0",p=i.validOrigins,c=1500,f=new URL("https://res.cdn.office.net/teams-js/validDomains/json/validDomains.json"),j="https",v="teams.microsoft.com",y="The library has not yet been initialized",D="The runtime has not yet been initialized",T="The runtime version is not supported",b="The call was not properly started";export{c as ORIGIN_LIST_FETCH_TIMEOUT_IN_MS,m as captureImageMobileSupportVersion,t as defaultSDKVersionForCompatCheck,b as errorCallNotStarted,y as errorLibraryNotInitialized,D as errorRuntimeNotInitialized,T as errorRuntimeNotSupported,d as getMediaCallbackSupportVersion,o as getUserJoinedTeamsSupportedAndroidClientVersion,n as imageOutputFormatsAPISupportVersion,a as locationAPIsRequiredVersion,l as mediaAPISupportVersion,s as nonFullScreenVideoModeAPISupportVersion,r as peoplePickerRequiredVersion,h as scanBarCodeAPIMobileSupportVersion,v as teamsDeepLinkHost,j as teamsDeepLinkProtocol,f as validOriginsCdnEndpoint,p as validOriginsFallback,e as videoAndImageMediaAPISupportVersion};
@@ -1 +1 @@
1
- import{HostClientType as i}from"../public/constants.js";import{ErrorCode as t}from"../public/interfaces.js";import{isRuntimeInitialized as e}from"../public/runtime.js";import{defaultSDKVersionForCompatCheck as n,errorLibraryNotInitialized as o,userOriginUrlValidationRegExp as r}from"./constants.js";import{GlobalVars as l}from"./globalVars.js";import{getLogger as s}from"./telemetry.js";import{compareSDKVersions as a}from"./utils.js";const f=s("internal"),c=f.extend("ensureInitializeCalled"),d=f.extend("ensureInitialized");function p(){if(!l.initializeCalled)throw c(o),new Error(o)}function m(i,...t){if(!l.initializeCompleted)throw d("%s. initializeCalled: %s",o,l.initializeCalled.toString()),new Error(o);if(t&&t.length>0){let i=!1;for(let e=0;e<t.length;e++)if(t[e]===l.frameContext){i=!0;break}if(!i)throw new Error(`This call is only allowed in following contexts: ${JSON.stringify(t)}. Current context: "${l.frameContext}".`)}return e(i)}function u(i=n){const t=a(l.clientSupportedSDKVersion,i);return!isNaN(t)&&t>=0}function C(){return l.hostClientType==i.android||l.hostClientType==i.ios||l.hostClientType==i.ipados||l.hostClientType==i.visionOS}function h(i=n){if(!C()){throw{errorCode:t.NOT_SUPPORTED_ON_PLATFORM}}if(!u(i)){throw{errorCode:t.OLD_PLATFORM}}}function w(i){let t=l.additionalValidOrigins.concat(i.filter(i=>"string"==typeof i&&r.test(i)));const e={};t=t.filter(i=>!e[i]&&(e[i]=!0,!0)),l.additionalValidOrigins=t}export{p as ensureInitializeCalled,m as ensureInitialized,u as isCurrentSDKVersionAtLeast,C as isHostClientMobile,w as processAdditionalValidOrigins,h as throwExceptionIfMobileApiIsNotSupported};
1
+ import{HostClientType as i}from"../public/constants.js";import{ErrorCode as t}from"../public/interfaces.js";import{isRuntimeInitialized as r}from"../public/runtime.js";import{defaultSDKVersionForCompatCheck as e,errorLibraryNotInitialized as n}from"./constants.js";import{GlobalVars as o}from"./globalVars.js";import{getLogger as l}from"./telemetry.js";import{isValidPatternUrl as s}from"./urlPattern.js";import{compareSDKVersions as a}from"./utils.js";const f=l("internal"),c=f.extend("ensureInitializeCalled"),d=f.extend("ensureInitialized");function m(){if(!o.initializeCalled)throw c(n),new Error(n)}function p(i,...t){if(!o.initializeCompleted)throw d("%s. initializeCalled: %s",n,o.initializeCalled.toString()),new Error(n);if(t&&t.length>0){let i=!1;for(let r=0;r<t.length;r++)if(t[r]===o.frameContext){i=!0;break}if(!i)throw new Error(`This call is only allowed in following contexts: ${JSON.stringify(t)}. Current context: "${o.frameContext}".`)}return r(i)}function u(i=e){const t=a(o.clientSupportedSDKVersion,i);return!isNaN(t)&&t>=0}function C(){return o.hostClientType==i.android||o.hostClientType==i.ios||o.hostClientType==i.ipados||o.hostClientType==i.visionOS}function h(i=e){if(!C()){throw{errorCode:t.NOT_SUPPORTED_ON_PLATFORM}}if(!u(i)){throw{errorCode:t.OLD_PLATFORM}}}function w(i){let t=o.additionalValidOrigins.concat(i.filter(i=>"string"==typeof i&&s(i)));const r={};t=t.filter(i=>!r[i]&&(r[i]=!0,!0)),o.additionalValidOrigins=t}export{m as ensureInitializeCalled,p as ensureInitialized,u as isCurrentSDKVersionAtLeast,C as isHostClientMobile,w as processAdditionalValidOrigins,h as throwExceptionIfMobileApiIsNotSupported};
@@ -0,0 +1 @@
1
+ const t=/^[A-Za-z][A-Za-z\d+.-]*:\/\//;function s(t,s){const n=t.substring(1);return t===s||"*."===t.substring(0,2)&&s.length>n.length&&s.split(".").length===n.split(".").length&&s.substring(s.length-n.length)===n}class n{constructor(t,s,n){this.protocol=t,this.host=s,this.logger=n}static canUse(s){return t.test(s)}static create(t,s){const e=t.split("://");return new n(e[0],e[1],s.extend("InternalURLPattern"))}test(t){return this.logger("Testing URL %s against pattern protocol: %s, host: %s",t,this.protocol,this.host),t.protocol===`${this.protocol}:`&&(!t.host||s(this.host,t.host))}}function e(t){return n.canUse(t)}function o(t,s){if(n.canUse(t))return n.create(t,s);s("No URL verifier available for pattern: %s",t)}export{o as createURLVerifier,e as isValidPatternUrl,s as validateHostAgainstPattern};
@@ -1 +1 @@
1
- import{__awaiter as i}from"../../../../node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@4.55.1_tslib@2.8.1_typescript@4.9.5/node_modules/tslib/tslib.es6.js";import{ORIGIN_LIST_FETCH_TIMEOUT_IN_MS as t,validOriginsCdnEndpoint as r,validOriginsFallback as n}from"./constants.js";import{GlobalVars as e}from"./globalVars.js";import{getLogger as o}from"./telemetry.js";import{inServerSideRenderingEnvironment as l,isValidHttpsURL as s}from"./utils.js";let a=[];const u=o("validateOrigin");let c;function f(){return i(this,void 0,void 0,function*(){c||(yield g())})}function d(){return 0===a.length}function g(e=!1){return i(this,void 0,void 0,function*(){if(!d()&&!e)return a;if(c)return c;if(l())return a=n,n;{u("Initiating fetch call to acquire valid origins list from CDN");const i=new AbortController,e=setTimeout(()=>i.abort(),t);return c=fetch(r,{signal:i.signal}).then(i=>{if(clearTimeout(e),!i.ok)throw new Error("Invalid Response from Fetch Call");return u("Fetch call completed and retrieved valid origins list from CDN"),i.json().then(i=>{if(function(i){let t=JSON.parse(i);try{t=JSON.parse(i)}catch(i){return!1}if(!t.validOrigins)return!1;for(const i of t.validOrigins)try{new URL("https://"+i)}catch(t){return u("isValidOriginsFromCDN call failed to validate origin: %s",i),!1}return!0}(JSON.stringify(i)))return a=i.validOrigins,a;throw new Error("Valid origins list retrieved from CDN is invalid")})}).catch(i=>("AbortError"===i.name?u(`validOrigins fetch call to CDN failed due to Timeout of ${t} ms. Defaulting to fallback list`):u("validOrigins fetch call to CDN failed with error: %s. Defaulting to fallback list",i),a=n,a)),c}})}function p(i,t){if("*."===i.substring(0,2)){const r=i.substring(1);if(t.length>r.length&&t.split(".").length===r.split(".").length&&t.substring(t.length-r.length)===r)return!0}else if(i===t)return!0;return!1}function h(i,t){const r=d()?n:a;return m(i,r)?Promise.resolve(!0):(u("Origin %s is not in the local valid origins list, fetching from CDN",i),g(t).then(t=>m(i,t)))}function m(i,t){if(!s(i))return u("Origin %s is invalid because it is not using https protocol. Protocol being used: %s",i,i.protocol),!1;const r=i.host;if(t.some(i=>p(i,r)))return!0;for(const i of e.additionalValidOrigins){if(p("https://"===i.substring(0,8)?i.substring(8):i,r))return!0}return u("Origin %s is invalid because it is not an origin approved by this library or included in the call to app.initialize.\nOrigins approved by this library: %o\nOrigins included in app.initialize: %o",i,t,e.additionalValidOrigins),!1}f();export{f as prefetchOriginsFromCDN,h as validateOrigin};
1
+ import{__awaiter as i}from"../../../../node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@4.55.1_tslib@2.8.1_typescript@4.9.5/node_modules/tslib/tslib.es6.js";import{ORIGIN_LIST_FETCH_TIMEOUT_IN_MS as t,validOriginsCdnEndpoint as r,validOriginsFallback as n}from"./constants.js";import{GlobalVars as o}from"./globalVars.js";import{getLogger as e}from"./telemetry.js";import{validateHostAgainstPattern as l,createURLVerifier as s}from"./urlPattern.js";import{inServerSideRenderingEnvironment as a,isValidHttpsURL as c}from"./utils.js";let u=[];const d=e("validateOrigin");let f;function g(){return i(this,void 0,void 0,function*(){f||(yield m())})}function p(){return 0===u.length}function m(o=!1){return i(this,void 0,void 0,function*(){if(!p()&&!o)return u;if(f)return f;if(a())return u=n,n;{d("Initiating fetch call to acquire valid origins list from CDN");const i=new AbortController,o=setTimeout(()=>i.abort(),t);return f=fetch(r,{signal:i.signal}).then(i=>{if(clearTimeout(o),!i.ok)throw new Error("Invalid Response from Fetch Call");return d("Fetch call completed and retrieved valid origins list from CDN"),i.json().then(i=>{if(function(i){let t=JSON.parse(i);try{t=JSON.parse(i)}catch(i){return!1}if(!t.validOrigins)return!1;for(const i of t.validOrigins)try{new URL("https://"+i)}catch(t){return d("isValidOriginsFromCDN call failed to validate origin: %s",i),!1}return!0}(JSON.stringify(i)))return u=i.validOrigins,u;throw new Error("Valid origins list retrieved from CDN is invalid")})}).catch(i=>("AbortError"===i.name?d(`validOrigins fetch call to CDN failed due to Timeout of ${t} ms. Defaulting to fallback list`):d("validOrigins fetch call to CDN failed with error: %s. Defaulting to fallback list",i),u=n,u)),f}})}function h(i,t){let r;try{const t=s(i,d);if(!t)return!1;r=t}catch(i){return!1}return r.test(t)}function v(i,t){const r=p()?n:u;return O(i,r)?Promise.resolve(!0):(d("Origin %s is not in the local valid origins list, fetching from CDN",i),m(t).then(t=>O(i,t)))}function O(i,t){for(const t of o.additionalValidOrigins)if(h(t,i))return!0;const r=i.host;return c(i)?!!t.some(i=>l(i,r))||(d("Origin %s is invalid because it is not an origin approved by this library or included in the call to app.initialize.\nOrigins approved by this library: %o\nOrigins included in app.initialize: %o",i,t,o.additionalValidOrigins),!1):(d("Origin %s is invalid because it is not using https protocol. Protocol being used: %s",i,i.protocol),!1)}g();export{g as prefetchOriginsFromCDN,v as validateOrigin};
@@ -1 +1 @@
1
- const o="2.48.1";export{o as version};
1
+ const t="2.49.0-beta.0";export{t as version};
@@ -2429,14 +2429,6 @@ const ORIGIN_LIST_FETCH_TIMEOUT_IN_MS = 1500;
2429
2429
  * Limited to Microsoft-internal use
2430
2430
  */
2431
2431
  const validOriginsCdnEndpoint = new URL('https://res.cdn.office.net/teams-js/validDomains/json/validDomains.json');
2432
- /**
2433
- * @hidden
2434
- * USer specified message origins should satisfy this test
2435
- *
2436
- * @internal
2437
- * Limited to Microsoft-internal use
2438
- */
2439
- const userOriginUrlValidationRegExp = /^https:\/\//;
2440
2432
  /**
2441
2433
  * @hidden
2442
2434
  * The protocol used for deep links into Teams
@@ -4677,7 +4669,7 @@ function isSerializable(arg) {
4677
4669
  * @hidden
4678
4670
  * Package version.
4679
4671
  */
4680
- const version = "2.48.1";
4672
+ const version = "2.49.0-beta.0";
4681
4673
 
4682
4674
  ;// ./src/public/featureFlags.ts
4683
4675
  // All build feature flags are defined inside this object. Any build feature flag must have its own unique getter and setter function. This pattern allows for client apps to treeshake unused code and avoid including code guarded by this feature flags in the final bundle. If this property isn't desired, use the below runtime feature flags object.
@@ -4810,6 +4802,92 @@ function flushMessageQueue(targetWindow, targetOrigin, targetMessageQueue, targe
4810
4802
  }
4811
4803
  }
4812
4804
 
4805
+ ;// ./src/internal/urlPattern.ts
4806
+ /**
4807
+ * Regex for validating that a user-provided origin includes a protocol.
4808
+ */
4809
+ const userOriginUrlValidationRegExp = /^[A-Za-z][A-Za-z\d+.-]*:\/\//;
4810
+ /**
4811
+ * @param pattern - reference pattern
4812
+ * @param host - candidate string
4813
+ * @returns returns true if host matches pre-know valid pattern
4814
+ *
4815
+ * @example
4816
+ * validateHostAgainstPattern('*.teams.microsoft.com', 'subdomain.teams.microsoft.com') returns true
4817
+ * validateHostAgainstPattern('teams.microsoft.com', 'team.microsoft.com') returns false
4818
+ *
4819
+ * @internal
4820
+ * Limited to Microsoft-internal use
4821
+ */
4822
+ function validateHostAgainstPattern(pattern, host) {
4823
+ const suffix = pattern.substring(1);
4824
+ return (pattern === host ||
4825
+ (pattern.substring(0, 2) === '*.' &&
4826
+ host.length > suffix.length &&
4827
+ host.split('.').length === suffix.split('.').length &&
4828
+ host.substring(host.length - suffix.length) === suffix));
4829
+ }
4830
+ /**
4831
+ * @hidden
4832
+ * @internal
4833
+ * Limited to Microsoft-internal use.
4834
+ *
4835
+ * Internal class when widely-available URLPattern is not available.
4836
+ */
4837
+ class InternalURLPattern {
4838
+ constructor(protocol, host, logger) {
4839
+ this.protocol = protocol;
4840
+ this.host = host;
4841
+ this.logger = logger;
4842
+ }
4843
+ /**
4844
+ * Checks if InternalURLPattern can be used with the provided pattern.
4845
+ */
4846
+ static canUse(pattern) {
4847
+ return userOriginUrlValidationRegExp.test(pattern);
4848
+ }
4849
+ /**
4850
+ * Creates an instance of InternalURLPattern with the provided pattern and logger.
4851
+ */
4852
+ static create(pattern, logger) {
4853
+ const splitPattern = pattern.split('://');
4854
+ return new InternalURLPattern(splitPattern[0], splitPattern[1], logger.extend('InternalURLPattern'));
4855
+ }
4856
+ /**
4857
+ * Tests the URL against the pattern.
4858
+ */
4859
+ test(url) {
4860
+ this.logger('Testing URL %s against pattern protocol: %s, host: %s', url, this.protocol, this.host);
4861
+ return url.protocol === `${this.protocol}:` && (!url.host || validateHostAgainstPattern(this.host, url.host));
4862
+ }
4863
+ }
4864
+ /**
4865
+ * @hidden
4866
+ * @internal
4867
+ * Limited to Microsoft-internal use.
4868
+ *
4869
+ * Checks if the provided pattern is valid for checking against URLs.
4870
+ * @param pattern - The pattern to validate.
4871
+ * @returns - True if the pattern is valid, false otherwise.
4872
+ */
4873
+ function isValidPatternUrl(pattern) {
4874
+ return InternalURLPattern.canUse(pattern);
4875
+ }
4876
+ /**
4877
+ * @hidden
4878
+ * @internal
4879
+ * Limited to Microsoft-internal use.
4880
+ *
4881
+ * Creates a URL verifier based on the provided pattern.
4882
+ */
4883
+ function createURLVerifier(pattern, logger) {
4884
+ if (InternalURLPattern.canUse(pattern)) {
4885
+ return InternalURLPattern.create(pattern, logger);
4886
+ }
4887
+ logger('No URL verifier available for pattern: %s', pattern);
4888
+ return undefined;
4889
+ }
4890
+
4813
4891
  ;// ./src/internal/internalAPIs.ts
4814
4892
 
4815
4893
 
@@ -4818,6 +4896,7 @@ function flushMessageQueue(targetWindow, targetOrigin, targetMessageQueue, targe
4818
4896
 
4819
4897
 
4820
4898
 
4899
+
4821
4900
  const internalLogger = getLogger('internal');
4822
4901
  const ensureInitializeCalledLogger = internalLogger.extend('ensureInitializeCalled');
4823
4902
  const ensureInitializedLogger = internalLogger.extend('ensureInitialized');
@@ -4927,7 +5006,7 @@ function throwExceptionIfMobileApiIsNotSupported(requiredVersion = defaultSDKVer
4927
5006
  */
4928
5007
  function processAdditionalValidOrigins(validMessageOrigins) {
4929
5008
  let combinedOriginUrls = GlobalVars.additionalValidOrigins.concat(validMessageOrigins.filter((_origin) => {
4930
- return typeof _origin === 'string' && userOriginUrlValidationRegExp.test(_origin);
5009
+ return typeof _origin === 'string' && isValidPatternUrl(_origin);
4931
5010
  }));
4932
5011
  const dedupUrls = {};
4933
5012
  combinedOriginUrls = combinedOriginUrls.filter((_originUrl) => {
@@ -5403,7 +5482,7 @@ logWhereTeamsJsIsBeingUsed();
5403
5482
  * @param validMessageOrigins - Optionally specify a list of cross-frame message origins. This parameter is used if you know that your app
5404
5483
  * will be hosted on a custom domain (i.e., not a standard Microsoft 365 host like Teams, Outlook, etc.) Most apps will never need
5405
5484
  * to pass a value for this parameter.
5406
- * Any domains passed in the array must have the https: protocol on the string otherwise they will be ignored. Example: https://www.example.com
5485
+ * Any domains passed in the array must define a scheme to be able to be processed. Examples: https://www.example.com, chrome://
5407
5486
  * @returns Promise that will be fulfilled when initialization has completed, or rejected if the initialization fails or times out
5408
5487
  */
5409
5488
  function initialize(validMessageOrigins) {
@@ -6756,6 +6835,7 @@ var validOrigins_awaiter = (undefined && undefined.__awaiter) || function (thisA
6756
6835
 
6757
6836
 
6758
6837
 
6838
+
6759
6839
  let validOriginsCache = [];
6760
6840
  const validateOriginLogger = getLogger('validateOrigin');
6761
6841
  let validOriginsPromise;
@@ -6840,30 +6920,23 @@ function isValidOriginsJSONValid(validOriginsJSON) {
6840
6920
  return true;
6841
6921
  }
6842
6922
  /**
6923
+ * Validates the origin against the full pattern including protocol and hostname.
6843
6924
  * @param pattern - reference pattern
6844
- * @param host - candidate string
6845
- * @returns returns true if host matches pre-know valid pattern
6846
- *
6847
- * @example
6848
- * validateHostAgainstPattern('*.teams.microsoft.com', 'subdomain.teams.microsoft.com') returns true
6849
- * validateHostAgainstPattern('teams.microsoft.com', 'team.microsoft.com') returns false
6850
- *
6851
- * @internal
6852
- * Limited to Microsoft-internal use
6925
+ * @param origin - candidate URL object
6853
6926
  */
6854
- function validateHostAgainstPattern(pattern, host) {
6855
- if (pattern.substring(0, 2) === '*.') {
6856
- const suffix = pattern.substring(1);
6857
- if (host.length > suffix.length &&
6858
- host.split('.').length === suffix.split('.').length &&
6859
- host.substring(host.length - suffix.length) === suffix) {
6860
- return true;
6927
+ function validateOriginAgainstFullPattern(pattern, origin) {
6928
+ let patternUrl;
6929
+ try {
6930
+ const createdURLVerifier = createURLVerifier(pattern, validateOriginLogger);
6931
+ if (!createdURLVerifier) {
6932
+ return false;
6861
6933
  }
6934
+ patternUrl = createdURLVerifier;
6862
6935
  }
6863
- else if (pattern === host) {
6864
- return true;
6936
+ catch (_a) {
6937
+ return false;
6865
6938
  }
6866
- return false;
6939
+ return patternUrl.test(origin);
6867
6940
  }
6868
6941
  /**
6869
6942
  * @internal
@@ -6875,29 +6948,25 @@ function validateOrigin(messageOrigin, disableCache) {
6875
6948
  if (validateOriginWithValidOriginsList(messageOrigin, localList)) {
6876
6949
  return Promise.resolve(true);
6877
6950
  }
6878
- else {
6879
- validateOriginLogger('Origin %s is not in the local valid origins list, fetching from CDN', messageOrigin);
6880
- return getValidOriginsListFromCDN(disableCache).then((validOriginsList) => {
6881
- return validateOriginWithValidOriginsList(messageOrigin, validOriginsList);
6882
- });
6883
- }
6951
+ validateOriginLogger('Origin %s is not in the local valid origins list, fetching from CDN', messageOrigin);
6952
+ return getValidOriginsListFromCDN(disableCache).then((validOriginsList) => validateOriginWithValidOriginsList(messageOrigin, validOriginsList));
6884
6953
  }
6885
6954
  function validateOriginWithValidOriginsList(messageOrigin, validOriginsList) {
6886
- // Check whether the url is in the pre-known allowlist or supplied by user
6955
+ // User provided additional valid origins take precedence as they do not require https protocol
6956
+ for (const domainOrPattern of GlobalVars.additionalValidOrigins) {
6957
+ if (validateOriginAgainstFullPattern(domainOrPattern, messageOrigin)) {
6958
+ return true;
6959
+ }
6960
+ }
6961
+ const messageOriginHost = messageOrigin.host;
6962
+ // For standard valid origins, only allow https protocol
6887
6963
  if (!isValidHttpsURL(messageOrigin)) {
6888
6964
  validateOriginLogger('Origin %s is invalid because it is not using https protocol. Protocol being used: %s', messageOrigin, messageOrigin.protocol);
6889
6965
  return false;
6890
6966
  }
6891
- const messageOriginHost = messageOrigin.host;
6892
6967
  if (validOriginsList.some((pattern) => validateHostAgainstPattern(pattern, messageOriginHost))) {
6893
6968
  return true;
6894
6969
  }
6895
- for (const domainOrPattern of GlobalVars.additionalValidOrigins) {
6896
- const pattern = domainOrPattern.substring(0, 8) === 'https://' ? domainOrPattern.substring(8) : domainOrPattern;
6897
- if (validateHostAgainstPattern(pattern, messageOriginHost)) {
6898
- return true;
6899
- }
6900
- }
6901
6970
  validateOriginLogger('Origin %s is invalid because it is not an origin approved by this library or included in the call to app.initialize.\nOrigins approved by this library: %o\nOrigins included in app.initialize: %o', messageOrigin, validOriginsList, GlobalVars.additionalValidOrigins);
6902
6971
  return false;
6903
6972
  }