@kikiutils/shared 15.0.3 → 15.1.1
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/README.md +137 -67
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js.map +1 -1
- package/dist/classes/path.d.ts +8 -0
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js +5 -0
- package/dist/classes/path.js.map +1 -1
- package/dist/classes/precision-number.d.ts +215 -11
- package/dist/classes/precision-number.d.ts.map +1 -1
- package/dist/classes/precision-number.js +268 -25
- package/dist/classes/precision-number.js.map +1 -1
- package/dist/classes/ssh-client.js.map +1 -1
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js.map +1 -1
- package/dist/consola.d.ts.map +1 -1
- package/dist/consola.js.map +1 -1
- package/dist/crypto-hash.d.ts +7 -7
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +7 -7
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js.map +1 -1
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js.map +1 -1
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/event-awaiter.js.map +1 -1
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js.map +1 -1
- package/dist/hash.d.ts +3 -3
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +3 -3
- package/dist/hash.js.map +1 -1
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js.map +1 -1
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js.map +1 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js.map +1 -1
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js.map +1 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +3 -3
- package/dist/storages/lru/keyed-store.js +3 -3
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +1 -1
- package/dist/storages/redis/keyed-store.js +1 -1
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/string.d.ts +12 -6
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +9 -6
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/url.d.ts +27 -3
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +37 -4
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js.map +1 -1
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +12 -21
- package/src/classes/path.ts +9 -0
- package/src/classes/precision-number.ts +300 -25
- package/src/crypto-hash.ts +7 -7
- package/src/hash.ts +3 -3
- package/src/storages/lru/keyed-store.ts +3 -3
- package/src/storages/redis/keyed-store.ts +1 -1
- package/src/string.ts +12 -6
- package/src/types/index.ts +39 -0
- package/src/url.ts +39 -7
package/src/url.ts
CHANGED
|
@@ -5,18 +5,15 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param {string} url - The target URL to modify
|
|
7
7
|
* @param {string} redirectPath - The path to use as the redirect destination
|
|
8
|
-
* (must be
|
|
8
|
+
* (must be a safe same-origin application path starting with `/`)
|
|
9
9
|
*
|
|
10
10
|
* @returns {string} A new URL string with the `redirect` query parameter
|
|
11
11
|
*
|
|
12
|
-
* @throws {Error} If redirectPath is not a
|
|
12
|
+
* @throws {Error} If redirectPath is not a safe same-origin application path
|
|
13
13
|
*/
|
|
14
14
|
export function appendRedirectParamToUrl(url: string, redirectPath: string) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
`Invalid redirect path: "${redirectPath}". Redirect paths must be absolute paths starting with '/'.`,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
15
|
+
// eslint-disable-next-line style/max-len
|
|
16
|
+
if (!isSafeRedirectPath(redirectPath)) throw new Error(`Invalid redirect path: "${redirectPath}". Redirect paths must be safe same-origin paths starting with '/'.`);
|
|
20
17
|
|
|
21
18
|
const [baseAndHash, rawQuery = ''] = url.split('?');
|
|
22
19
|
const [base, hash] = (baseAndHash || '').split('#');
|
|
@@ -25,3 +22,38 @@ export function appendRedirectParamToUrl(url: string, redirectPath: string) {
|
|
|
25
22
|
const queryString = searchParams.toString();
|
|
26
23
|
return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;
|
|
27
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns whether a value is a safe same-origin redirect path.
|
|
28
|
+
*
|
|
29
|
+
* Safe redirect paths are absolute application paths such as `/dashboard`.
|
|
30
|
+
* Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,
|
|
31
|
+
* and non-string values are rejected.
|
|
32
|
+
*
|
|
33
|
+
* @param {unknown} value - The value to check
|
|
34
|
+
*
|
|
35
|
+
* @returns {boolean} Whether the value is safe to use as an application redirect path
|
|
36
|
+
*/
|
|
37
|
+
export function isSafeRedirectPath(value: unknown): value is string {
|
|
38
|
+
if (typeof value !== 'string') return false;
|
|
39
|
+
if (!value.startsWith('/')) return false;
|
|
40
|
+
if (value.startsWith('//')) return false;
|
|
41
|
+
if (value.includes('\\')) return false;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Normalizes a redirect value into a safe same-origin application path.
|
|
47
|
+
*
|
|
48
|
+
* If an array is provided, the first value is checked. Unsafe values fall back
|
|
49
|
+
* to the provided fallback path.
|
|
50
|
+
*
|
|
51
|
+
* @param {unknown} value - The redirect value to normalize
|
|
52
|
+
* @param {string} fallback - The safe fallback path
|
|
53
|
+
*
|
|
54
|
+
* @returns {string} A safe redirect path
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeRedirectPath(value: unknown, fallback = '/') {
|
|
57
|
+
const redirectPath = Array.isArray(value) ? value[0] : value;
|
|
58
|
+
return isSafeRedirectPath(redirectPath) ? redirectPath : fallback;
|
|
59
|
+
}
|