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 (#53896)

* 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 <5295965+jportner@users.noreply.github.com>

* 🙇‍♂️ Lint

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 24, 2020
1 parent 498abb4 commit 72afbbb
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 72afbbb

Please sign in to comment.