Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions assets/dev/js/editor/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ColorPicker from './color-picker';
import DocumentHelper from 'elementor-editor/document/helper-bc';
import ContainerHelper from 'elementor-editor-utils/container-helper';
import DOMPurify from 'dompurify';
import { isValidAttribute } from 'dompurify';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import DOMPurify from 'dompurify';
import { isValidAttribute } from 'dompurify';
import DOMPurify, { isValidAttribute } from 'dompurify';

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


const allowedHTMLWrapperTags = [
'article',
Expand Down Expand Up @@ -704,4 +705,10 @@ module.exports = {
sanitize( value, options ) {
return DOMPurify.sanitize( value, options );
},

sanitizeUrl( url ) {
const isValidUrl = isValidAttribute( 'a', 'href', url );

return isValidUrl ? url : '';
},
};
2 changes: 1 addition & 1 deletion includes/widgets/heading.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ protected function content_template() {
let title = elementor.helpers.sanitize( settings.title, { ALLOW_DATA_ATTR: false } );

if ( '' !== settings.link.url ) {
title = '<a href="' + _.escape( settings.link.url ) + '">' + title + '</a>';
title = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '">' + title + '</a>';
}

view.addRenderAttribute( 'title', 'class', [ 'elementor-heading-title' ] );
Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/icon-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ protected function content_template() {
view.addRenderAttribute( 'icon', 'class', 'elementor-icon elementor-animation-' + settings.hover_animation );

if ( hasLink ) {
view.addRenderAttribute( 'link', 'href', settings.link.url );
view.addRenderAttribute( 'link', 'href', elementor.helpers.sanitizeUrl( settings.link.url ) );
view.addRenderAttribute( 'icon', 'tabindex', '-1' );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/icon-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ protected function content_template() {

<li {{{ view.getRenderAttributeString( 'list_item' ) }}}>
<# if ( item.link && item.link.url ) { #>
<a href="{{ item.link.url }}">
<a href="{{ elementor.helpers.sanitizeUrl( item.link.url ) }}">
<# } #>
<# if ( item.icon || item.selected_icon.value ) { #>
<span class="elementor-icon-list-icon">
Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ protected function content_template() {
return;
}

const link = settings.link.url ? 'href="' + _.escape( settings.link.url ) + '"' : '',
const link = settings.link.url ? 'href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '"' : '',
iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' ),
iconTag = link ? 'a' : 'div';
Expand Down
4 changes: 2 additions & 2 deletions includes/widgets/image-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ protected function content_template() {
var imageHtml = '<img src="' + _.escape( image_url ) + '" class="elementor-animation-' + _.escape( settings.hover_animation ) + '" />';

if ( settings.link.url ) {
imageHtml = '<a href="' + _.escape( settings.link.url ) + '" tabindex="-1">' + imageHtml + '</a>';
imageHtml = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '" tabindex="-1">' + imageHtml + '</a>';
}

html += '<figure class="elementor-image-box-img">' + imageHtml + '</figure>';
Expand All @@ -714,7 +714,7 @@ protected function content_template() {
titleSizeTag = elementor.helpers.validateHTMLTag( settings.title_size );

if ( settings.link.url ) {
title_html = '<a href="' + _.escape( settings.link.url ) + '">' + title_html + '</a>';
title_html = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '">' + title_html + '</a>';
}

view.addRenderAttribute( 'title_text', 'class', 'elementor-image-box-title' );
Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ protected function content_template() {
}

if ( link_url ) {
#><a class="elementor-clickable" data-elementor-open-lightbox="{{ settings.open_lightbox }}" href="{{ link_url }}"><#
#><a class="elementor-clickable" data-elementor-open-lightbox="{{ settings.open_lightbox }}" href="{{ elementor.helpers.sanitizeUrl( link_url ) }}"><#
}
#><img src="{{ image_url }}" class="{{ imgClass }}" /><#

Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/social-icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ protected function content_template() {
social = elementor.helpers.getSocialNetworkNameFromIcon( item.social_icon, item.social, false, migrated );
#>
<span class="elementor-grid-item">
<a class="elementor-icon elementor-social-icon elementor-social-icon-{{ social }} elementor-animation-{{ settings.hover_animation }} elementor-repeater-item-{{item._id}}" href="{{ link }}">
<a class="elementor-icon elementor-social-icon elementor-social-icon-{{ social }} elementor-animation-{{ settings.hover_animation }} elementor-repeater-item-{{item._id}}" href="{{ elementor.helpers.sanitizeUrl( link ) }}">
<span class="elementor-screen-only">{{{ social }}}</span>
<#
iconsHTML[ index ] = elementor.helpers.renderIcon( view, item.social_icon, {}, 'i', 'object' );
Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/testimonial.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ protected function content_template() {

var imageHtml = '<img src="' + _.escape( imageUrl ) + '" alt="testimonial" />';
if ( settings.link.url ) {
imageHtml = '<a href="' + _.escape( settings.link.url ) + '">' + imageHtml + '</a>';
imageHtml = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '">' + imageHtml + '</a>';
}
}

Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/traits/button-trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ protected function content_template() {
view.addRenderAttribute( 'button', 'class', 'elementor-button' );

if ( '' !== settings.link.url ) {
view.addRenderAttribute( 'button', 'href', settings.link.url );
view.addRenderAttribute( 'button', 'href', elementor.helpers.sanitizeUrl( settings.link.url ) );
view.addRenderAttribute( 'button', 'class', 'elementor-button-link' );
} else {
view.addRenderAttribute( 'button', 'role', 'button' );
Expand Down