Skip to content

Commit e0b1d5c

Browse files
authored
fix (lightbox): sanitize lightbox title (#3390)
Co-authored-by: [email protected] <>
1 parent ae145d8 commit e0b1d5c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lightbox/frontend-image-lightbox.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ const isImageBlock = el => {
9393
return el && el.classList.contains( 'stk-block-image' )
9494
}
9595

96+
function sanitize( string ) {
97+
const map = {
98+
'&': '&amp;',
99+
'<': '&lt;',
100+
'>': '&gt;',
101+
'"': '&quot;',
102+
"'": '&#x27;',
103+
'/': '&#x2F;',
104+
}
105+
const reg = /[&<>"'/]/ig
106+
return string.replace( reg, match => map[ match ] )
107+
}
108+
96109
class StackableImageLightbox {
97110
init = () => {
98111
this.elements = []
@@ -135,6 +148,10 @@ class StackableImageLightbox {
135148
title = imageBlock.getAttribute( 'alt' ) || null
136149
}
137150

151+
// Sanitize strings.
152+
title = title ? sanitize( title ) : null
153+
link = typeof link === 'string' ? sanitize( link ) : link
154+
138155
const isUsingImageBlock = ( ! link || ! href ) && imageBlock
139156

140157
this.elements.push( {

0 commit comments

Comments
 (0)