-
Notifications
You must be signed in to change notification settings - Fork 19.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(tooltip): fix tooltip XSS issue when legend name is HTML string #20045
Conversation
Thanks for your contribution! The pull request is marked to be |
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-20045@6221076 |
@plainheart If use But in https://github.com/apache/echarts/pull/20045/files#diff-36702e9ce5f4d6cb00be763ce719953d6fd5384008ad5959e96502145ae344a5R608 we can not know the tooltip view renderMode yet to decide whether perform The only way I can think of right now is to add other internal property besides 'content' named maybe 'needEncode' to indicate that the 'content' (i.e., the default tooltip content) need to be encoded according to the different types of tooltip view. /** @file echarts/src/util/graphic.ts */
ecData.tooltipConfig = {
name: itemName,
option: defaults({
contentNeedEncode: true, // need to write as `__contentNeedEncode` like an internal option?
// or may be public in future?
content: itemName,
formatterParams: formatterParams
}, itemTooltipOptionObj)
}; /** @file echarts/echarts/src/util/types.ts */
export type ComponentItemTooltipOption<T> = CommonTooltipOption<T> & {
// Default content HTML.
content?: string;
// Whether to encode content acorrdoing to `tooltip.renderMode`.
// e.g., renderMode 'html' need to encode but 'richText' do not.
contentNeedEncode: boolean;
formatterParams?: ComponentItemTooltipLabelFormatterParams;
}; /** @file echarts/src/component/tooltip/TooltipView.ts */
private _getContentCascade(subTooltipModel: Model<TooltipOption & ComponentItemTooltipOption<unknown>>): string {
let tmpModel = subTooltipModel;
let defaultContent: string;
while (tmpModel) {
defaultContent = tmpModel.get('content', true);
if (this._renderMode === 'html' && tmpModel.get('contentNeedEncode', true)) {
defaultContent = encodeHTML(defaultContent);
}
tmpModel = tmpModel.parentModel;
}
return defaultContent;
}
private _showComponentItemTooltip(...) {
// ...
// const defaultHtml = subTooltipModel.get('content');
const defaultHtml = this._getContentCascade(subTooltipModel);
// ...
} I'm not sure whether it's a good idea |
…the content should be encoded by default
@100pah https://github.com/apache/echarts/blob/5.5.0/src/component/tooltip/TooltipView.ts#L747 passes the raw content of tooltipConfig option to |
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
Brief Information
This pull request is in the type of:
What does this PR do?
Some components use
graphic.setTooltipConfig
to provide the tooltip ability and use its name as the default tooltip content. This causes potential XSS issues when the name (likelegend
) is an HTML string. This PR tries to fix it by escaping the raw name from HTML. If users hope to render HTML, they can usetooltip.formatter
to do that.Before
After
Fixed issues
Details
Before: What was the problem?
After: How does it behave after the fixing?
Document Info
One of the following should be checked.
Misc
ZRender Changes
Related test cases or examples to use the new APIs
Please refer to the last test case in
test/tooltip.html
.Others
Merging options
Other information