mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Disallows use of "dangerouslySetInnerHTML" on React components, except where explicitly whitelisted
This commit is contained in:
parent
dc6ef763fe
commit
56fe6cbb33
4 changed files with 27 additions and 3 deletions
|
@ -105,6 +105,7 @@ module.exports = {
|
||||||
'react/jsx-indent-props': ['error', 2],
|
'react/jsx-indent-props': ['error', 2],
|
||||||
'react/jsx-max-props-per-line': ['error', { maximum: 1, when: 'multiline' }],
|
'react/jsx-max-props-per-line': ['error', { maximum: 1, when: 'multiline' }],
|
||||||
'react/jsx-no-duplicate-props': ['error', { ignoreCase: true }],
|
'react/jsx-no-duplicate-props': ['error', { ignoreCase: true }],
|
||||||
|
'react/no-danger': 'error',
|
||||||
'react/self-closing-comp': 'error',
|
'react/self-closing-comp': 'error',
|
||||||
'react/jsx-wrap-multilines': ['error', {
|
'react/jsx-wrap-multilines': ['error', {
|
||||||
declaration: true,
|
declaration: true,
|
||||||
|
|
|
@ -37,7 +37,15 @@ class MetricVisValue extends Component {
|
||||||
<div
|
<div
|
||||||
className="metric-value"
|
className="metric-value"
|
||||||
style={metricValueStyle}
|
style={metricValueStyle}
|
||||||
dangerouslySetInnerHTML={{ __html: metric.value }}
|
/*
|
||||||
|
* Justification for dangerouslySetInnerHTML:
|
||||||
|
* This is one of the visualizations which makes use of the HTML field formatters.
|
||||||
|
* Since these formatters produce raw HTML, this visualization needs to be able to render them as-is, relying
|
||||||
|
* on the field formatter to only produce safe HTML.
|
||||||
|
* `metric.value` is set by the MetricVisComponent, so this component must make sure this value never contains
|
||||||
|
* any unsafe HTML (e.g. by bypassing the field formatter).
|
||||||
|
*/
|
||||||
|
dangerouslySetInnerHTML={{ __html: metric.value }} //eslint-disable-line react/no-danger
|
||||||
/>
|
/>
|
||||||
{ showLabel &&
|
{ showLabel &&
|
||||||
<div>{metric.label}</div>
|
<div>{metric.label}</div>
|
||||||
|
|
|
@ -12,6 +12,10 @@ import MarkdownIt from 'markdown-it';
|
||||||
*/
|
*/
|
||||||
export function markdownFactory(whiteListedRules, openLinksInNewTab = false) {
|
export function markdownFactory(whiteListedRules, openLinksInNewTab = false) {
|
||||||
let markdownIt;
|
let markdownIt;
|
||||||
|
|
||||||
|
// It is imperitive that the html config property be set to false, to mitigate XSS: the output of markdown-it is
|
||||||
|
// fed directly to the DOM via React's dangerouslySetInnerHTML below.
|
||||||
|
|
||||||
if (whiteListedRules && whiteListedRules.length > 0) {
|
if (whiteListedRules && whiteListedRules.length > 0) {
|
||||||
markdownIt = new MarkdownIt('zero', { html: false, linkify: true });
|
markdownIt = new MarkdownIt('zero', { html: false, linkify: true });
|
||||||
markdownIt.enable(whiteListedRules);
|
markdownIt.enable(whiteListedRules);
|
||||||
|
@ -89,7 +93,12 @@ export class Markdown extends Component {
|
||||||
<div
|
<div
|
||||||
className={classes}
|
className={classes}
|
||||||
{...rest}
|
{...rest}
|
||||||
dangerouslySetInnerHTML={this.state.renderedMarkdown}
|
/*
|
||||||
|
* Justification for dangerouslySetInnerHTML:
|
||||||
|
* The Markdown Visulization is, believe it or not, responsible for rendering Markdown.
|
||||||
|
* This relies on `markdown-it` to produce safe and correct HTML.
|
||||||
|
*/
|
||||||
|
dangerouslySetInnerHTML={this.state.renderedMarkdown} //eslint-disable-line react/no-danger
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,7 +349,13 @@ Notifier.prototype.banner = function (content = '') {
|
||||||
title="Attention"
|
title="Attention"
|
||||||
iconType="help"
|
iconType="help"
|
||||||
>
|
>
|
||||||
<div dangerouslySetInnerHTML={{ __html: markdownIt.render(content) }} />
|
<div
|
||||||
|
/*
|
||||||
|
* Justification for dangerouslySetInnerHTML:
|
||||||
|
* The notifier relies on `markdown-it` to produce safe and correct HTML.
|
||||||
|
*/
|
||||||
|
dangerouslySetInnerHTML={{ __html: markdownIt.render(content) }} //eslint-disable-line react/no-danger
|
||||||
|
/>
|
||||||
|
|
||||||
<EuiButton type="primary" size="s" onClick={dismissBanner}>
|
<EuiButton type="primary" size="s" onClick={dismissBanner}>
|
||||||
Dismiss
|
Dismiss
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue