@weni/unnnic-system 2.27.0 → 2.28.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 +6 -0
- package/dist/{es-decba808.mjs → es-09c71e9f.mjs} +1 -1
- package/dist/{index-37969170.mjs → index-94c443ff.mjs} +5381 -5353
- package/dist/{pt-br-de4f26b2.mjs → pt-br-34ba2ea0.mjs} +1 -1
- package/dist/style.css +1 -1
- package/dist/unnnic.mjs +1 -1
- package/dist/unnnic.umd.js +33 -33
- package/package.json +1 -1
- package/src/components/FormElement/FormElement.vue +7 -4
- package/src/components/Input/BaseInput.vue +6 -2
- package/src/components/Input/Input.vue +7 -3
- package/src/components/Label/Label.vue +5 -1
- package/src/components/SelectSmart/SelectSmartOption.vue +6 -2
- package/src/components/TextArea/TextArea.vue +4 -2
- package/src/utils/sanitize.js +88 -0
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
]"
|
|
14
14
|
>
|
|
15
|
-
{{ label }}
|
|
15
|
+
{{ fullySanitize(label) }}
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
18
|
<slot></slot>
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
scheme="aux-red-500"
|
|
29
29
|
/>
|
|
30
30
|
|
|
31
|
-
{{ error }}
|
|
31
|
+
{{ fullySanitize(error) }}
|
|
32
32
|
</template>
|
|
33
33
|
|
|
34
34
|
<span
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
v-if="message || !!$slots.rightMessage"
|
|
44
44
|
class="unnnic-form-element__message"
|
|
45
45
|
>
|
|
46
|
-
{{ message }}
|
|
46
|
+
{{ fullySanitize(message) }}
|
|
47
47
|
|
|
48
48
|
<span
|
|
49
49
|
v-if="!shouldShowErrorSection && !!$slots.rightMessage"
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
|
|
58
58
|
<script>
|
|
59
59
|
import UnnnicIcon from '../../components/Icon.vue';
|
|
60
|
-
|
|
60
|
+
import { fullySanitize } from '../../utils/sanitize';
|
|
61
61
|
export default {
|
|
62
62
|
components: {
|
|
63
63
|
UnnnicIcon,
|
|
@@ -93,6 +93,9 @@ export default {
|
|
|
93
93
|
return this.error && (this.error !== true || !!this.$slots.rightMessage);
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
|
+
methods: {
|
|
97
|
+
fullySanitize,
|
|
98
|
+
},
|
|
96
99
|
};
|
|
97
100
|
</script>
|
|
98
101
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
v-if="mask"
|
|
4
4
|
v-mask="mask"
|
|
5
5
|
v-bind="attributes"
|
|
6
|
-
:value="modelValue"
|
|
6
|
+
:value="fullySanitize(modelValue)"
|
|
7
7
|
:class="classes"
|
|
8
8
|
:type="nativeType"
|
|
9
9
|
/>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<input
|
|
12
12
|
v-else
|
|
13
13
|
v-bind="attributes"
|
|
14
|
-
:value="modelValue"
|
|
14
|
+
:value="fullySanitize(modelValue)"
|
|
15
15
|
:class="classes"
|
|
16
16
|
:type="nativeType"
|
|
17
17
|
/>
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
<script>
|
|
21
21
|
import { mask } from 'vue-the-mask';
|
|
22
|
+
import { fullySanitize } from '../../utils/sanitize';
|
|
22
23
|
|
|
23
24
|
export default {
|
|
24
25
|
directives: { mask },
|
|
@@ -76,6 +77,9 @@ export default {
|
|
|
76
77
|
];
|
|
77
78
|
},
|
|
78
79
|
},
|
|
80
|
+
methods: {
|
|
81
|
+
fullySanitize,
|
|
82
|
+
},
|
|
79
83
|
};
|
|
80
84
|
</script>
|
|
81
85
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
v-else-if="label"
|
|
12
12
|
class="unnnic-form__label"
|
|
13
13
|
>
|
|
14
|
-
{{ label }}
|
|
14
|
+
{{ fullySanitize(label) }}
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
17
|
<TextInput
|
|
@@ -34,12 +34,13 @@
|
|
|
34
34
|
v-if="message"
|
|
35
35
|
class="unnnic-form__message"
|
|
36
36
|
>
|
|
37
|
-
{{ message }}
|
|
37
|
+
{{ fullySanitize(message) }}
|
|
38
38
|
</p>
|
|
39
39
|
</div>
|
|
40
40
|
</template>
|
|
41
41
|
|
|
42
42
|
<script>
|
|
43
|
+
import { fullySanitize } from '../../utils/sanitize';
|
|
43
44
|
import TextInput from './TextInput.vue';
|
|
44
45
|
|
|
45
46
|
export default {
|
|
@@ -117,9 +118,12 @@ export default {
|
|
|
117
118
|
return !!this.$slots.label;
|
|
118
119
|
},
|
|
119
120
|
},
|
|
121
|
+
methods: {
|
|
122
|
+
fullySanitize,
|
|
123
|
+
},
|
|
120
124
|
watch: {
|
|
121
125
|
val() {
|
|
122
|
-
this.$emit('update:modelValue', this.val);
|
|
126
|
+
this.$emit('update:modelValue', fullySanitize(this.val));
|
|
123
127
|
},
|
|
124
128
|
modelValue() {
|
|
125
129
|
this.val = this.modelValue;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<p class="unnnic-label__label">{{ label }}</p>
|
|
2
|
+
<p class="unnnic-label__label">{{ fullySanitize(label) }}</p>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
|
+
import { fullySanitize } from '../../utils/sanitize';
|
|
6
7
|
export default {
|
|
7
8
|
name: 'UnnnicLabel',
|
|
8
9
|
props: {
|
|
@@ -11,6 +12,9 @@ export default {
|
|
|
11
12
|
default: null,
|
|
12
13
|
},
|
|
13
14
|
},
|
|
15
|
+
methods: {
|
|
16
|
+
fullySanitize,
|
|
17
|
+
},
|
|
14
18
|
};
|
|
15
19
|
</script>
|
|
16
20
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
`unnnic-select-smart-option__label--${size}`,
|
|
28
28
|
]"
|
|
29
29
|
data-testid="label"
|
|
30
|
-
>{{ label }}</span
|
|
30
|
+
>{{ fullySanitize(label) }}</span
|
|
31
31
|
>
|
|
32
32
|
<p
|
|
33
33
|
v-if="description"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
`unnnic-select-smart-option__description--${size}`,
|
|
38
38
|
]"
|
|
39
39
|
>
|
|
40
|
-
{{ description }}
|
|
40
|
+
{{ fullySanitize(description) }}
|
|
41
41
|
</p>
|
|
42
42
|
</div>
|
|
43
43
|
</div>
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
<script>
|
|
47
47
|
import UnnnicCheckbox from '../Checkbox/Checkbox.vue';
|
|
48
|
+
import { fullySanitize } from '../../utils/sanitize';
|
|
48
49
|
|
|
49
50
|
export default {
|
|
50
51
|
name: 'UnnnicSelectSmartOption',
|
|
@@ -89,6 +90,9 @@ export default {
|
|
|
89
90
|
},
|
|
90
91
|
},
|
|
91
92
|
},
|
|
93
|
+
methods: {
|
|
94
|
+
fullySanitize,
|
|
95
|
+
},
|
|
92
96
|
};
|
|
93
97
|
</script>
|
|
94
98
|
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
`unnnic-text-area__textarea--size-${size}`,
|
|
14
14
|
`unnnic-text-area__textarea--type-${type}`,
|
|
15
15
|
]"
|
|
16
|
-
:placeholder="placeholder"
|
|
16
|
+
:placeholder="fullySanitize(placeholder)"
|
|
17
17
|
:maxlength="maxLength"
|
|
18
18
|
:disabled="disabled"
|
|
19
19
|
:value="modelValue"
|
|
20
|
-
@input="$emit('update:modelValue', $event.target.value)"
|
|
20
|
+
@input="$emit('update:modelValue', fullySanitize($event.target.value))"
|
|
21
21
|
></textarea>
|
|
22
22
|
|
|
23
23
|
<template
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
</template>
|
|
30
30
|
|
|
31
31
|
<script>
|
|
32
|
+
import { fullySanitize } from '../../utils/sanitize';
|
|
32
33
|
import UnnnicFormElement from '../FormElement/FormElement.vue';
|
|
33
34
|
|
|
34
35
|
export default {
|
|
@@ -83,6 +84,7 @@ export default {
|
|
|
83
84
|
emits: ['update:modelValue'],
|
|
84
85
|
|
|
85
86
|
methods: {
|
|
87
|
+
fullySanitize,
|
|
86
88
|
focus() {
|
|
87
89
|
this.$refs.textarea.focus();
|
|
88
90
|
},
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes HTML entities (`<` → `<`, `>` → `>`, etc.).
|
|
3
|
+
* @param {string} input
|
|
4
|
+
* @returns {string}
|
|
5
|
+
*/
|
|
6
|
+
export function escapeHtml(input) {
|
|
7
|
+
if (typeof input !== 'string') return '';
|
|
8
|
+
return input.replace(/<\/?[a-zA-Z]+\b[^>]*>/g, '');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Sanitizes HTML by removing disallowed tags and unsafe attributes.
|
|
13
|
+
* @param {string} input
|
|
14
|
+
* @param {Array<string>} allowedTags - List of allowed HTML tags.
|
|
15
|
+
* @param {number} maxLength - Maximum length of the sanitized string.
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
export function sanitizeHtml(input, allowedTags = [], maxLength = 1000) {
|
|
19
|
+
if (typeof input !== 'string') return '';
|
|
20
|
+
|
|
21
|
+
// Limits text length
|
|
22
|
+
if (input.length > maxLength) {
|
|
23
|
+
input = input.substring(0, maxLength);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Decodes HTML entities (<, >, &)
|
|
27
|
+
input = escapeHtml(input);
|
|
28
|
+
|
|
29
|
+
// Removes **only** real HTML tags
|
|
30
|
+
input = input.replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, (match, tagName) => {
|
|
31
|
+
return allowedTags.includes(tagName.toLowerCase()) ? match : '';
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return input;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Fully sanitizes a string by applying multiple layers of security:
|
|
39
|
+
* 1. `sanitizeHtml` removes disallowed tags and attributes.
|
|
40
|
+
* 2. `escapeHtml` ensures no encoded characters remain and removes any remaining tags.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} input
|
|
43
|
+
* @param {Array<string>} allowedTags - List of allowed HTML tags.
|
|
44
|
+
* @param {number} maxLength - Maximum length of the sanitized string.
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
export function fullySanitize(input, allowedTags = [], maxLength = 1000) {
|
|
48
|
+
if (typeof input !== 'string') return '';
|
|
49
|
+
|
|
50
|
+
let sanitizedInput = sanitizeHtml(input, allowedTags, maxLength);
|
|
51
|
+
|
|
52
|
+
return escapeHtml(sanitizedInput);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Validates and sanitizes input text.
|
|
57
|
+
* @param {string} input - The input string to validate.
|
|
58
|
+
* @param {Array<string>} allowedTags - List of allowed HTML tags.
|
|
59
|
+
* @param {number} maxLength - Maximum length of the sanitized string.
|
|
60
|
+
* @returns {{ isValid: boolean, sanitized: string, errors: string[] }} - Validation result.
|
|
61
|
+
*/
|
|
62
|
+
export function validateInput(input, allowedTags = [], maxLength = 1000) {
|
|
63
|
+
const errors = [];
|
|
64
|
+
|
|
65
|
+
if (typeof input !== 'string') {
|
|
66
|
+
errors.push('Input must be a string.');
|
|
67
|
+
return { isValid: false, sanitized: '', errors };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (input.length > maxLength) {
|
|
71
|
+
errors.push(`Input exceeds the maximum length of ${maxLength} characters.`);
|
|
72
|
+
input = input.substring(0, maxLength);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const sanitized = fullySanitize(input, allowedTags, maxLength);
|
|
76
|
+
|
|
77
|
+
if (sanitized !== input) {
|
|
78
|
+
errors.push(
|
|
79
|
+
'Some HTML tags or attributes were removed for security reasons.',
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
isValid: errors.length === 0,
|
|
85
|
+
sanitized,
|
|
86
|
+
errors,
|
|
87
|
+
};
|
|
88
|
+
}
|