Skip to content
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 potential security risk #12380

Merged
merged 3 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/chart/sunburst/SunburstView.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as zrUtil from 'zrender/src/core/util';
import ChartView from '../../view/Chart';
import SunburstPiece from './SunburstPiece';
import DataDiffer from '../../data/DataDiffer';
import {windowOpen} from '../../util/format';

var ROOT_TO_NODE_ACTION = 'sunburstRootToNode';

Expand Down Expand Up @@ -206,7 +207,7 @@ var SunburstView = ChartView.extend({
if (link) {
var linkTarget = itemModel.get('target', true)
|| '_blank';
window.open(link, linkTarget);
windowOpen(link, linkTarget);
}
}
targetFound = true;
Expand Down
3 changes: 2 additions & 1 deletion src/chart/treemap/TreemapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import BoundingRect from 'zrender/src/core/BoundingRect';
import * as matrix from 'zrender/src/core/matrix';
import * as animationUtil from '../../util/animation';
import makeStyleMapper from '../../model/mixin/makeStyleMapper';
import {windowOpen} from '../../util/format';

var bind = zrUtil.bind;
var Group = graphic.Group;
Expand Down Expand Up @@ -544,7 +545,7 @@ export default echarts.extendChartView({
var itemModel = node.hostTree.data.getItemModel(node.dataIndex);
var link = itemModel.get('link', true);
var linkTarget = itemModel.get('target', true) || 'blank';
link && window.open(link, linkTarget);
link && windowOpen(link, linkTarget);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/component/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as zrUtil from 'zrender/src/core/util';
import * as echarts from '../echarts';
import * as graphic from '../util/graphic';
import {getLayoutRect} from '../util/layout';
import {windowOpen} from '../util/format';

// Model
echarts.extendComponentModel({
Expand Down Expand Up @@ -143,12 +144,12 @@ echarts.extendComponentView({

if (link) {
textEl.on('click', function () {
window.open(link, '_' + titleModel.get('target'));
windowOpen(link, '_' + titleModel.get('target'));
});
}
if (sublink) {
subTextEl.on('click', function () {
window.open(sublink, '_' + titleModel.get('subtarget'));
windowOpen(link, '_' + titleModel.get('subtarget'));
});
}

Expand Down
18 changes: 17 additions & 1 deletion src/util/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as numberUtil from './number';
// import Text from 'zrender/src/graphic/Text';

/**
* 每三位默认加,格式化
* add commas after every three numbers
* @param {string|number} x
* @return {string}
*/
Expand Down Expand Up @@ -275,3 +275,19 @@ export function getTextRect(
text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate
);
}

/**
* open new tab
* @param {string} link url
* @param {string} target blank or self
*/
export function windowOpen(link, target) {
if (target === '_blank' || target === 'blank') {
var blank = window.open();
blank.opener = null;
blank.location = link;
}
else {
window.open(link, target);
}
}