@kya-os/consent 0.1.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/constants/auth-modes.d.ts +54 -0
- package/dist/constants/auth-modes.d.ts.map +1 -0
- package/dist/constants/auth-modes.js +128 -0
- package/dist/constants/auth-modes.js.map +1 -0
- package/dist/constants/colors.d.ts +38 -0
- package/dist/constants/colors.d.ts.map +1 -0
- package/dist/constants/colors.js +40 -0
- package/dist/constants/colors.js.map +1 -0
- package/dist/constants/defaults.d.ts +112 -0
- package/dist/constants/defaults.d.ts.map +1 -0
- package/dist/constants/defaults.js +146 -0
- package/dist/constants/defaults.js.map +1 -0
- package/dist/constants/index.d.ts +11 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +37 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/resolution/index.d.ts +12 -0
- package/dist/resolution/index.d.ts.map +1 -0
- package/dist/resolution/index.js +28 -0
- package/dist/resolution/index.js.map +1 -0
- package/dist/resolution/resolve-branding.d.ts +70 -0
- package/dist/resolution/resolve-branding.d.ts.map +1 -0
- package/dist/resolution/resolve-branding.js +159 -0
- package/dist/resolution/resolve-branding.js.map +1 -0
- package/dist/resolution/resolve-config.d.ts +81 -0
- package/dist/resolution/resolve-config.d.ts.map +1 -0
- package/dist/resolution/resolve-config.js +254 -0
- package/dist/resolution/resolve-config.js.map +1 -0
- package/dist/resolution/resolve-copy.d.ts +53 -0
- package/dist/resolution/resolve-copy.d.ts.map +1 -0
- package/dist/resolution/resolve-copy.js +136 -0
- package/dist/resolution/resolve-copy.js.map +1 -0
- package/dist/schemas/api.schemas.d.ts +984 -0
- package/dist/schemas/api.schemas.d.ts.map +1 -0
- package/dist/schemas/api.schemas.js +153 -0
- package/dist/schemas/api.schemas.js.map +1 -0
- package/dist/schemas/branding.schemas.d.ts +100 -0
- package/dist/schemas/branding.schemas.d.ts.map +1 -0
- package/dist/schemas/branding.schemas.js +57 -0
- package/dist/schemas/branding.schemas.js.map +1 -0
- package/dist/schemas/config.schemas.d.ts +1182 -0
- package/dist/schemas/config.schemas.d.ts.map +1 -0
- package/dist/schemas/config.schemas.js +147 -0
- package/dist/schemas/config.schemas.js.map +1 -0
- package/dist/schemas/index.d.ts +13 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +29 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/modes.schemas.d.ts +406 -0
- package/dist/schemas/modes.schemas.d.ts.map +1 -0
- package/dist/schemas/modes.schemas.js +107 -0
- package/dist/schemas/modes.schemas.js.map +1 -0
- package/dist/security/escape.d.ts +114 -0
- package/dist/security/escape.d.ts.map +1 -0
- package/dist/security/escape.js +202 -0
- package/dist/security/escape.js.map +1 -0
- package/dist/security/index.d.ts +10 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +26 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/validators.d.ts +98 -0
- package/dist/security/validators.d.ts.map +1 -0
- package/dist/security/validators.js +210 -0
- package/dist/security/validators.js.map +1 -0
- package/dist/styles/css-variables.d.ts +78 -0
- package/dist/styles/css-variables.d.ts.map +1 -0
- package/dist/styles/css-variables.js +129 -0
- package/dist/styles/css-variables.js.map +1 -0
- package/dist/styles/index.d.ts +12 -0
- package/dist/styles/index.d.ts.map +1 -0
- package/dist/styles/index.js +28 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/stylesheet.d.ts +57 -0
- package/dist/styles/stylesheet.d.ts.map +1 -0
- package/dist/styles/stylesheet.js +204 -0
- package/dist/styles/stylesheet.js.map +1 -0
- package/dist/styles/tokens.d.ts +141 -0
- package/dist/styles/tokens.d.ts.map +1 -0
- package/dist/styles/tokens.js +183 -0
- package/dist/styles/tokens.js.map +1 -0
- package/dist/templates/base/base-template.d.ts +81 -0
- package/dist/templates/base/base-template.d.ts.map +1 -0
- package/dist/templates/base/base-template.js +282 -0
- package/dist/templates/base/base-template.js.map +1 -0
- package/dist/templates/base/components.d.ts +120 -0
- package/dist/templates/base/components.d.ts.map +1 -0
- package/dist/templates/base/components.js +295 -0
- package/dist/templates/base/components.js.map +1 -0
- package/dist/templates/base/index.d.ts +8 -0
- package/dist/templates/base/index.d.ts.map +1 -0
- package/dist/templates/base/index.js +26 -0
- package/dist/templates/base/index.js.map +1 -0
- package/dist/templates/index.d.ts +18 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +34 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/modes/consent-only.template.d.ts +36 -0
- package/dist/templates/modes/consent-only.template.d.ts.map +1 -0
- package/dist/templates/modes/consent-only.template.js +74 -0
- package/dist/templates/modes/consent-only.template.js.map +1 -0
- package/dist/templates/modes/credentials.template.d.ts +65 -0
- package/dist/templates/modes/credentials.template.d.ts.map +1 -0
- package/dist/templates/modes/credentials.template.js +414 -0
- package/dist/templates/modes/credentials.template.js.map +1 -0
- package/dist/templates/modes/index.d.ts +14 -0
- package/dist/templates/modes/index.d.ts.map +1 -0
- package/dist/templates/modes/index.js +24 -0
- package/dist/templates/modes/index.js.map +1 -0
- package/dist/templates/modes/magic-link.template.d.ts +33 -0
- package/dist/templates/modes/magic-link.template.d.ts.map +1 -0
- package/dist/templates/modes/magic-link.template.js +196 -0
- package/dist/templates/modes/magic-link.template.js.map +1 -0
- package/dist/templates/modes/oauth.template.d.ts +40 -0
- package/dist/templates/modes/oauth.template.d.ts.map +1 -0
- package/dist/templates/modes/oauth.template.js +153 -0
- package/dist/templates/modes/oauth.template.js.map +1 -0
- package/dist/templates/modes/otp.template.d.ts +35 -0
- package/dist/templates/modes/otp.template.d.ts.map +1 -0
- package/dist/templates/modes/otp.template.js +316 -0
- package/dist/templates/modes/otp.template.js.map +1 -0
- package/dist/templates/modes/success.template.d.ts +41 -0
- package/dist/templates/modes/success.template.d.ts.map +1 -0
- package/dist/templates/modes/success.template.js +140 -0
- package/dist/templates/modes/success.template.js.map +1 -0
- package/dist/templates/registry.d.ts +62 -0
- package/dist/templates/registry.d.ts.map +1 -0
- package/dist/templates/registry.js +135 -0
- package/dist/templates/registry.js.map +1 -0
- package/dist/types/api.types.d.ts +134 -0
- package/dist/types/api.types.d.ts.map +1 -0
- package/dist/types/api.types.js +10 -0
- package/dist/types/api.types.js.map +1 -0
- package/dist/types/branding.types.d.ts +53 -0
- package/dist/types/branding.types.d.ts.map +1 -0
- package/dist/types/branding.types.js +10 -0
- package/dist/types/branding.types.js.map +1 -0
- package/dist/types/config.types.d.ts +201 -0
- package/dist/types/config.types.d.ts.map +1 -0
- package/dist/types/config.types.js +10 -0
- package/dist/types/config.types.js.map +1 -0
- package/dist/types/copy.types.d.ts +109 -0
- package/dist/types/copy.types.d.ts.map +1 -0
- package/dist/types/copy.types.js +10 -0
- package/dist/types/copy.types.js.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +31 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/modes.types.d.ts +197 -0
- package/dist/types/modes.types.d.ts.map +1 -0
- package/dist/types/modes.types.js +35 -0
- package/dist/types/modes.types.js.map +1 -0
- package/dist/types/page.types.d.ts +120 -0
- package/dist/types/page.types.d.ts.map +1 -0
- package/dist/types/page.types.js +10 -0
- package/dist/types/page.types.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Consent Mode Schemas
|
|
4
|
+
*
|
|
5
|
+
* Zod validation schemas for auth mode configurations.
|
|
6
|
+
*
|
|
7
|
+
* @module @kya-os/consent/schemas/modes
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ModeConfigsSchema = exports.IDVConfigSchema = exports.PasskeyConfigSchema = exports.QRCodeConfigSchema = exports.OTPConfigSchema = exports.MagicLinkConfigSchema = exports.OAuthConfigSchema = exports.CredentialsConfigSchema = exports.AuthModeSchema = void 0;
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const modes_types_1 = require("../types/modes.types");
|
|
13
|
+
/**
|
|
14
|
+
* Auth Mode Schema
|
|
15
|
+
*/
|
|
16
|
+
exports.AuthModeSchema = zod_1.z.enum([
|
|
17
|
+
modes_types_1.AUTH_MODES.CONSENT_ONLY,
|
|
18
|
+
modes_types_1.AUTH_MODES.CREDENTIALS,
|
|
19
|
+
modes_types_1.AUTH_MODES.OAUTH,
|
|
20
|
+
modes_types_1.AUTH_MODES.MAGIC_LINK,
|
|
21
|
+
modes_types_1.AUTH_MODES.OTP,
|
|
22
|
+
modes_types_1.AUTH_MODES.QR_CODE,
|
|
23
|
+
modes_types_1.AUTH_MODES.PASSKEY,
|
|
24
|
+
modes_types_1.AUTH_MODES.IDV,
|
|
25
|
+
]);
|
|
26
|
+
/**
|
|
27
|
+
* Credentials Config Schema
|
|
28
|
+
*/
|
|
29
|
+
exports.CredentialsConfigSchema = zod_1.z.object({
|
|
30
|
+
usernameLabel: zod_1.z.string().max(100).optional(),
|
|
31
|
+
usernamePlaceholder: zod_1.z.string().max(200).optional(),
|
|
32
|
+
passwordLabel: zod_1.z.string().max(100).optional(),
|
|
33
|
+
passwordPlaceholder: zod_1.z.string().max(200).optional(),
|
|
34
|
+
showRememberMe: zod_1.z.boolean().optional(),
|
|
35
|
+
showForgotPassword: zod_1.z.boolean().optional(),
|
|
36
|
+
forgotPasswordUrl: zod_1.z.string().url().optional(),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* OAuth Config Schema
|
|
40
|
+
*/
|
|
41
|
+
exports.OAuthConfigSchema = zod_1.z.object({
|
|
42
|
+
providerId: zod_1.z.string().max(100).optional(),
|
|
43
|
+
providerName: zod_1.z.string().max(100).optional(),
|
|
44
|
+
buttonText: zod_1.z.string().max(100).optional(),
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Magic Link Config Schema
|
|
48
|
+
*/
|
|
49
|
+
exports.MagicLinkConfigSchema = zod_1.z.object({
|
|
50
|
+
enabled: zod_1.z.boolean().optional(),
|
|
51
|
+
emailLabel: zod_1.z.string().max(100).optional(),
|
|
52
|
+
emailPlaceholder: zod_1.z.string().max(200).optional(),
|
|
53
|
+
buttonText: zod_1.z.string().max(100).optional(),
|
|
54
|
+
resendCooldown: zod_1.z.number().int().min(30).max(600).optional(),
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* OTP Config Schema
|
|
58
|
+
*/
|
|
59
|
+
exports.OTPConfigSchema = zod_1.z.object({
|
|
60
|
+
enabled: zod_1.z.boolean().optional(),
|
|
61
|
+
phoneLabel: zod_1.z.string().max(100).optional(),
|
|
62
|
+
phonePlaceholder: zod_1.z.string().max(200).optional(),
|
|
63
|
+
instructions: zod_1.z.string().max(500).optional(),
|
|
64
|
+
digits: zod_1.z.union([zod_1.z.literal(4), zod_1.z.literal(6), zod_1.z.literal(8)]).optional(),
|
|
65
|
+
resendCooldown: zod_1.z.number().int().min(30).max(600).optional(),
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* QR Code Config Schema
|
|
69
|
+
*/
|
|
70
|
+
exports.QRCodeConfigSchema = zod_1.z.object({
|
|
71
|
+
enabled: zod_1.z.boolean().optional(),
|
|
72
|
+
instructions: zod_1.z.string().max(500).optional(),
|
|
73
|
+
size: zod_1.z.number().int().min(100).max(500).optional(),
|
|
74
|
+
showManualEntry: zod_1.z.boolean().optional(),
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Passkey Config Schema
|
|
78
|
+
*/
|
|
79
|
+
exports.PasskeyConfigSchema = zod_1.z.object({
|
|
80
|
+
enabled: zod_1.z.boolean().optional(),
|
|
81
|
+
instructions: zod_1.z.string().max(500).optional(),
|
|
82
|
+
buttonText: zod_1.z.string().max(100).optional(),
|
|
83
|
+
showCompatibilityInfo: zod_1.z.boolean().optional(),
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* IDV Config Schema
|
|
87
|
+
*/
|
|
88
|
+
exports.IDVConfigSchema = zod_1.z.object({
|
|
89
|
+
enabled: zod_1.z.boolean().optional(),
|
|
90
|
+
providerName: zod_1.z.string().max(100).optional(),
|
|
91
|
+
verificationType: zod_1.z.enum(["document", "selfie", "both"]).optional(),
|
|
92
|
+
instructions: zod_1.z.string().max(500).optional(),
|
|
93
|
+
estimatedTime: zod_1.z.string().max(50).optional(),
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Mode Configs Schema
|
|
97
|
+
*/
|
|
98
|
+
exports.ModeConfigsSchema = zod_1.z.object({
|
|
99
|
+
credentials: exports.CredentialsConfigSchema.optional(),
|
|
100
|
+
oauth: exports.OAuthConfigSchema.optional(),
|
|
101
|
+
magicLink: exports.MagicLinkConfigSchema.optional(),
|
|
102
|
+
otp: exports.OTPConfigSchema.optional(),
|
|
103
|
+
qrCode: exports.QRCodeConfigSchema.optional(),
|
|
104
|
+
passkey: exports.PasskeyConfigSchema.optional(),
|
|
105
|
+
idv: exports.IDVConfigSchema.optional(),
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=modes.schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modes.schemas.js","sourceRoot":"","sources":["../../src/schemas/modes.schemas.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6BAAwB;AACxB,sDAAkD;AAElD;;GAEG;AACU,QAAA,cAAc,GAAG,OAAC,CAAC,IAAI,CAAC;IACnC,wBAAU,CAAC,YAAY;IACvB,wBAAU,CAAC,WAAW;IACtB,wBAAU,CAAC,KAAK;IAChB,wBAAU,CAAC,UAAU;IACrB,wBAAU,CAAC,GAAG;IACd,wBAAU,CAAC,OAAO;IAClB,wBAAU,CAAC,OAAO;IAClB,wBAAU,CAAC,GAAG;CACf,CAAC,CAAC;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C,CAAC,CAAC;AAIH;;GAEG;AACU,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,WAAW,EAAE,+BAAuB,CAAC,QAAQ,EAAE;IAC/C,KAAK,EAAE,yBAAiB,CAAC,QAAQ,EAAE;IACnC,SAAS,EAAE,6BAAqB,CAAC,QAAQ,EAAE;IAC3C,GAAG,EAAE,uBAAe,CAAC,QAAQ,EAAE;IAC/B,MAAM,EAAE,0BAAkB,CAAC,QAAQ,EAAE;IACrC,OAAO,EAAE,2BAAmB,CAAC,QAAQ,EAAE;IACvC,GAAG,EAAE,uBAAe,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML/JS Escape Utilities
|
|
3
|
+
*
|
|
4
|
+
* XSS prevention utilities for rendering user content safely.
|
|
5
|
+
*
|
|
6
|
+
* @module @kya-os/consent/security/escape
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Escape HTML special characters to prevent XSS
|
|
10
|
+
*
|
|
11
|
+
* Converts characters that have special meaning in HTML to their
|
|
12
|
+
* entity equivalents, making them safe to insert into HTML content.
|
|
13
|
+
*
|
|
14
|
+
* @param text - The text to escape
|
|
15
|
+
* @returns HTML-safe string
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* escapeHtml('<script>alert("xss")</script>')
|
|
20
|
+
* // Returns: '<script>alert("xss")</script>'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function escapeHtml(text: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Escape text for use in HTML attributes
|
|
26
|
+
*
|
|
27
|
+
* More comprehensive escaping than escapeHtml, including backticks
|
|
28
|
+
* and equals signs which can be dangerous in attribute contexts.
|
|
29
|
+
*
|
|
30
|
+
* @param value - The value to escape
|
|
31
|
+
* @returns Attribute-safe string
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* escapeAttr('value" onclick="alert(1)')
|
|
36
|
+
* // Returns: 'value" onclick="alert(1)'
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function escapeAttr(value: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Escape text for use in JavaScript strings
|
|
42
|
+
*
|
|
43
|
+
* Uses JSON.stringify to properly escape all special characters
|
|
44
|
+
* that could break out of a JavaScript string context.
|
|
45
|
+
*
|
|
46
|
+
* @param text - The text to escape
|
|
47
|
+
* @returns JS-safe string (without surrounding quotes)
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* escapeJs('hello\nworld')
|
|
52
|
+
* // Returns: '"hello\\nworld"' (with quotes from JSON.stringify)
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function escapeJs(text: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Escape text for use in JavaScript, returning value without quotes
|
|
58
|
+
*
|
|
59
|
+
* @param text - The text to escape
|
|
60
|
+
* @returns JS-safe string content (without surrounding quotes)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* escapeJsValue('hello\nworld')
|
|
65
|
+
* // Returns: 'hello\\nworld'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function escapeJsValue(text: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Escape URL for use in href or src attributes
|
|
71
|
+
*
|
|
72
|
+
* Only allows http, https, and mailto protocols. Returns empty
|
|
73
|
+
* string for dangerous protocols like javascript:.
|
|
74
|
+
*
|
|
75
|
+
* @param url - The URL to escape
|
|
76
|
+
* @returns Safe URL or empty string
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* escapeUrl('javascript:alert(1)')
|
|
81
|
+
* // Returns: ''
|
|
82
|
+
*
|
|
83
|
+
* escapeUrl('https://example.com/?q=test')
|
|
84
|
+
* // Returns: 'https://example.com/?q=test'
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function escapeUrl(url: string | undefined): string;
|
|
88
|
+
/**
|
|
89
|
+
* Create a safe HTML string from template literals
|
|
90
|
+
*
|
|
91
|
+
* Automatically escapes interpolated values while preserving
|
|
92
|
+
* the template structure.
|
|
93
|
+
*
|
|
94
|
+
* @param strings - Template literal strings
|
|
95
|
+
* @param values - Interpolated values to escape
|
|
96
|
+
* @returns Safe HTML string
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const userInput = '<script>alert("xss")</script>';
|
|
101
|
+
* const html = safeHtml`<div>${userInput}</div>`;
|
|
102
|
+
* // Returns: '<div><script>alert("xss")</script></div>'
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function safeHtml(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
106
|
+
/**
|
|
107
|
+
* Create a safe attribute value from template literals
|
|
108
|
+
*
|
|
109
|
+
* @param strings - Template literal strings
|
|
110
|
+
* @param values - Interpolated values to escape
|
|
111
|
+
* @returns Safe attribute string
|
|
112
|
+
*/
|
|
113
|
+
export declare function safeAttr(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
114
|
+
//# sourceMappingURL=escape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/security/escape.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAsBH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CA8BzD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,oBAAoB,EAC7B,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,oBAAoB,EAC7B,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,MAAM,CASR"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HTML/JS Escape Utilities
|
|
4
|
+
*
|
|
5
|
+
* XSS prevention utilities for rendering user content safely.
|
|
6
|
+
*
|
|
7
|
+
* @module @kya-os/consent/security/escape
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.escapeHtml = escapeHtml;
|
|
11
|
+
exports.escapeAttr = escapeAttr;
|
|
12
|
+
exports.escapeJs = escapeJs;
|
|
13
|
+
exports.escapeJsValue = escapeJsValue;
|
|
14
|
+
exports.escapeUrl = escapeUrl;
|
|
15
|
+
exports.safeHtml = safeHtml;
|
|
16
|
+
exports.safeAttr = safeAttr;
|
|
17
|
+
/**
|
|
18
|
+
* HTML entities to escape
|
|
19
|
+
*/
|
|
20
|
+
const HTML_ESCAPE_MAP = {
|
|
21
|
+
"&": "&",
|
|
22
|
+
"<": "<",
|
|
23
|
+
">": ">",
|
|
24
|
+
'"': """,
|
|
25
|
+
"'": "'",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Additional characters to escape in attributes
|
|
29
|
+
*/
|
|
30
|
+
const ATTR_ESCAPE_MAP = {
|
|
31
|
+
...HTML_ESCAPE_MAP,
|
|
32
|
+
"`": "`",
|
|
33
|
+
"=": "=",
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Escape HTML special characters to prevent XSS
|
|
37
|
+
*
|
|
38
|
+
* Converts characters that have special meaning in HTML to their
|
|
39
|
+
* entity equivalents, making them safe to insert into HTML content.
|
|
40
|
+
*
|
|
41
|
+
* @param text - The text to escape
|
|
42
|
+
* @returns HTML-safe string
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* escapeHtml('<script>alert("xss")</script>')
|
|
47
|
+
* // Returns: '<script>alert("xss")</script>'
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function escapeHtml(text) {
|
|
51
|
+
if (!text)
|
|
52
|
+
return "";
|
|
53
|
+
return text.replace(/[&<>"']/g, (char) => HTML_ESCAPE_MAP[char] ?? char);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Escape text for use in HTML attributes
|
|
57
|
+
*
|
|
58
|
+
* More comprehensive escaping than escapeHtml, including backticks
|
|
59
|
+
* and equals signs which can be dangerous in attribute contexts.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to escape
|
|
62
|
+
* @returns Attribute-safe string
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* escapeAttr('value" onclick="alert(1)')
|
|
67
|
+
* // Returns: 'value" onclick="alert(1)'
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
function escapeAttr(value) {
|
|
71
|
+
if (!value)
|
|
72
|
+
return "";
|
|
73
|
+
return value.replace(/[&<>"'`=]/g, (char) => ATTR_ESCAPE_MAP[char] ?? char);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Escape text for use in JavaScript strings
|
|
77
|
+
*
|
|
78
|
+
* Uses JSON.stringify to properly escape all special characters
|
|
79
|
+
* that could break out of a JavaScript string context.
|
|
80
|
+
*
|
|
81
|
+
* @param text - The text to escape
|
|
82
|
+
* @returns JS-safe string (without surrounding quotes)
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* escapeJs('hello\nworld')
|
|
87
|
+
* // Returns: '"hello\\nworld"' (with quotes from JSON.stringify)
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
function escapeJs(text) {
|
|
91
|
+
if (!text)
|
|
92
|
+
return '""';
|
|
93
|
+
return JSON.stringify(text);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Escape text for use in JavaScript, returning value without quotes
|
|
97
|
+
*
|
|
98
|
+
* @param text - The text to escape
|
|
99
|
+
* @returns JS-safe string content (without surrounding quotes)
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* escapeJsValue('hello\nworld')
|
|
104
|
+
* // Returns: 'hello\\nworld'
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
function escapeJsValue(text) {
|
|
108
|
+
if (!text)
|
|
109
|
+
return "";
|
|
110
|
+
// JSON.stringify adds quotes, remove them
|
|
111
|
+
const escaped = JSON.stringify(text);
|
|
112
|
+
return escaped.slice(1, -1);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Escape URL for use in href or src attributes
|
|
116
|
+
*
|
|
117
|
+
* Only allows http, https, and mailto protocols. Returns empty
|
|
118
|
+
* string for dangerous protocols like javascript:.
|
|
119
|
+
*
|
|
120
|
+
* @param url - The URL to escape
|
|
121
|
+
* @returns Safe URL or empty string
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* escapeUrl('javascript:alert(1)')
|
|
126
|
+
* // Returns: ''
|
|
127
|
+
*
|
|
128
|
+
* escapeUrl('https://example.com/?q=test')
|
|
129
|
+
* // Returns: 'https://example.com/?q=test'
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function escapeUrl(url) {
|
|
133
|
+
if (!url)
|
|
134
|
+
return "";
|
|
135
|
+
// Check for dangerous protocols
|
|
136
|
+
const lowerUrl = url.toLowerCase().trim();
|
|
137
|
+
if (lowerUrl.startsWith("javascript:") ||
|
|
138
|
+
lowerUrl.startsWith("data:") ||
|
|
139
|
+
lowerUrl.startsWith("vbscript:") ||
|
|
140
|
+
lowerUrl.startsWith("file:")) {
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
143
|
+
// Try to parse as URL to validate
|
|
144
|
+
try {
|
|
145
|
+
const parsed = new URL(url);
|
|
146
|
+
if (!["http:", "https:", "mailto:"].includes(parsed.protocol)) {
|
|
147
|
+
return "";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// If it's a relative URL, that's okay
|
|
152
|
+
if (!url.startsWith("/") && !url.startsWith("#") && !url.startsWith("?")) {
|
|
153
|
+
// Absolute URL that failed to parse - unsafe
|
|
154
|
+
return "";
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Escape any HTML characters in the URL (but not = or ` which are safe in URLs)
|
|
158
|
+
return escapeHtml(url);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a safe HTML string from template literals
|
|
162
|
+
*
|
|
163
|
+
* Automatically escapes interpolated values while preserving
|
|
164
|
+
* the template structure.
|
|
165
|
+
*
|
|
166
|
+
* @param strings - Template literal strings
|
|
167
|
+
* @param values - Interpolated values to escape
|
|
168
|
+
* @returns Safe HTML string
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const userInput = '<script>alert("xss")</script>';
|
|
173
|
+
* const html = safeHtml`<div>${userInput}</div>`;
|
|
174
|
+
* // Returns: '<div><script>alert("xss")</script></div>'
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
function safeHtml(strings, ...values) {
|
|
178
|
+
let result = strings[0] ?? "";
|
|
179
|
+
for (let i = 0; i < values.length; i++) {
|
|
180
|
+
const value = values[i];
|
|
181
|
+
const escaped = value === null || value === undefined ? "" : escapeHtml(String(value));
|
|
182
|
+
result += escaped + (strings[i + 1] ?? "");
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create a safe attribute value from template literals
|
|
188
|
+
*
|
|
189
|
+
* @param strings - Template literal strings
|
|
190
|
+
* @param values - Interpolated values to escape
|
|
191
|
+
* @returns Safe attribute string
|
|
192
|
+
*/
|
|
193
|
+
function safeAttr(strings, ...values) {
|
|
194
|
+
let result = strings[0] ?? "";
|
|
195
|
+
for (let i = 0; i < values.length; i++) {
|
|
196
|
+
const value = values[i];
|
|
197
|
+
const escaped = value === null || value === undefined ? "" : escapeAttr(String(value));
|
|
198
|
+
result += escaped + (strings[i + 1] ?? "");
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/security/escape.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAqCH,gCAGC;AAiBD,gCAGC;AAiBD,4BAGC;AAcD,sCAKC;AAoBD,8BA8BC;AAmBD,4BAYC;AASD,4BAYC;AAvMD;;GAEG;AACH,MAAM,eAAe,GAA2B;IAC9C,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,eAAe,GAA2B;IAC9C,GAAG,eAAe;IAClB,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;CACd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,OAA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AAQ,CACtB,OAA6B,EAC7B,GAAG,MAAiB;IAEpB,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,OAAO,GACX,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACzE,MAAM,IAAI,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Consent Security Utilities
|
|
4
|
+
*
|
|
5
|
+
* XSS prevention and input validation utilities.
|
|
6
|
+
*
|
|
7
|
+
* @module @kya-os/consent/security
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
__exportStar(require("./escape"), exports);
|
|
25
|
+
__exportStar(require("./validators"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,+CAA6B"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Validators
|
|
3
|
+
*
|
|
4
|
+
* Input validation utilities for secure rendering.
|
|
5
|
+
*
|
|
6
|
+
* @module @kya-os/consent/security/validators
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a string is a valid hex color
|
|
10
|
+
*
|
|
11
|
+
* Only accepts 6-digit hex colors with # prefix.
|
|
12
|
+
*
|
|
13
|
+
* @param color - Color string to validate
|
|
14
|
+
* @returns The color if valid, undefined otherwise
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* validateColor('#2563EB') // Returns '#2563EB'
|
|
19
|
+
* validateColor('2563EB') // Returns undefined
|
|
20
|
+
* validateColor('#fff') // Returns undefined (3-digit not allowed)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateColor(color: string | undefined): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Validate that a string is a valid URL
|
|
26
|
+
*
|
|
27
|
+
* Only accepts http and https protocols.
|
|
28
|
+
*
|
|
29
|
+
* @param url - URL string to validate
|
|
30
|
+
* @returns The URL if valid, undefined otherwise
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* validateUrl('https://example.com') // Returns 'https://example.com'
|
|
35
|
+
* validateUrl('javascript:alert(1)') // Returns undefined
|
|
36
|
+
* validateUrl('ftp://files.example.com') // Returns undefined
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateUrl(url: string | undefined): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Validate that a string is a valid email address
|
|
42
|
+
*
|
|
43
|
+
* Uses a simple but effective email pattern.
|
|
44
|
+
*
|
|
45
|
+
* @param email - Email string to validate
|
|
46
|
+
* @returns The email if valid, undefined otherwise
|
|
47
|
+
*/
|
|
48
|
+
export declare function validateEmail(email: string | undefined): string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Validate that a string is a valid DID
|
|
51
|
+
*
|
|
52
|
+
* @param did - DID string to validate
|
|
53
|
+
* @returns The DID if valid, undefined otherwise
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateDid(did: string | undefined): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Validate that a string contains no control characters
|
|
58
|
+
*
|
|
59
|
+
* @param text - Text to validate
|
|
60
|
+
* @returns The text if valid, undefined otherwise
|
|
61
|
+
*/
|
|
62
|
+
export declare function validateNoControlChars(text: string | undefined): string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Validate and sanitize a string for display
|
|
65
|
+
*
|
|
66
|
+
* Removes control characters and trims whitespace.
|
|
67
|
+
*
|
|
68
|
+
* @param text - Text to sanitize
|
|
69
|
+
* @param maxLength - Maximum allowed length
|
|
70
|
+
* @returns Sanitized text or undefined if invalid
|
|
71
|
+
*/
|
|
72
|
+
export declare function sanitizeDisplayText(text: string | undefined, maxLength?: number): string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Validate that a string is alphanumeric with underscores only
|
|
75
|
+
*
|
|
76
|
+
* Useful for field names and identifiers.
|
|
77
|
+
*
|
|
78
|
+
* @param text - Text to validate
|
|
79
|
+
* @returns The text if valid, undefined otherwise
|
|
80
|
+
*/
|
|
81
|
+
export declare function validateIdentifier(text: string | undefined): string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Check if a value is a safe integer within range
|
|
84
|
+
*
|
|
85
|
+
* @param value - Value to check
|
|
86
|
+
* @param min - Minimum value (inclusive)
|
|
87
|
+
* @param max - Maximum value (inclusive)
|
|
88
|
+
* @returns True if valid
|
|
89
|
+
*/
|
|
90
|
+
export declare function isValidInteger(value: unknown, min?: number, max?: number): value is number;
|
|
91
|
+
/**
|
|
92
|
+
* Validate a CSRF token format
|
|
93
|
+
*
|
|
94
|
+
* @param token - Token to validate
|
|
95
|
+
* @returns The token if valid, undefined otherwise
|
|
96
|
+
*/
|
|
97
|
+
export declare function validateCSRFToken(token: string | undefined): string | undefined;
|
|
98
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/security/validators.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAS3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAavE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAU3E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CA0BvE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAWnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,SAAS,SAAM,GACd,MAAM,GAAG,SAAS,CAcpB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAQ/E;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,GAAG,SAA0B,EAC7B,GAAG,SAA0B,GAC5B,KAAK,IAAI,MAAM,CAKjB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAc/E"}
|