billboard.js 3.18.0-next.2 → 3.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +319 -100
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +10 -9
- package/dist/billboard.pkgd.js +2059 -1625
- package/dist/billboard.pkgd.min.js +23 -22
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +305 -79
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-stanford.js +305 -79
- package/dist/plugin/billboardjs-plugin-stanford.min.js +11 -11
- package/dist/plugin/billboardjs-plugin-tableview.js +305 -79
- package/dist/plugin/billboardjs-plugin-tableview.min.js +6 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +305 -79
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +4 -4
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1743 -1528
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +8 -8
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2047 -1606
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +2048 -1607
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +17 -17
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +2049 -1608
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +13 -12
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +2050 -1609
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +10 -10
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/billboard.js +441 -135
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +416 -102
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/package.json +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/internals/tooltip.ts +11 -9
- package/src/config/Options/axis/y2.ts +0 -13
- package/src/config/Options/common/legend.ts +1 -0
- package/src/config/Options/common/point.ts +1 -1
- package/src/config/Options/common/tooltip.ts +3 -1
- package/src/module/sanitize.ts +471 -0
- package/src/module/util.ts +1 -131
package/src/module/util.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {brushSelection as d3BrushSelection} from "d3-brush";
|
|
|
7
7
|
import {pointer as d3Pointer} from "d3-selection";
|
|
8
8
|
import type {d3Selection} from "../../types/types";
|
|
9
9
|
import {document, requestAnimationFrame, window} from "./browser";
|
|
10
|
+
import {sanitize} from "./sanitize";
|
|
10
11
|
|
|
11
12
|
// ====================================
|
|
12
13
|
// Internal Helper (Not Exported)
|
|
@@ -57,95 +58,6 @@ function _forEachValidItem<T>(items: T[], callback: (item: T, index: number) =>
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
/**
|
|
61
|
-
* Private sanitization utilities
|
|
62
|
-
* Encapsulates all XSS prevention patterns and helper functions
|
|
63
|
-
* @private
|
|
64
|
-
*/
|
|
65
|
-
const _sanitize = (() => {
|
|
66
|
-
const DANGEROUS_TAGS =
|
|
67
|
-
"script|iframe|object|embed|form|input|button|textarea|select|style|link|meta|base|math|isindex";
|
|
68
|
-
|
|
69
|
-
// HTML entity character code map (for decoding)
|
|
70
|
-
const ENTITY_MAP = {
|
|
71
|
-
quot: 34,
|
|
72
|
-
amp: 38,
|
|
73
|
-
apos: 39,
|
|
74
|
-
lt: 60,
|
|
75
|
-
gt: 62,
|
|
76
|
-
nbsp: 160,
|
|
77
|
-
iexcl: 161,
|
|
78
|
-
cent: 162,
|
|
79
|
-
pound: 163,
|
|
80
|
-
curren: 164,
|
|
81
|
-
yen: 165
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// Angle bracket codes (< and >) - never decode these to prevent tag bypass
|
|
85
|
-
const LT_CODE = 60;
|
|
86
|
-
const GT_CODE = 62;
|
|
87
|
-
|
|
88
|
-
// Maximum sanitization iterations to prevent infinite loops
|
|
89
|
-
const MAX_ITERATIONS = 10;
|
|
90
|
-
|
|
91
|
-
// Regular expressions (compiled once for performance)
|
|
92
|
-
const rx = {
|
|
93
|
-
tags: new RegExp(
|
|
94
|
-
`<(${DANGEROUS_TAGS})\\b[\\s\\S]*?>([\\s\\S]*?<\\/(${DANGEROUS_TAGS})\\s*>)?`,
|
|
95
|
-
"gi"
|
|
96
|
-
),
|
|
97
|
-
htmlEntity: /&#x([0-9a-f]+);?|&#([0-9]+);?|&([a-z]+);/gi,
|
|
98
|
-
// eslint-disable-next-line no-control-regex
|
|
99
|
-
controlChar: /[\x00-\x1F\x7F]/g,
|
|
100
|
-
eventHandler:
|
|
101
|
-
/\s+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|`[^`]*`|[^\s>]*)|on\w+\s*=\s*(?:"[^"]*"|'[^']*'|`[^`]*`|[^\s>]*)/gi,
|
|
102
|
-
dangerousUri: /(href|src|action|xlink:href)\s*=\s*(['"`]?)([^'"`>\s]*)\2/gi,
|
|
103
|
-
dangerousProtocol: /^(javascript|data|vbscript):/
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
ENTITY_MAP,
|
|
108
|
-
LT_CODE,
|
|
109
|
-
GT_CODE,
|
|
110
|
-
MAX_ITERATIONS,
|
|
111
|
-
rx,
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Decode HTML entities to prevent bypass attacks
|
|
115
|
-
* @param {string} str String with potential HTML entities
|
|
116
|
-
* @returns {string} Decoded string
|
|
117
|
-
*/
|
|
118
|
-
decodeEntities(str: string): string {
|
|
119
|
-
return str.replace(rx.htmlEntity, (match, hex, dec, named) => {
|
|
120
|
-
const code = hex ?
|
|
121
|
-
parseInt(hex, 16) :
|
|
122
|
-
dec ?
|
|
123
|
-
parseInt(dec, 10) :
|
|
124
|
-
named ?
|
|
125
|
-
ENTITY_MAP[named.toLowerCase()] || 0 :
|
|
126
|
-
0;
|
|
127
|
-
|
|
128
|
-
// Never decode angle brackets to prevent tag bypass
|
|
129
|
-
return code && code !== LT_CODE && code !== GT_CODE ?
|
|
130
|
-
String.fromCharCode(code) :
|
|
131
|
-
match;
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Remove dangerous URI protocols from attribute values
|
|
137
|
-
* @param {string} str String to sanitize
|
|
138
|
-
* @returns {string} Sanitized string
|
|
139
|
-
*/
|
|
140
|
-
removeDangerousUris(str: string): string {
|
|
141
|
-
return str.replace(rx.dangerousUri, (match, attr, quote, value) => {
|
|
142
|
-
const normalized = value.toLowerCase().replace(/\s/g, "");
|
|
143
|
-
return rx.dangerousProtocol.test(normalized) ? `${attr}=${quote}${quote}` : match;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
})();
|
|
148
|
-
|
|
149
61
|
// ====================================
|
|
150
62
|
// Exported
|
|
151
63
|
// ====================================
|
|
@@ -258,48 +170,6 @@ function endall(transition, cb: Function): void {
|
|
|
258
170
|
}
|
|
259
171
|
}
|
|
260
172
|
|
|
261
|
-
/**
|
|
262
|
-
* Sanitize HTML string to prevent XSS attacks
|
|
263
|
-
* Uses blacklist approach with repeated application to prevent nested tag bypass
|
|
264
|
-
* Handles encoded characters (HTML entities, Unicode escapes) to prevent bypass attacks
|
|
265
|
-
* @param {string} str Target string value
|
|
266
|
-
* @returns {string} Sanitized string with dangerous elements removed
|
|
267
|
-
* @private
|
|
268
|
-
*/
|
|
269
|
-
function sanitize(str: string): string {
|
|
270
|
-
// Early return for non-string, empty string, or string without HTML
|
|
271
|
-
if (!isString(str) || !str || str.indexOf("<") === -1) {
|
|
272
|
-
return str;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
let result = str;
|
|
276
|
-
let prev: string;
|
|
277
|
-
let iterations = 0;
|
|
278
|
-
|
|
279
|
-
// Repeat until no more changes (prevents nested tag attacks like <scri<script>pt>)
|
|
280
|
-
do {
|
|
281
|
-
prev = result;
|
|
282
|
-
|
|
283
|
-
// 1. Decode HTML entities to prevent bypass (e.g., jav
ascript:)
|
|
284
|
-
// 2. Remove control characters (NULL, tab, newline, etc.)
|
|
285
|
-
// 3. Remove dangerous tags (script, iframe, etc.)
|
|
286
|
-
result = _sanitize.decodeEntities(result)
|
|
287
|
-
.replace(_sanitize.rx.controlChar, "")
|
|
288
|
-
.replace(_sanitize.rx.tags, "")
|
|
289
|
-
.replace(_sanitize.rx.eventHandler, ""); // 4. Remove event handlers
|
|
290
|
-
|
|
291
|
-
// 5. Remove dangerous URIs (javascript:, data:, vbscript:)
|
|
292
|
-
result = _sanitize.removeDangerousUris(result);
|
|
293
|
-
|
|
294
|
-
// Safety check to prevent infinite loops
|
|
295
|
-
if (++iterations >= _sanitize.MAX_ITERATIONS) {
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
} while (result !== prev);
|
|
299
|
-
|
|
300
|
-
return result;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
173
|
/**
|
|
304
174
|
* Set text value. If there're multiline add nodes.
|
|
305
175
|
* @param {d3Selection} node Text node
|