* Create a function that can check a URL's origin against a list of allowed/whitelisted origins. * The current location's origin is implicitly trusted. * * @param {string[]} whitelistedOriginUrls - A list of URLs (strings), whose origins are trusted. * * @returns {Function} - A function that re
(whitelistedOriginUrls)
| 21062 | * whether it is of an allowed origin. |
| 21063 | */ |
| 21064 | function urlIsAllowedOriginFactory(whitelistedOriginUrls) { |
| 21065 | var parsedAllowedOriginUrls = [originUrl].concat(whitelistedOriginUrls.map(urlResolve)); |
| 21066 | |
| 21067 | /** |
| 21068 | * Check whether the specified URL (string or parsed URL object) has an origin that is allowed |
| 21069 | * based on a list of whitelisted-origin URLs. The current location's origin is implicitly |
| 21070 | * trusted. |
| 21071 | * |
| 21072 | * @param {string|Object} requestUrl - The URL to be checked (provided as a string that will be |
| 21073 | * resolved or a parsed URL object). |
| 21074 | * |
| 21075 | * @returns {boolean} - Whether the specified URL is of an allowed origin. |
| 21076 | */ |
| 21077 | return function urlIsAllowedOrigin(requestUrl) { |
| 21078 | var parsedUrl = urlResolve(requestUrl); |
| 21079 | return parsedAllowedOriginUrls.some(urlsAreSameOrigin.bind(null, parsedUrl)); |
| 21080 | }; |
| 21081 | } |
| 21082 | |
| 21083 | /** |
| 21084 | * Determine if two URLs share the same origin. |
no test coverage detected