Skip to content

Commit

Permalink
[Maps] Fix cross origin error for icon spritesheets when Kibana secur…
Browse files Browse the repository at this point in the history
…ed via OAuth proxy (elastic#53896) (elastic#61171)

* Set crossOrigin to anonymous only on requests from external hosts

* Update x-pack/legacy/plugins/maps/public/connected_components/map/mb/utils.js

Co-Authored-By: Joe Portner <[email protected]>

* 🙇‍♂️ Lint

Co-authored-by: Joe Portner <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Joe Portner <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Mar 24, 2020
1 parent c224350 commit 66cd8d8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ function getImageData(img) {
export async function loadSpriteSheetImageData(imgUrl) {
return new Promise((resolve, reject) => {
const image = new Image();
image.crossOrigin = 'Anonymous';
if (isCrossOriginUrl(imgUrl)) {
image.crossOrigin = 'Anonymous';
}
image.onload = el => {
const imgData = getImageData(el.currentTarget);
resolve(imgData);
Expand Down Expand Up @@ -142,3 +144,13 @@ export async function addSpritesheetToMap(json, imgUrl, mbMap) {
const imgData = await loadSpriteSheetImageData(imgUrl);
addSpriteSheetToMapFromImageData(json, imgData, mbMap);
}

function isCrossOriginUrl(url) {
const a = window.document.createElement('a');
a.href = url;
return (
a.protocol !== window.document.location.protocol ||
a.host !== window.document.location.host ||
a.port !== window.document.location.port
);
}

0 comments on commit 66cd8d8

Please sign in to comment.