Skip to content

Commit cc2f3d9

Browse files
authored
Merge pull request from GHSA-m52x-29pq-w3vv
Fix potential XSS vulnerability
2 parents f42e80f + 40111b2 commit cc2f3d9

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/js/pannellum.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ function createHotSpot(hs) {
17191719
if (config.basePath && !absoluteURL(imgp))
17201720
imgp = config.basePath + imgp;
17211721
a = document.createElement('a');
1722-
a.href = sanitizeURL(hs.URL ? hs.URL : imgp);
1722+
a.href = sanitizeURL(hs.URL ? hs.URL : imgp, true);
17231723
a.target = '_blank';
17241724
span.appendChild(a);
17251725
var image = document.createElement('img');
@@ -1731,7 +1731,7 @@ function createHotSpot(hs) {
17311731
span.style.maxWidth = 'initial';
17321732
} else if (hs.URL) {
17331733
a = document.createElement('a');
1734-
a.href = sanitizeURL(hs.URL);
1734+
a.href = sanitizeURL(hs.URL, true);
17351735
if (hs.attributes) {
17361736
for (var key in hs.attributes) {
17371737
a.setAttribute(key, hs.attributes[key]);
@@ -2005,7 +2005,7 @@ function processOptions(isPreview) {
20052005
var authorText = escapeHTML(config[key]);
20062006
if (config.authorURL) {
20072007
var authorLink = document.createElement('a');
2008-
authorLink.href = sanitizeURL(config['authorURL']);
2008+
authorLink.href = sanitizeURL(config['authorURL'], true);
20092009
authorLink.target = '_blank';
20102010
authorLink.innerHTML = escapeHTML(config[key]);
20112011
authorText = authorLink.outerHTML;
@@ -2016,7 +2016,7 @@ function processOptions(isPreview) {
20162016

20172017
case 'fallback':
20182018
var link = document.createElement('a');
2019-
link.href = sanitizeURL(config[key]);
2019+
link.href = sanitizeURL(config[key], true);
20202020
link.target = '_blank';
20212021
link.textContent = 'Click here to view this panorama in an alternative viewer.';
20222022
var message = document.createElement('p');
@@ -2378,10 +2378,17 @@ function escapeHTML(s) {
23782378
* The URL cannot be of protocol 'javascript'.
23792379
* @private
23802380
* @param {string} url - URL to sanitize
2381+
* @param {boolean} href - True if URL is for link (blocks data URIs)
23812382
* @returns {string} Sanitized URL
23822383
*/
2383-
function sanitizeURL(url) {
2384-
if (url.trim().toLowerCase().indexOf('javascript:') === 0) {
2384+
function sanitizeURL(url, href) {
2385+
if (url.trim().toLowerCase().indexOf('javascript:') === 0 ||
2386+
url.trim().toLowerCase().indexOf('vbscript:') === 0) {
2387+
console.log('Script URL removed.');
2388+
return 'about:blank';
2389+
}
2390+
if (href && url.trim().toLowerCase().indexOf('data:') === 0) {
2391+
console.log('Data URI removed from link.');
23852392
return 'about:blank';
23862393
}
23872394
return url;

0 commit comments

Comments
 (0)