TextPanel: Allow iframes (after sanitization) (#92299)

* Allow iframes in text panel

* add more attributes

* remove =true
This commit is contained in:
Kristian Bremberg 2024-08-27 15:44:58 +02:00 committed by GitHub
parent 7c408f5e16
commit 24afc7a5b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -19,7 +19,14 @@ describe('sanitizeUrl', () => {
}); });
}); });
// write test to sanitize xss payloads using the sanitize function describe('sanitizeIframe', () => {
it('should sanitize iframe tags', () => {
const html = '<iframe src="javascript:alert(document.domain)"></iframe>';
const str = sanitizeTextPanelContent(html);
expect(str).toBe('<iframe src="about:blank" sandbox credentialless referrerpolicy=no-referrer></iframe>');
});
});
describe('sanitize', () => { describe('sanitize', () => {
it('should sanitize xss payload', () => { it('should sanitize xss payload', () => {
const html = '<script>alert(1)</script>'; const html = '<script>alert(1)</script>';

View File

@ -7,7 +7,20 @@ const XSSWL = Object.keys(xss.whiteList).reduce<xss.IWhiteList>((acc, element) =
return acc; return acc;
}, {}); }, {});
// Add iframe tags to XSSWL.
// We don't allow the sandbox attribute, since it can be overridden, instead we add it below.
XSSWL.iframe = ['src', 'width', 'height'];
const sanitizeTextPanelWhitelist = new xss.FilterXSS({ const sanitizeTextPanelWhitelist = new xss.FilterXSS({
// Add sandbox attribute to iframe tags if an attribute is allowed.
onTagAttr: function (tag, name, value, isWhiteAttr) {
if (tag === 'iframe') {
return isWhiteAttr
? ` ${name}="${xss.escapeAttrValue(sanitizeUrl(value))}" sandbox credentialless referrerpolicy=no-referrer`
: '';
}
return;
},
whiteList: XSSWL, whiteList: XSSWL,
css: { css: {
whiteList: { whiteList: {