* 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)
| 21783 | * whether it is of an allowed origin. |
| 21784 | */ |
| 21785 | function urlIsAllowedOriginFactory(whitelistedOriginUrls) { |
| 21786 | var parsedAllowedOriginUrls = [originUrl].concat(whitelistedOriginUrls.map(urlResolve)); |
| 21787 | |
| 21788 | /** |
| 21789 | * Check whether the specified URL (string or parsed URL object) has an origin that is allowed |
| 21790 | * based on a list of whitelisted-origin URLs. The current location's origin is implicitly |
| 21791 | * trusted. |
| 21792 | * |
| 21793 | * @param {string|Object} requestUrl - The URL to be checked (provided as a string that will be |
| 21794 | * resolved or a parsed URL object). |
| 21795 | * |
| 21796 | * @returns {boolean} - Whether the specified URL is of an allowed origin. |
| 21797 | */ |
| 21798 | return function urlIsAllowedOrigin(requestUrl) { |
| 21799 | var parsedUrl = urlResolve(requestUrl); |
| 21800 | return parsedAllowedOriginUrls.some(urlsAreSameOrigin.bind(null, parsedUrl)); |
| 21801 | }; |
| 21802 | } |
| 21803 | |
| 21804 | /** |
| 21805 | * Determine if two URLs share the same origin. |
no test coverage detected