@kupola/kupola 1.2.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/CHANGELOG.md +130 -0
- package/INTEGRATION.md +440 -0
- package/PROJECT_SUMMARY.md +312 -0
- package/README.md +286 -0
- package/SKILL.md +572 -0
- package/css/accessibility.css +119 -0
- package/css/animations.css +224 -0
- package/css/brand-themes.css +300 -0
- package/css/colors_and_type.css +441 -0
- package/css/components-ext.css +4165 -0
- package/css/components.css +1483 -0
- package/css/kupola.css +12 -0
- package/css/responsive.css +697 -0
- package/css/scaffold.css +145 -0
- package/css/states.css +316 -0
- package/css/theme-dark.css +296 -0
- package/css/theme-light.css +296 -0
- package/css/utilities.css +171 -0
- package/dist/css/kupola.css +12 -0
- package/dist/icons/icons/activity.svg +3 -0
- package/dist/icons/icons/alert-circle.svg +1 -0
- package/dist/icons/icons/alert-triangle.svg +1 -0
- package/dist/icons/icons/alert.d27e24.svg +1 -0
- package/dist/icons/icons/alert.svg +1 -0
- package/dist/icons/icons/apple.svg +1 -0
- package/dist/icons/icons/arrow-down.svg +1 -0
- package/dist/icons/icons/arrow-expand.svg +1 -0
- package/dist/icons/icons/arrow-left.svg +1 -0
- package/dist/icons/icons/arrow-minimize.svg +1 -0
- package/dist/icons/icons/arrow-right-to-line.svg +1 -0
- package/dist/icons/icons/arrow-right.svg +1 -0
- package/dist/icons/icons/arrow-up-right.svg +1 -0
- package/dist/icons/icons/arrow-up.0c0c0d.svg +1 -0
- package/dist/icons/icons/arrow-up.svg +1 -0
- package/dist/icons/icons/at.svg +1 -0
- package/dist/icons/icons/atom.0c0c0d.svg +1 -0
- package/dist/icons/icons/atom.svg +1 -0
- package/dist/icons/icons/bar-chart-2.svg +1 -0
- package/dist/icons/icons/bar.svg +1 -0
- package/dist/icons/icons/bell.svg +1 -0
- package/dist/icons/icons/box.svg +1 -0
- package/dist/icons/icons/bug.svg +1 -0
- package/dist/icons/icons/button.svg +1 -0
- package/dist/icons/icons/calendar.svg +1 -0
- package/dist/icons/icons/check-circle.33c192.svg +1 -0
- package/dist/icons/icons/check-circle.svg +1 -0
- package/dist/icons/icons/check-square.svg +4 -0
- package/dist/icons/icons/check.d1d3db.svg +1 -0
- package/dist/icons/icons/check.svg +1 -0
- package/dist/icons/icons/chevron-down.svg +1 -0
- package/dist/icons/icons/chevron-left.svg +1 -0
- package/dist/icons/icons/chevron-right.svg +1 -0
- package/dist/icons/icons/chevron-up.svg +1 -0
- package/dist/icons/icons/circle.svg +1 -0
- package/dist/icons/icons/clock.svg +1 -0
- package/dist/icons/icons/cmd.svg +1 -0
- package/dist/icons/icons/code.svg +1 -0
- package/dist/icons/icons/columns.svg +1 -0
- package/dist/icons/icons/copy.svg +1 -0
- package/dist/icons/icons/cpu.svg +1 -0
- package/dist/icons/icons/dashboard.0c0c0d.svg +1 -0
- package/dist/icons/icons/dashboard.svg +1 -0
- package/dist/icons/icons/dollar.svg +1 -0
- package/dist/icons/icons/download.svg +1 -0
- package/dist/icons/icons/edit.svg +1 -0
- package/dist/icons/icons/extensions.svg +1 -0
- package/dist/icons/icons/external.svg +1 -0
- package/dist/icons/icons/eye.svg +1 -0
- package/dist/icons/icons/file-text.svg +1 -0
- package/dist/icons/icons/file.svg +1 -0
- package/dist/icons/icons/files.svg +1 -0
- package/dist/icons/icons/filter.svg +1 -0
- package/dist/icons/icons/folder-open.svg +4 -0
- package/dist/icons/icons/folder.svg +1 -0
- package/dist/icons/icons/gear.svg +1 -0
- package/dist/icons/icons/git.svg +1 -0
- package/dist/icons/icons/github.svg +1 -0
- package/dist/icons/icons/globe.svg +1 -0
- package/dist/icons/icons/grid-2x2.svg +1 -0
- package/dist/icons/icons/hash.svg +1 -0
- package/dist/icons/icons/heart.svg +1 -0
- package/dist/icons/icons/help-circle.svg +5 -0
- package/dist/icons/icons/help.svg +1 -0
- package/dist/icons/icons/home.svg +1 -0
- package/dist/icons/icons/icons.svg +153 -0
- package/dist/icons/icons/image.svg +1 -0
- package/dist/icons/icons/info-circle.svg +1 -0
- package/dist/icons/icons/info-square.svg +1 -0
- package/dist/icons/icons/info.387bff.svg +1 -0
- package/dist/icons/icons/info.svg +1 -0
- package/dist/icons/icons/input.svg +1 -0
- package/dist/icons/icons/key.svg +1 -0
- package/dist/icons/icons/layers.svg +1 -0
- package/dist/icons/icons/layout-grid.svg +6 -0
- package/dist/icons/icons/layout.svg +1 -0
- package/dist/icons/icons/link.svg +1 -0
- package/dist/icons/icons/list.svg +1 -0
- package/dist/icons/icons/lock.svg +1 -0
- package/dist/icons/icons/log-out.svg +1 -0
- package/dist/icons/icons/logo.svg +1 -0
- package/dist/icons/icons/mail.svg +1 -0
- package/dist/icons/icons/menu.svg +1 -0
- package/dist/icons/icons/message-circle.svg +1 -0
- package/dist/icons/icons/message-plus.svg +1 -0
- package/dist/icons/icons/message-square.svg +1 -0
- package/dist/icons/icons/mic.svg +1 -0
- package/dist/icons/icons/minus.svg +1 -0
- package/dist/icons/icons/moon.svg +1 -0
- package/dist/icons/icons/more-h.svg +1 -0
- package/dist/icons/icons/mouse.svg +1 -0
- package/dist/icons/icons/palette.svg +1 -0
- package/dist/icons/icons/panel-bottom.svg +1 -0
- package/dist/icons/icons/pause.svg +1 -0
- package/dist/icons/icons/play.svg +1 -0
- package/dist/icons/icons/plug.svg +1 -0
- package/dist/icons/icons/plus.0c0c0d.svg +1 -0
- package/dist/icons/icons/plus.svg +1 -0
- package/dist/icons/icons/refresh.svg +1 -0
- package/dist/icons/icons/ruler.svg +1 -0
- package/dist/icons/icons/scroll-text.svg +1 -0
- package/dist/icons/icons/search-menu.svg +1 -0
- package/dist/icons/icons/search.svg +1 -0
- package/dist/icons/icons/send.0c0c0d.svg +1 -0
- package/dist/icons/icons/send.svg +1 -0
- package/dist/icons/icons/settings.0c0c0d.svg +1 -0
- package/dist/icons/icons/settings.svg +1 -0
- package/dist/icons/icons/shield.svg +1 -0
- package/dist/icons/icons/sidebar-left.svg +1 -0
- package/dist/icons/icons/sidebar-right.svg +1 -0
- package/dist/icons/icons/sliders.svg +1 -0
- package/dist/icons/icons/sparkles.32f08c.svg +1 -0
- package/dist/icons/icons/sparkles.svg +1 -0
- package/dist/icons/icons/square.svg +1 -0
- package/dist/icons/icons/star.svg +1 -0
- package/dist/icons/icons/sun.svg +1 -0
- package/dist/icons/icons/table.svg +1 -0
- package/dist/icons/icons/terminal.svg +1 -0
- package/dist/icons/icons/trash.svg +1 -0
- package/dist/icons/icons/trending-down.svg +1 -0
- package/dist/icons/icons/trending-up.svg +1 -0
- package/dist/icons/icons/type.svg +1 -0
- package/dist/icons/icons/upload.svg +1 -0
- package/dist/icons/icons/user-circle.svg +1 -0
- package/dist/icons/icons/user-plus.svg +6 -0
- package/dist/icons/icons/user.svg +1 -0
- package/dist/icons/icons/users.svg +1 -0
- package/dist/icons/icons/warning.svg +1 -0
- package/dist/icons/icons/wrench.svg +1 -0
- package/dist/icons/icons/x-circle.svg +1 -0
- package/dist/icons/icons/x.svg +1 -0
- package/dist/icons/icons/zap.0c0c0d.svg +1 -0
- package/dist/icons/icons/zap.svg +1 -0
- package/dist/kupola.cjs.js +258 -0
- package/dist/kupola.cjs.js.map +1 -0
- package/dist/kupola.esm.js +7640 -0
- package/dist/kupola.esm.js.map +1 -0
- package/dist/kupola.umd.js +258 -0
- package/dist/kupola.umd.js.map +1 -0
- package/dist/types/kupola.d.ts +1359 -0
- package/dist/utils/utils/Kupola.cs +77 -0
- package/dist/utils/utils/Kupola.java +104 -0
- package/dist/utils/utils/kupola.go +120 -0
- package/dist/utils/utils/kupola.js +63 -0
- package/dist/utils/utils/kupola.py +1392 -0
- package/dist/utils/utils/kupola.rb +69 -0
- package/icons/activity.svg +3 -0
- package/icons/alert-circle.svg +1 -0
- package/icons/alert-triangle.svg +1 -0
- package/icons/alert.d27e24.svg +1 -0
- package/icons/alert.svg +1 -0
- package/icons/apple.svg +1 -0
- package/icons/arrow-down.svg +1 -0
- package/icons/arrow-expand.svg +1 -0
- package/icons/arrow-left.svg +1 -0
- package/icons/arrow-minimize.svg +1 -0
- package/icons/arrow-right-to-line.svg +1 -0
- package/icons/arrow-right.svg +1 -0
- package/icons/arrow-up-right.svg +1 -0
- package/icons/arrow-up.0c0c0d.svg +1 -0
- package/icons/arrow-up.svg +1 -0
- package/icons/at.svg +1 -0
- package/icons/atom.0c0c0d.svg +1 -0
- package/icons/atom.svg +1 -0
- package/icons/bar-chart-2.svg +1 -0
- package/icons/bar.svg +1 -0
- package/icons/bell.svg +1 -0
- package/icons/box.svg +1 -0
- package/icons/bug.svg +1 -0
- package/icons/button.svg +1 -0
- package/icons/calendar.svg +1 -0
- package/icons/check-circle.33c192.svg +1 -0
- package/icons/check-circle.svg +1 -0
- package/icons/check-square.svg +4 -0
- package/icons/check.d1d3db.svg +1 -0
- package/icons/check.svg +1 -0
- package/icons/chevron-down.svg +1 -0
- package/icons/chevron-left.svg +1 -0
- package/icons/chevron-right.svg +1 -0
- package/icons/chevron-up.svg +1 -0
- package/icons/circle.svg +1 -0
- package/icons/clock.svg +1 -0
- package/icons/cmd.svg +1 -0
- package/icons/code.svg +1 -0
- package/icons/columns.svg +1 -0
- package/icons/copy.svg +1 -0
- package/icons/cpu.svg +1 -0
- package/icons/dashboard.0c0c0d.svg +1 -0
- package/icons/dashboard.svg +1 -0
- package/icons/dollar.svg +1 -0
- package/icons/download.svg +1 -0
- package/icons/edit.svg +1 -0
- package/icons/extensions.svg +1 -0
- package/icons/external.svg +1 -0
- package/icons/eye.svg +1 -0
- package/icons/file-text.svg +1 -0
- package/icons/file.svg +1 -0
- package/icons/files.svg +1 -0
- package/icons/filter.svg +1 -0
- package/icons/folder-open.svg +4 -0
- package/icons/folder.svg +1 -0
- package/icons/gear.svg +1 -0
- package/icons/git.svg +1 -0
- package/icons/github.svg +1 -0
- package/icons/globe.svg +1 -0
- package/icons/grid-2x2.svg +1 -0
- package/icons/hash.svg +1 -0
- package/icons/heart.svg +1 -0
- package/icons/help-circle.svg +5 -0
- package/icons/help.svg +1 -0
- package/icons/home.svg +1 -0
- package/icons/icons.svg +153 -0
- package/icons/image.svg +1 -0
- package/icons/info-circle.svg +1 -0
- package/icons/info-square.svg +1 -0
- package/icons/info.387bff.svg +1 -0
- package/icons/info.svg +1 -0
- package/icons/input.svg +1 -0
- package/icons/key.svg +1 -0
- package/icons/layers.svg +1 -0
- package/icons/layout-grid.svg +6 -0
- package/icons/layout.svg +1 -0
- package/icons/link.svg +1 -0
- package/icons/list.svg +1 -0
- package/icons/lock.svg +1 -0
- package/icons/log-out.svg +1 -0
- package/icons/logo.svg +1 -0
- package/icons/mail.svg +1 -0
- package/icons/menu.svg +1 -0
- package/icons/message-circle.svg +1 -0
- package/icons/message-plus.svg +1 -0
- package/icons/message-square.svg +1 -0
- package/icons/mic.svg +1 -0
- package/icons/minus.svg +1 -0
- package/icons/moon.svg +1 -0
- package/icons/more-h.svg +1 -0
- package/icons/mouse.svg +1 -0
- package/icons/palette.svg +1 -0
- package/icons/panel-bottom.svg +1 -0
- package/icons/pause.svg +1 -0
- package/icons/play.svg +1 -0
- package/icons/plug.svg +1 -0
- package/icons/plus.0c0c0d.svg +1 -0
- package/icons/plus.svg +1 -0
- package/icons/refresh.svg +1 -0
- package/icons/ruler.svg +1 -0
- package/icons/scroll-text.svg +1 -0
- package/icons/search-menu.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/send.0c0c0d.svg +1 -0
- package/icons/send.svg +1 -0
- package/icons/settings.0c0c0d.svg +1 -0
- package/icons/settings.svg +1 -0
- package/icons/shield.svg +1 -0
- package/icons/sidebar-left.svg +1 -0
- package/icons/sidebar-right.svg +1 -0
- package/icons/sliders.svg +1 -0
- package/icons/sparkles.32f08c.svg +1 -0
- package/icons/sparkles.svg +1 -0
- package/icons/square.svg +1 -0
- package/icons/star.svg +1 -0
- package/icons/sun.svg +1 -0
- package/icons/table.svg +1 -0
- package/icons/terminal.svg +1 -0
- package/icons/trash.svg +1 -0
- package/icons/trending-down.svg +1 -0
- package/icons/trending-up.svg +1 -0
- package/icons/type.svg +1 -0
- package/icons/upload.svg +1 -0
- package/icons/user-circle.svg +1 -0
- package/icons/user-plus.svg +6 -0
- package/icons/user.svg +1 -0
- package/icons/users.svg +1 -0
- package/icons/warning.svg +1 -0
- package/icons/wrench.svg +1 -0
- package/icons/x-circle.svg +1 -0
- package/icons/x.svg +1 -0
- package/icons/zap.0c0c0d.svg +1 -0
- package/icons/zap.svg +1 -0
- package/js/calendar.js +184 -0
- package/js/carousel.js +173 -0
- package/js/collapse.js +127 -0
- package/js/color-picker.js +144 -0
- package/js/component.js +276 -0
- package/js/composition-api.js +458 -0
- package/js/countdown.js +144 -0
- package/js/data-bind.js +1286 -0
- package/js/datepicker.js +270 -0
- package/js/dialog.js +131 -0
- package/js/drawer.js +118 -0
- package/js/dropdown.js +122 -0
- package/js/dynamic-tags.js +156 -0
- package/js/error-handler.js +181 -0
- package/js/fileupload.js +392 -0
- package/js/form.js +291 -0
- package/js/global-events.js +203 -0
- package/js/heatmap.js +405 -0
- package/js/http.js +419 -0
- package/js/i18n.js +228 -0
- package/js/icons.js +165 -0
- package/js/image-preview.js +218 -0
- package/js/initializer.js +162 -0
- package/js/kupola-core.js +66 -0
- package/js/kupola-devtools.js +598 -0
- package/js/kupola-lifecycle.js +510 -0
- package/js/message.js +60 -0
- package/js/modal.js +191 -0
- package/js/notification.js +73 -0
- package/js/numberinput.js +146 -0
- package/js/performance.js +250 -0
- package/js/registry.js +205 -0
- package/js/router.js +396 -0
- package/js/security.js +189 -0
- package/js/select.js +143 -0
- package/js/slide-captcha.js +504 -0
- package/js/slider.js +94 -0
- package/js/statcard.js +219 -0
- package/js/tag.js +83 -0
- package/js/test-utils.js +251 -0
- package/js/theme.js +363 -0
- package/js/timepicker.js +238 -0
- package/js/tooltip.js +122 -0
- package/js/utils.js +1458 -0
- package/js/validation.js +553 -0
- package/js/virtual-list.js +593 -0
- package/package.json +105 -0
- package/templates/base.html +30 -0
- package/templates/base_dashboard.html +99 -0
- package/types/kupola.d.ts +1359 -0
- package/utils/Kupola.cs +77 -0
- package/utils/Kupola.java +104 -0
- package/utils/kupola.go +120 -0
- package/utils/kupola.js +63 -0
- package/utils/kupola.py +1392 -0
- package/utils/kupola.rb +69 -0
package/js/security.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
class KupolaSecurity {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.csrfToken = null;
|
|
4
|
+
this.cspEnabled = false;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
init() {
|
|
8
|
+
this._initCSRF();
|
|
9
|
+
this._initCSP();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_initCSRF() {
|
|
13
|
+
const metaTag = document.querySelector('meta[name="csrf-token"]');
|
|
14
|
+
if (metaTag) {
|
|
15
|
+
this.csrfToken = metaTag.getAttribute('content');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_initCSP() {
|
|
20
|
+
const metaTag = document.querySelector('meta[http-equiv="Content-Security-Policy"]');
|
|
21
|
+
if (metaTag) {
|
|
22
|
+
this.cspEnabled = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getCSRFToken() {
|
|
27
|
+
return this.csrfToken;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setCSRFToken(token) {
|
|
31
|
+
this.csrfToken = token;
|
|
32
|
+
const metaTag = document.querySelector('meta[name="csrf-token"]');
|
|
33
|
+
if (metaTag) {
|
|
34
|
+
metaTag.setAttribute('content', token);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
addCSRFHeader(config) {
|
|
39
|
+
if (this.csrfToken) {
|
|
40
|
+
config.headers = config.headers || {};
|
|
41
|
+
config.headers['X-CSRF-Token'] = this.csrfToken;
|
|
42
|
+
}
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
escapeHtml(str) {
|
|
47
|
+
if (!str || typeof str !== 'string') return str;
|
|
48
|
+
const div = document.createElement('div');
|
|
49
|
+
div.textContent = str;
|
|
50
|
+
return div.innerHTML;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
sanitize(html) {
|
|
54
|
+
if (!html || typeof html !== 'string') return html;
|
|
55
|
+
|
|
56
|
+
const allowedTags = [
|
|
57
|
+
'b', 'strong', 'i', 'em', 'u', 's', 'strike', 'sub', 'sup',
|
|
58
|
+
'a', 'br', 'p', 'span', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
59
|
+
'ul', 'ol', 'li', 'table', 'thead', 'tbody', 'tr', 'td', 'th',
|
|
60
|
+
'img', 'video', 'audio', 'iframe'
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const allowedAttributes = [
|
|
64
|
+
'href', 'src', 'alt', 'title', 'class', 'id', 'data-*',
|
|
65
|
+
'width', 'height', 'frameborder', 'allowfullscreen'
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const tempDiv = document.createElement('div');
|
|
69
|
+
tempDiv.innerHTML = html;
|
|
70
|
+
|
|
71
|
+
const walk = (node) => {
|
|
72
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
73
|
+
const tagName = node.tagName.toLowerCase();
|
|
74
|
+
if (!allowedTags.includes(tagName)) {
|
|
75
|
+
node.parentNode.replaceChild(document.createTextNode(node.textContent), node);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Array.from(node.attributes).forEach(attr => {
|
|
80
|
+
const attrName = attr.name.toLowerCase();
|
|
81
|
+
const isAllowed = allowedAttributes.includes(attrName) ||
|
|
82
|
+
attrName.startsWith('data-');
|
|
83
|
+
|
|
84
|
+
if (!isAllowed) {
|
|
85
|
+
node.removeAttribute(attr.name);
|
|
86
|
+
} else if (attrName === 'href' || attrName === 'src') {
|
|
87
|
+
if (!this._isSafeUrl(attr.value)) {
|
|
88
|
+
node.removeAttribute(attr.name);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for (let i = node.childNodes.length - 1; i >= 0; i--) {
|
|
95
|
+
walk(node.childNodes[i]);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
walk(tempDiv);
|
|
100
|
+
return tempDiv.innerHTML;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_isSafeUrl(url) {
|
|
104
|
+
try {
|
|
105
|
+
const parsed = new URL(url);
|
|
106
|
+
const safeProtocols = ['http:', 'https:', 'data:', 'mailto:', 'tel:'];
|
|
107
|
+
return safeProtocols.includes(parsed.protocol);
|
|
108
|
+
} catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
validateEmail(email) {
|
|
114
|
+
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
115
|
+
return re.test(email);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
validateURL(url) {
|
|
119
|
+
try {
|
|
120
|
+
new URL(url);
|
|
121
|
+
return true;
|
|
122
|
+
} catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
validatePhone(phone) {
|
|
128
|
+
const re = /^[\d\s\-\+\(\)]{7,20}$/;
|
|
129
|
+
return re.test(phone.replace(/\s/g, ''));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
generateSecureHash(str) {
|
|
133
|
+
if (!str || typeof str !== 'string') return '';
|
|
134
|
+
|
|
135
|
+
let hash = 0;
|
|
136
|
+
for (let i = 0; i < str.length; i++) {
|
|
137
|
+
const char = str.charCodeAt(i);
|
|
138
|
+
hash = ((hash << 5) - hash) + char;
|
|
139
|
+
hash = hash & hash;
|
|
140
|
+
}
|
|
141
|
+
return Math.abs(hash).toString(36);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
isXSSAttack(str) {
|
|
145
|
+
if (!str || typeof str !== 'string') return false;
|
|
146
|
+
|
|
147
|
+
const xssPatterns = [
|
|
148
|
+
/<script[^>]*>.*?<\/script>/gi,
|
|
149
|
+
/<img[^>]*onerror[^>]*>/gi,
|
|
150
|
+
/javascript:/gi,
|
|
151
|
+
/vbscript:/gi,
|
|
152
|
+
/onload[^>]*=/gi,
|
|
153
|
+
/onclick[^>]*=/gi,
|
|
154
|
+
/onmouseover[^>]*=/gi,
|
|
155
|
+
/<iframe[^>]*>/gi
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
return xssPatterns.some(pattern => pattern.test(str));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
protectForm(form) {
|
|
162
|
+
if (!(form instanceof HTMLFormElement)) return;
|
|
163
|
+
|
|
164
|
+
form.addEventListener('submit', (e) => {
|
|
165
|
+
const inputs = form.querySelectorAll('input, textarea');
|
|
166
|
+
let hasXSS = false;
|
|
167
|
+
|
|
168
|
+
inputs.forEach(input => {
|
|
169
|
+
if (this.isXSSAttack(input.value)) {
|
|
170
|
+
hasXSS = true;
|
|
171
|
+
input.classList.add('ds-input--error');
|
|
172
|
+
} else {
|
|
173
|
+
input.classList.remove('ds-input--error');
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (hasXSS) {
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
console.error('[KupolaSecurity] XSS attack detected in form');
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const kupolaSecurity = new KupolaSecurity();
|
|
186
|
+
window.kupolaSecurity = kupolaSecurity;
|
|
187
|
+
window.KupolaSecurity = KupolaSecurity;
|
|
188
|
+
|
|
189
|
+
export default KupolaSecurity;
|
package/js/select.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
class Select {
|
|
2
|
+
constructor(element) {
|
|
3
|
+
this.element = element;
|
|
4
|
+
this.trigger = element.querySelector('.ds-select__trigger');
|
|
5
|
+
this.valueEl = element.querySelector('.ds-select__value') || element.querySelector('.ds-select__trigger span');
|
|
6
|
+
this.optionsEl = element.querySelector('.ds-select__options') || element.querySelector('.ds-select__menu');
|
|
7
|
+
this.nativeSelect = element.querySelector('select');
|
|
8
|
+
this.icon = element.querySelector('.ds-select__icon');
|
|
9
|
+
this.scope = `select-${Math.random().toString(36).substr(2, 9)}`;
|
|
10
|
+
|
|
11
|
+
this._triggerClickHandler = null;
|
|
12
|
+
this._documentClickHandler = null;
|
|
13
|
+
this._documentClickListener = null;
|
|
14
|
+
this._optionClickHandler = null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
init() {
|
|
18
|
+
if (!this.trigger || !this.optionsEl) return;
|
|
19
|
+
if (this.element.__kupolaInitialized) return;
|
|
20
|
+
|
|
21
|
+
this._optionClickHandler = (e) => {
|
|
22
|
+
const option = e.currentTarget;
|
|
23
|
+
const value = option.getAttribute('data-value');
|
|
24
|
+
if (this.nativeSelect) {
|
|
25
|
+
this.nativeSelect.value = value;
|
|
26
|
+
}
|
|
27
|
+
this.optionsEl.querySelectorAll('.ds-select__option, .ds-select__item').forEach(o => o.classList.remove('is-selected'));
|
|
28
|
+
option.classList.add('is-selected');
|
|
29
|
+
this.updateValue(option.textContent.trim());
|
|
30
|
+
this.hideOptions();
|
|
31
|
+
if (this.nativeSelect) {
|
|
32
|
+
this.nativeSelect.dispatchEvent(new Event('change'));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
this.optionsEl.querySelectorAll('.ds-select__option, .ds-select__item').forEach(option => {
|
|
37
|
+
option.addEventListener('click', this._optionClickHandler);
|
|
38
|
+
option._selectOptionClickHandler = this._optionClickHandler;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
this._triggerClickHandler = (e) => {
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
this.showOptions();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
this.trigger.addEventListener('click', this._triggerClickHandler);
|
|
47
|
+
|
|
48
|
+
this._documentClickHandler = (e) => {
|
|
49
|
+
if (!this.element.contains(e.target)) {
|
|
50
|
+
this.hideOptions();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (window.globalEvents) {
|
|
55
|
+
this._documentClickListener = window.globalEvents.on(document, 'click', this._documentClickHandler, { scope: this.scope });
|
|
56
|
+
} else {
|
|
57
|
+
document.addEventListener('click', this._documentClickHandler);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.optionsEl.style.display = 'none';
|
|
61
|
+
this.element.__kupolaInitialized = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
updateValue(text) {
|
|
65
|
+
if (this.valueEl) {
|
|
66
|
+
this.valueEl.textContent = text || this.valueEl.textContent;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
showOptions() {
|
|
71
|
+
const isOpen = this.optionsEl.style.display === 'block';
|
|
72
|
+
this.optionsEl.style.display = isOpen ? 'none' : 'block';
|
|
73
|
+
if (this.icon) {
|
|
74
|
+
this.icon.style.transform = isOpen ? 'rotate(0deg)' : 'rotate(180deg)';
|
|
75
|
+
}
|
|
76
|
+
this.element.classList.toggle('is-open', !isOpen);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
hideOptions() {
|
|
80
|
+
this.optionsEl.style.display = 'none';
|
|
81
|
+
if (this.icon) {
|
|
82
|
+
this.icon.style.transform = 'rotate(0deg)';
|
|
83
|
+
}
|
|
84
|
+
this.element.classList.remove('is-open');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
destroy() {
|
|
88
|
+
if (!this.element.__kupolaInitialized) return;
|
|
89
|
+
|
|
90
|
+
if (this.trigger && this._triggerClickHandler) {
|
|
91
|
+
this.trigger.removeEventListener('click', this._triggerClickHandler);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (this.optionsEl) {
|
|
95
|
+
this.optionsEl.querySelectorAll('.ds-select__option, .ds-select__item').forEach(option => {
|
|
96
|
+
if (option._selectOptionClickHandler) {
|
|
97
|
+
option.removeEventListener('click', option._selectOptionClickHandler);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (this._documentClickListener && this._documentClickListener.unsubscribe) {
|
|
103
|
+
this._documentClickListener.unsubscribe();
|
|
104
|
+
} else if (this._documentClickHandler) {
|
|
105
|
+
document.removeEventListener('click', this._documentClickHandler);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this._documentClickHandler = null;
|
|
109
|
+
this._documentClickListener = null;
|
|
110
|
+
this._triggerClickHandler = null;
|
|
111
|
+
this._optionClickHandler = null;
|
|
112
|
+
this.element.__kupolaInitialized = false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function initSelect(element) {
|
|
117
|
+
const select = new Select(element);
|
|
118
|
+
select.init();
|
|
119
|
+
element._kupolaSelect = select;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function initSelects(root = document) {
|
|
123
|
+
root.querySelectorAll('.ds-select').forEach(select => {
|
|
124
|
+
initSelect(select);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function cleanupSelect(select) {
|
|
129
|
+
if (select._kupolaSelect) {
|
|
130
|
+
select._kupolaSelect.destroy();
|
|
131
|
+
select._kupolaSelect = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function cleanupAllSelects() {
|
|
136
|
+
document.querySelectorAll('.ds-select').forEach(select => {
|
|
137
|
+
cleanupSelect(select);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (window.kupolaInitializer) {
|
|
142
|
+
window.kupolaInitializer.register('select', initSelect, cleanupSelect);
|
|
143
|
+
}
|