Skip to content
Open
Changes from all 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
10 changes: 9 additions & 1 deletion src/bento/components/bento-autocomplete/1.0/base-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {tryParseJson} from '#core/types/object/json';
import * as Preact from '#preact';
import {PreactBaseElement} from '#preact/base-element';

import {Purifier} from '#purifier';

import {BentoAutocomplete} from './component';
import {CSS as COMPONENT_CSS} from './component.jss';

Expand Down Expand Up @@ -71,10 +73,16 @@ export class BaseElement extends PreactBaseElement {
return;
}

// Mustache only escapes interpolated values; its output is not a security
// boundary. Suggestion data can come from a remote `src`, so run the
// rendered markup through the AMP Purifier before it reaches the DOM, the
// same way amp-mustache and amp-autocomplete sanitize template output.
const purifier = new Purifier(this.win.document);
this.mutateProps({
'itemTemplate': (data) => {
const html = mustache.render(template./*OK*/ innerHTML, data);
return <div dangerouslySetInnerHTML={{__html: html}} />;
const sanitized = purifier.purifyHtml(html)./*OK*/ innerHTML;
return <div dangerouslySetInnerHTML={{__html: sanitized}} />;
},
});
}
Expand Down
Loading