Skip to content

Commit 21320f6

Browse files
committed
MC-15311: [Sec] PageBuilder XSS Injection Possible Through Block on HTML Code Content Type For CSS Classes Attribute & in TinyMCE
- add form field validation for css class values
1 parent 5a69a2c commit 21320f6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

app/code/Magento/PageBuilder/view/adminhtml/ui_component/pagebuilder_base_form.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@
184184
<dataType>text</dataType>
185185
<label translate="true">CSS Classes</label>
186186
<notice translate="true">Space separated list of classes.</notice>
187+
<validation>
188+
<rule name="validate-css-class" xsi:type="boolean">true</rule>
189+
</validation>
187190
</settings>
188191
</field>
189192
<field name="margins_and_padding" sortOrder="70" formElement="input" component="Magento_PageBuilder/js/form/element/margins-and-padding">

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/validator-rules-mixin.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ define([
5252
return (/<a[\s]+([^>]+)>|<a>|<\/a>/igm).test(str);
5353
}
5454

55+
/**
56+
* Validate that string is a proper css-class
57+
* @param {String} str
58+
* @return {Boolean}
59+
*/
60+
function validateCssClass(str) {
61+
return (/^[a-zA-Z_\-\d]+$/i).test(str);
62+
}
63+
5564
/**
5665
* Validate message field and url field anchor tag is used exclusively by one field
5766
* @param {String} message
@@ -147,6 +156,18 @@ define([
147156
$.mage.__('Please enter a valid video URL.')
148157
);
149158

159+
validator.addRule(
160+
'validate-css-class',
161+
function (value) {
162+
if (utils.isEmptyNoTrim(value)) {
163+
return true;
164+
}
165+
166+
return validateCssClass(value);
167+
},
168+
$.mage.__('Please enter a valid CSS class.')
169+
);
170+
150171
validator.addRule(
151172
'required-entry',
152173
function (value) {

0 commit comments

Comments
 (0)