@nice2dev/ui-security 1.0.10

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.
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @file Security Automation CI/CD Integration
3
+ * @description Scripts for SAST, SCA, secret scanning in CI/CD
4
+ */
5
+ export interface SASTConfig {
6
+ /** Source directories to scan */
7
+ sourceDirectories: string[];
8
+ /** File extensions to include */
9
+ extensions: string[];
10
+ /** Exclude patterns */
11
+ exclude?: string[];
12
+ /** Severity threshold to fail build */
13
+ failOnSeverity?: 'critical' | 'high' | 'medium' | 'low';
14
+ /** Output format */
15
+ outputFormat?: 'json' | 'sarif' | 'html';
16
+ /** Output file path */
17
+ outputPath?: string;
18
+ }
19
+ export interface SASTFinding {
20
+ id: string;
21
+ severity: 'critical' | 'high' | 'medium' | 'low' | 'info';
22
+ title: string;
23
+ description: string;
24
+ file: string;
25
+ line: number;
26
+ column?: number;
27
+ code?: string;
28
+ cweId?: string;
29
+ recommendation: string;
30
+ }
31
+ /**
32
+ * Common security patterns to detect
33
+ */
34
+ export declare const SECURITY_PATTERNS: {
35
+ hardcodedSecrets: {
36
+ pattern: RegExp;
37
+ name: string;
38
+ }[];
39
+ sqlInjection: {
40
+ pattern: RegExp;
41
+ name: string;
42
+ }[];
43
+ xss: {
44
+ pattern: RegExp;
45
+ name: string;
46
+ }[];
47
+ insecureFunctions: {
48
+ pattern: RegExp;
49
+ name: string;
50
+ }[];
51
+ infoExposure: {
52
+ pattern: RegExp;
53
+ name: string;
54
+ }[];
55
+ };
56
+ /**
57
+ * Generate SAST configuration for CI
58
+ */
59
+ export declare function generateSASTConfig(): string;
60
+ export interface SCAConfig {
61
+ /** Package manager */
62
+ packageManager: 'npm' | 'pnpm' | 'yarn';
63
+ /** Severity threshold */
64
+ failOnSeverity?: 'critical' | 'high' | 'moderate' | 'low';
65
+ /** Ignore dev dependencies */
66
+ ignoreDevDependencies?: boolean;
67
+ /** Allowed licenses */
68
+ allowedLicenses?: string[];
69
+ /** Blocked licenses */
70
+ blockedLicenses?: string[];
71
+ }
72
+ export interface SCAVulnerability {
73
+ name: string;
74
+ version: string;
75
+ severity: 'critical' | 'high' | 'moderate' | 'low';
76
+ vulnerableVersions: string;
77
+ patchedVersions?: string;
78
+ cve?: string;
79
+ ghsaId?: string;
80
+ title: string;
81
+ url: string;
82
+ }
83
+ /**
84
+ * Generate SCA configuration for CI
85
+ */
86
+ export declare function generateSCAConfig(): string;
87
+ export interface SecretPattern {
88
+ name: string;
89
+ pattern: RegExp;
90
+ severity: 'critical' | 'high' | 'medium';
91
+ }
92
+ /**
93
+ * Common secret patterns
94
+ */
95
+ export declare const SECRET_PATTERNS: SecretPattern[];
96
+ /**
97
+ * Generate secret scanning pre-commit hook
98
+ */
99
+ export declare function generatePreCommitHook(): string;
100
+ /**
101
+ * Generate GitHub Actions secret scanning workflow
102
+ */
103
+ export declare function generateSecretScanningConfig(): string;
104
+ export interface SecurityRelease {
105
+ version: string;
106
+ date: string;
107
+ cves: string[];
108
+ severity: 'critical' | 'high' | 'medium' | 'low';
109
+ description: string;
110
+ affectedVersions: string;
111
+ fixedIn: string;
112
+ acknowledgments?: string[];
113
+ }
114
+ /**
115
+ * Generate security advisory template
116
+ */
117
+ export declare function generateSecurityAdvisory(release: SecurityRelease): string;
118
+ /**
119
+ * Generate SECURITY.md template
120
+ */
121
+ export declare function generateSecurityMd(): string;
@@ -0,0 +1,192 @@
1
+ /**
2
+ * @file Nice2Dev Security Utilities
3
+ * @description Content Security Policy, XSS prevention, CSRF protection
4
+ * @packageDocumentation
5
+ */
6
+ export interface CSPDirectives {
7
+ defaultSrc?: string[];
8
+ scriptSrc?: string[];
9
+ styleSrc?: string[];
10
+ imgSrc?: string[];
11
+ fontSrc?: string[];
12
+ connectSrc?: string[];
13
+ frameSrc?: string[];
14
+ objectSrc?: string[];
15
+ mediaSrc?: string[];
16
+ workerSrc?: string[];
17
+ childSrc?: string[];
18
+ formAction?: string[];
19
+ frameAncestors?: string[];
20
+ baseUri?: string[];
21
+ reportUri?: string;
22
+ reportTo?: string;
23
+ upgradeInsecureRequests?: boolean;
24
+ blockAllMixedContent?: boolean;
25
+ }
26
+ export interface CSPConfig {
27
+ /** Base directives */
28
+ directives: CSPDirectives;
29
+ /** Report-only mode (doesn't block, only reports) */
30
+ reportOnly?: boolean;
31
+ /** Nonce for inline scripts/styles */
32
+ nonce?: string;
33
+ }
34
+ /**
35
+ * Generate CSP header value from config
36
+ */
37
+ export declare function generateCSPHeader(config: CSPConfig): string;
38
+ /**
39
+ * Get recommended CSP for Nice2Dev apps
40
+ */
41
+ export declare function getRecommendedCSP(options?: {
42
+ apiDomain?: string;
43
+ cdnDomain?: string;
44
+ reportUri?: string;
45
+ }): CSPDirectives;
46
+ /**
47
+ * Generate random nonce for CSP
48
+ */
49
+ export declare function generateNonce(): string;
50
+ /**
51
+ * Escape HTML to prevent XSS
52
+ */
53
+ export declare function escapeHtml(input: string): string;
54
+ /**
55
+ * Sanitize user input for safe display
56
+ */
57
+ export declare function sanitizeInput(input: string, options?: {
58
+ allowedTags?: string[];
59
+ allowedAttributes?: string[];
60
+ maxLength?: number;
61
+ }): string;
62
+ /**
63
+ * Validate and sanitize URL
64
+ */
65
+ export declare function sanitizeUrl(url: string): string | null;
66
+ /**
67
+ * Sanitize SVG content to prevent XSS
68
+ */
69
+ export declare function sanitizeSvg(svg: string): string;
70
+ /**
71
+ * Create safe HTML for dangerouslySetInnerHTML
72
+ */
73
+ export declare function createSafeHtml(html: string, options?: {
74
+ allowedTags?: string[];
75
+ allowedAttributes?: string[];
76
+ }): {
77
+ __html: string;
78
+ };
79
+ export interface CSRFConfig {
80
+ /** Token header name */
81
+ headerName?: string;
82
+ /** Token cookie name */
83
+ cookieName?: string;
84
+ /** Token form field name */
85
+ fieldName?: string;
86
+ }
87
+ /**
88
+ * Generate CSRF token
89
+ */
90
+ export declare function generateCSRFToken(): string;
91
+ /**
92
+ * Get CSRF token from cookie
93
+ */
94
+ export declare function getCSRFTokenFromCookie(cookieName?: string | undefined): string | null;
95
+ /**
96
+ * Create fetch wrapper with CSRF token
97
+ */
98
+ export declare function createCSRFFetch(config?: CSRFConfig): (url: string, options?: RequestInit) => Promise<Response>;
99
+ /**
100
+ * Hook for CSRF-protected forms
101
+ */
102
+ export declare function useCSRFToken(config?: CSRFConfig): {
103
+ token: string | null;
104
+ inputProps: {
105
+ type: "hidden";
106
+ name: string | undefined;
107
+ value: string;
108
+ };
109
+ headerName: string | undefined;
110
+ };
111
+ export interface RateLimitConfig {
112
+ /** Max requests */
113
+ maxRequests: number;
114
+ /** Time window in ms */
115
+ windowMs: number;
116
+ /** Key generator (e.g., by endpoint) */
117
+ keyGenerator?: (request: {
118
+ url: string;
119
+ method?: string;
120
+ }) => string;
121
+ }
122
+ /**
123
+ * Client-side rate limiter
124
+ */
125
+ export declare function createRateLimiter(config: RateLimitConfig): {
126
+ checkLimit: (request: {
127
+ url: string;
128
+ method?: string;
129
+ }) => {
130
+ allowed: boolean;
131
+ remaining: number;
132
+ resetAt: number;
133
+ };
134
+ reset: (key?: string) => void;
135
+ };
136
+ /**
137
+ * Hook for rate limiting API calls
138
+ */
139
+ export declare function useRateLimiter(config: RateLimitConfig): {
140
+ checkAndFetch: (url: string, options?: RequestInit) => Promise<Response>;
141
+ checkLimit: (request: {
142
+ url: string;
143
+ method?: string;
144
+ }) => {
145
+ allowed: boolean;
146
+ remaining: number;
147
+ resetAt: number;
148
+ };
149
+ reset: (key?: string) => void;
150
+ };
151
+ export interface FileUploadConfig {
152
+ /** Allowed MIME types */
153
+ allowedTypes?: string[];
154
+ /** Max file size in bytes */
155
+ maxSize?: number;
156
+ /** Max total size for multiple files */
157
+ maxTotalSize?: number;
158
+ /** Max number of files */
159
+ maxFiles?: number;
160
+ /** Scan for viruses (requires backend integration) */
161
+ virusScan?: boolean;
162
+ /** Virus scan endpoint */
163
+ virusScanEndpoint?: string;
164
+ }
165
+ export interface FileValidationResult {
166
+ valid: boolean;
167
+ errors: string[];
168
+ file?: File;
169
+ }
170
+ /**
171
+ * Validate file for upload
172
+ */
173
+ export declare function validateFile(file: File, config: FileUploadConfig): FileValidationResult;
174
+ /**
175
+ * Validate multiple files
176
+ */
177
+ export declare function validateFiles(files: File[], config: FileUploadConfig): {
178
+ valid: boolean;
179
+ errors: string[];
180
+ validFiles: File[];
181
+ invalidFiles: {
182
+ file: File;
183
+ errors: string[];
184
+ }[];
185
+ };
186
+ /**
187
+ * Scan file for viruses (requires backend)
188
+ */
189
+ export declare function scanFileForViruses(file: File, endpoint: string): Promise<{
190
+ clean: boolean;
191
+ threat?: string;
192
+ }>;
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@nice2dev/ui-security",
3
+ "version": "1.0.10",
4
+ "description": "Nice2Dev Security — Biometric authentication (fingerprint, iris, face), security keypads, PIN entry, pattern lock, liveness detection for React. Frontend-first with optional backend verification.",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./style.css": "./dist/style.css"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "LICENSE",
20
+ "CHANGELOG.md",
21
+ "README.md"
22
+ ],
23
+ "sideEffects": [
24
+ "*.css"
25
+ ],
26
+ "scripts": {
27
+ "dev": "vite",
28
+ "build": "tsc -p tsconfig.build.json && vite build",
29
+ "typecheck": "tsc --noEmit",
30
+ "test": "vitest run --config vitest.config.ts",
31
+ "test:watch": "vitest --config vitest.config.ts",
32
+ "test:coverage": "vitest run --config vitest.config.ts --coverage",
33
+ "clean": "rimraf dist",
34
+ "prepublishOnly": "npm run build"
35
+ },
36
+ "keywords": [
37
+ "react",
38
+ "security",
39
+ "biometric",
40
+ "fingerprint",
41
+ "iris",
42
+ "face-recognition",
43
+ "webauthn",
44
+ "fido2",
45
+ "passkey",
46
+ "pin",
47
+ "pattern-lock",
48
+ "keypad",
49
+ "liveness-detection",
50
+ "mfa",
51
+ "authentication",
52
+ "nicetodev"
53
+ ],
54
+ "author": "NiceToDev <contact@nicetodev.com>",
55
+ "license": "SEE LICENSE IN LICENSE",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/NiceToDev/NiceToDev.UI.git",
59
+ "directory": "packages/ui-security"
60
+ },
61
+ "homepage": "https://github.com/NiceToDev/NiceToDev.UI#readme",
62
+ "bugs": {
63
+ "url": "https://github.com/NiceToDev/NiceToDev.UI/issues"
64
+ },
65
+ "peerDependencies": {
66
+ "react": ">=17.0.0",
67
+ "react-dom": ">=17.0.0"
68
+ },
69
+ "devDependencies": {
70
+ "@testing-library/jest-dom": "^6.9.1",
71
+ "@testing-library/react": "^14.0.0",
72
+ "@types/react": "^18.2.0",
73
+ "@types/react-dom": "^18.2.0",
74
+ "@vitejs/plugin-react": "^4.2.0",
75
+ "react": "^18.2.0",
76
+ "react-dom": "^18.2.0",
77
+ "typescript": "^5.3.0",
78
+ "vite": "^6.2.0",
79
+ "vite-plugin-dts": "^4.5.0",
80
+ "vitest": "^4.1.0"
81
+ }
82
+ }