@utilarium/cardigantime 0.0.24-dev.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/LICENSE +65 -0
- package/README.md +398 -0
- package/dist/cardigantime.cjs +2169 -0
- package/dist/cardigantime.cjs.map +1 -0
- package/dist/cardigantime.d.ts +92 -0
- package/dist/cardigantime.js +198 -0
- package/dist/cardigantime.js.map +1 -0
- package/dist/config/executable-security.d.ts +32 -0
- package/dist/config/format-detector.d.ts +59 -0
- package/dist/configure.d.ts +55 -0
- package/dist/configure.js +125 -0
- package/dist/configure.js.map +1 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.js +38 -0
- package/dist/constants.js.map +1 -0
- package/dist/discovery/discoverer.d.ts +62 -0
- package/dist/discovery/hierarchical-modes.d.ts +64 -0
- package/dist/discovery/index.d.ts +15 -0
- package/dist/discovery/patterns.d.ts +77 -0
- package/dist/discovery/root-detection.d.ts +100 -0
- package/dist/discovery/traversal-security.d.ts +106 -0
- package/dist/env/errors.d.ts +18 -0
- package/dist/env/index.d.ts +7 -0
- package/dist/env/naming.d.ts +38 -0
- package/dist/env/parser.d.ts +61 -0
- package/dist/env/reader.d.ts +45 -0
- package/dist/env/resolver.d.ts +25 -0
- package/dist/env/schema-utils.d.ts +33 -0
- package/dist/env/types.d.ts +43 -0
- package/dist/error/ArgumentError.d.ts +31 -0
- package/dist/error/ArgumentError.js +48 -0
- package/dist/error/ArgumentError.js.map +1 -0
- package/dist/error/ConfigParseError.d.ts +26 -0
- package/dist/error/ConfigurationError.d.ts +21 -0
- package/dist/error/ConfigurationError.js +46 -0
- package/dist/error/ConfigurationError.js.map +1 -0
- package/dist/error/FileSystemError.d.ts +30 -0
- package/dist/error/FileSystemError.js +58 -0
- package/dist/error/FileSystemError.js.map +1 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/mcp/discovery.d.ts +105 -0
- package/dist/mcp/errors.d.ts +75 -0
- package/dist/mcp/index.d.ts +22 -0
- package/dist/mcp/integration.d.ts +184 -0
- package/dist/mcp/parser.d.ts +141 -0
- package/dist/mcp/resolver.d.ts +165 -0
- package/dist/mcp/tools/check-config-types.d.ts +208 -0
- package/dist/mcp/tools/check-config.d.ts +85 -0
- package/dist/mcp/tools/index.d.ts +12 -0
- package/dist/mcp/types.d.ts +210 -0
- package/dist/parsers/index.d.ts +25 -0
- package/dist/parsers/javascript-parser.d.ts +12 -0
- package/dist/parsers/json-parser.d.ts +6 -0
- package/dist/parsers/typescript-parser.d.ts +15 -0
- package/dist/parsers/yaml-parser.d.ts +6 -0
- package/dist/read.d.ts +56 -0
- package/dist/read.js +653 -0
- package/dist/read.js.map +1 -0
- package/dist/security/audit-logger.d.ts +135 -0
- package/dist/security/cli-validator.d.ts +73 -0
- package/dist/security/config-validator.d.ts +95 -0
- package/dist/security/defaults.d.ts +17 -0
- package/dist/security/index.d.ts +14 -0
- package/dist/security/numeric-guard.d.ts +111 -0
- package/dist/security/path-guard.d.ts +53 -0
- package/dist/security/profiles.d.ts +127 -0
- package/dist/security/security-validator.d.ts +109 -0
- package/dist/security/string-guard.d.ts +92 -0
- package/dist/security/types.d.ts +126 -0
- package/dist/security/zod-secure-enum.d.ts +20 -0
- package/dist/security/zod-secure-number.d.ts +39 -0
- package/dist/security/zod-secure-path.d.ts +24 -0
- package/dist/security/zod-secure-string.d.ts +38 -0
- package/dist/types.d.ts +584 -0
- package/dist/types.js +56 -0
- package/dist/types.js.map +1 -0
- package/dist/util/hierarchical.d.ts +136 -0
- package/dist/util/hierarchical.js +436 -0
- package/dist/util/hierarchical.js.map +1 -0
- package/dist/util/schema-defaults.d.ts +80 -0
- package/dist/util/schema-defaults.js +118 -0
- package/dist/util/schema-defaults.js.map +1 -0
- package/dist/util/storage.d.ts +31 -0
- package/dist/util/storage.js +154 -0
- package/dist/util/storage.js.map +1 -0
- package/dist/validate.d.ts +113 -0
- package/dist/validate.js +260 -0
- package/dist/validate.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { SecurityValidationConfig, SecurityProfile } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Profile presets for common scenarios.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SECURITY_PROFILES: Record<SecurityProfile, SecurityValidationConfig>;
|
|
6
|
+
/**
|
|
7
|
+
* Environment-based profile detection.
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectProfile(): SecurityProfile;
|
|
10
|
+
/**
|
|
11
|
+
* Get security configuration for a profile.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getProfileConfig(profile: SecurityProfile): SecurityValidationConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Profile builder for custom configurations.
|
|
16
|
+
*/
|
|
17
|
+
export declare class SecurityProfileBuilder {
|
|
18
|
+
private config;
|
|
19
|
+
constructor(baseProfile?: 'development' | 'production');
|
|
20
|
+
/**
|
|
21
|
+
* Enable fail-fast mode (throw on first error).
|
|
22
|
+
*/
|
|
23
|
+
failFast(enabled?: boolean): this;
|
|
24
|
+
/**
|
|
25
|
+
* Enable audit logging.
|
|
26
|
+
*/
|
|
27
|
+
withAuditLogging(enabled?: boolean): this;
|
|
28
|
+
/**
|
|
29
|
+
* Set path security options.
|
|
30
|
+
*/
|
|
31
|
+
withPathSecurity(options: Partial<SecurityValidationConfig['paths']>): this;
|
|
32
|
+
/**
|
|
33
|
+
* Set numeric security options.
|
|
34
|
+
*/
|
|
35
|
+
withNumericSecurity(options: Partial<SecurityValidationConfig['numbers']>): this;
|
|
36
|
+
/**
|
|
37
|
+
* Set string security options.
|
|
38
|
+
*/
|
|
39
|
+
withStringSecurity(options: Partial<SecurityValidationConfig['strings']>): this;
|
|
40
|
+
/**
|
|
41
|
+
* Restrict paths to specific base directories.
|
|
42
|
+
*/
|
|
43
|
+
restrictPathsTo(directories: string[]): this;
|
|
44
|
+
/**
|
|
45
|
+
* Allow only specific file extensions.
|
|
46
|
+
*/
|
|
47
|
+
allowExtensions(extensions: string[]): this;
|
|
48
|
+
/**
|
|
49
|
+
* Require explicit numeric bounds.
|
|
50
|
+
*/
|
|
51
|
+
requireNumericBounds(required?: boolean): this;
|
|
52
|
+
/**
|
|
53
|
+
* Set maximum string length.
|
|
54
|
+
*/
|
|
55
|
+
maxStringLength(length: number): this;
|
|
56
|
+
/**
|
|
57
|
+
* Create production-like profile with specific overrides.
|
|
58
|
+
*/
|
|
59
|
+
productionLike(overrides?: Partial<SecurityValidationConfig>): this;
|
|
60
|
+
/**
|
|
61
|
+
* Build the final configuration.
|
|
62
|
+
*/
|
|
63
|
+
build(): SecurityValidationConfig;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a custom security profile.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createProfile(base?: 'development' | 'production'): SecurityProfileBuilder;
|
|
69
|
+
/**
|
|
70
|
+
* Preset profiles for common scenarios.
|
|
71
|
+
*/
|
|
72
|
+
export declare const presets: {
|
|
73
|
+
/**
|
|
74
|
+
* Local development with warnings only.
|
|
75
|
+
*/
|
|
76
|
+
localDevelopment: () => SecurityValidationConfig;
|
|
77
|
+
/**
|
|
78
|
+
* CI/CD testing with strict validation but detailed errors.
|
|
79
|
+
*/
|
|
80
|
+
testing: () => SecurityValidationConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Production deployment with maximum security.
|
|
83
|
+
*/
|
|
84
|
+
productionDeployment: () => SecurityValidationConfig;
|
|
85
|
+
/**
|
|
86
|
+
* Library usage (embedded in other applications).
|
|
87
|
+
*/
|
|
88
|
+
libraryMode: () => SecurityValidationConfig;
|
|
89
|
+
/**
|
|
90
|
+
* Config file only (no CLI, just validating config files).
|
|
91
|
+
*/
|
|
92
|
+
configFileOnly: () => SecurityValidationConfig;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Runtime profile switching support.
|
|
96
|
+
*/
|
|
97
|
+
export declare class ProfileManager {
|
|
98
|
+
private currentProfile;
|
|
99
|
+
private currentConfig;
|
|
100
|
+
private listeners;
|
|
101
|
+
constructor(initialProfile?: SecurityProfile);
|
|
102
|
+
/**
|
|
103
|
+
* Get current profile.
|
|
104
|
+
*/
|
|
105
|
+
getProfile(): SecurityProfile;
|
|
106
|
+
/**
|
|
107
|
+
* Get current configuration.
|
|
108
|
+
*/
|
|
109
|
+
getConfig(): SecurityValidationConfig;
|
|
110
|
+
/**
|
|
111
|
+
* Switch to a different profile.
|
|
112
|
+
*/
|
|
113
|
+
switchProfile(profile: SecurityProfile): void;
|
|
114
|
+
/**
|
|
115
|
+
* Apply a custom configuration.
|
|
116
|
+
*/
|
|
117
|
+
applyCustomConfig(config: SecurityValidationConfig): void;
|
|
118
|
+
/**
|
|
119
|
+
* Subscribe to profile changes.
|
|
120
|
+
*/
|
|
121
|
+
onProfileChange(listener: (profile: SecurityProfile, config: SecurityValidationConfig) => void): () => void;
|
|
122
|
+
private notifyListeners;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the global profile manager.
|
|
126
|
+
*/
|
|
127
|
+
export declare function getProfileManager(): ProfileManager;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ConfigValueSource } from './config-validator';
|
|
3
|
+
import { SecurityValidationConfig, SecurityValidationResult, SecurityValidationError, SecurityProfile } from './types';
|
|
4
|
+
import { Logger } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Aggregated validation result from all sources.
|
|
7
|
+
*/
|
|
8
|
+
export interface AggregatedValidationResult {
|
|
9
|
+
/** Overall validation status */
|
|
10
|
+
valid: boolean;
|
|
11
|
+
/** All errors from all sources */
|
|
12
|
+
errors: SecurityValidationError[];
|
|
13
|
+
/** All warnings from all sources */
|
|
14
|
+
warnings: SecurityValidationResult['warnings'];
|
|
15
|
+
/** Results by source */
|
|
16
|
+
bySource: {
|
|
17
|
+
cli?: SecurityValidationResult;
|
|
18
|
+
config?: SecurityValidationResult;
|
|
19
|
+
defaults?: SecurityValidationResult;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* SecurityValidator provides unified security validation across all input sources.
|
|
24
|
+
*/
|
|
25
|
+
export declare class SecurityValidator {
|
|
26
|
+
private config;
|
|
27
|
+
private cliValidator;
|
|
28
|
+
private configValidator;
|
|
29
|
+
private pathGuard;
|
|
30
|
+
private numericGuard;
|
|
31
|
+
private stringGuard;
|
|
32
|
+
private logger?;
|
|
33
|
+
private schemaRegistered;
|
|
34
|
+
constructor(config?: Partial<SecurityValidationConfig>, logger?: Logger);
|
|
35
|
+
/**
|
|
36
|
+
* Register a Zod schema for validation.
|
|
37
|
+
* Extracts security metadata and configures both CLI and config validators.
|
|
38
|
+
*/
|
|
39
|
+
registerSchema<T extends z.ZodRawShape>(schema: z.ZodObject<T>): this;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a schema has been registered.
|
|
42
|
+
*/
|
|
43
|
+
hasSchema(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Validate CLI arguments.
|
|
46
|
+
*/
|
|
47
|
+
validateCLI(args: Record<string, unknown>): SecurityValidationResult;
|
|
48
|
+
/**
|
|
49
|
+
* Validate configuration file content.
|
|
50
|
+
*/
|
|
51
|
+
validateConfig(config: Record<string, unknown>, sources?: Map<string, ConfigValueSource>): SecurityValidationResult;
|
|
52
|
+
/**
|
|
53
|
+
* Validate a single config file before merging.
|
|
54
|
+
*/
|
|
55
|
+
validateConfigFile(content: Record<string, unknown>, filePath: string, level?: number): SecurityValidationResult;
|
|
56
|
+
/**
|
|
57
|
+
* Validate the merged configuration (CLI + config file + defaults).
|
|
58
|
+
* This is the main entry point for validation after all merging is complete.
|
|
59
|
+
*/
|
|
60
|
+
validateMerged(merged: Record<string, unknown>, cliArgs: Record<string, unknown>, configValues: Record<string, unknown>, configSources?: Map<string, ConfigValueSource>): AggregatedValidationResult;
|
|
61
|
+
/**
|
|
62
|
+
* Validate a single value (for ad-hoc validation).
|
|
63
|
+
*/
|
|
64
|
+
validateValue(value: unknown, type: 'path' | 'number' | 'string', options?: {
|
|
65
|
+
fieldName?: string;
|
|
66
|
+
bounds?: {
|
|
67
|
+
min: number;
|
|
68
|
+
max: number;
|
|
69
|
+
integer?: boolean;
|
|
70
|
+
};
|
|
71
|
+
pattern?: RegExp;
|
|
72
|
+
}): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current security profile.
|
|
75
|
+
*/
|
|
76
|
+
getProfile(): SecurityProfile;
|
|
77
|
+
/**
|
|
78
|
+
* Check if security validation should fail on errors.
|
|
79
|
+
*/
|
|
80
|
+
shouldFailOnError(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Perform cross-source validation (detect conflicts, suspicious patterns).
|
|
83
|
+
*/
|
|
84
|
+
private validateCrossSources;
|
|
85
|
+
/**
|
|
86
|
+
* Check for suspicious patterns in configuration.
|
|
87
|
+
*/
|
|
88
|
+
private checkSuspiciousPatterns;
|
|
89
|
+
/**
|
|
90
|
+
* Walk an object recursively.
|
|
91
|
+
*/
|
|
92
|
+
private walkObject;
|
|
93
|
+
/**
|
|
94
|
+
* Log validation result.
|
|
95
|
+
*/
|
|
96
|
+
private logResult;
|
|
97
|
+
/**
|
|
98
|
+
* Log aggregated validation result.
|
|
99
|
+
*/
|
|
100
|
+
private logAggregatedResult;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a security validator.
|
|
104
|
+
*/
|
|
105
|
+
export declare function createSecurityValidator(config?: Partial<SecurityValidationConfig>, logger?: Logger): SecurityValidator;
|
|
106
|
+
/**
|
|
107
|
+
* Create a security validator for a specific profile.
|
|
108
|
+
*/
|
|
109
|
+
export declare function createSecurityValidatorForProfile(profile: 'development' | 'production', logger?: Logger): SecurityValidator;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { StringSecurityOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Common patterns for security-sensitive strings.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SAFE_PATTERNS: {
|
|
6
|
+
/** Model names: alphanumeric with hyphens, dots, colons, slashes */
|
|
7
|
+
readonly modelName: RegExp;
|
|
8
|
+
/** Identifiers: alphanumeric with underscores */
|
|
9
|
+
readonly identifier: RegExp;
|
|
10
|
+
/** Environment variable names */
|
|
11
|
+
readonly envVar: RegExp;
|
|
12
|
+
/** Slugs: lowercase alphanumeric with hyphens */
|
|
13
|
+
readonly slug: RegExp;
|
|
14
|
+
/** Semantic version */
|
|
15
|
+
readonly semver: RegExp;
|
|
16
|
+
/** Safe filename (no path separators) */
|
|
17
|
+
readonly filename: RegExp;
|
|
18
|
+
/** Email (basic validation) */
|
|
19
|
+
readonly email: RegExp;
|
|
20
|
+
/** URL (http/https only) */
|
|
21
|
+
readonly httpUrl: RegExp;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* StringGuard provides secure string validation.
|
|
25
|
+
*/
|
|
26
|
+
export declare class StringGuard {
|
|
27
|
+
private options;
|
|
28
|
+
constructor(options?: Partial<StringSecurityOptions>);
|
|
29
|
+
/**
|
|
30
|
+
* Validate a string value against security constraints.
|
|
31
|
+
*
|
|
32
|
+
* @param value - The string to validate
|
|
33
|
+
* @param constraints - Validation constraints
|
|
34
|
+
* @param fieldName - Field name for error messages
|
|
35
|
+
* @returns The validated string
|
|
36
|
+
* @throws Error if validation fails
|
|
37
|
+
*/
|
|
38
|
+
validate(value: unknown, constraints?: {
|
|
39
|
+
minLength?: number;
|
|
40
|
+
maxLength?: number;
|
|
41
|
+
pattern?: RegExp;
|
|
42
|
+
patternName?: string;
|
|
43
|
+
allowedValues?: string[];
|
|
44
|
+
blockShellMeta?: boolean;
|
|
45
|
+
trim?: boolean;
|
|
46
|
+
}, fieldName?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Validate using a predefined safe pattern.
|
|
49
|
+
*/
|
|
50
|
+
validatePattern(value: unknown, patternName: keyof typeof SAFE_PATTERNS, fieldName?: string, additionalConstraints?: {
|
|
51
|
+
minLength?: number;
|
|
52
|
+
maxLength?: number;
|
|
53
|
+
}): string;
|
|
54
|
+
/**
|
|
55
|
+
* Validate a model name (e.g., "gpt-4o", "claude-3-opus-20240229").
|
|
56
|
+
*/
|
|
57
|
+
validateModelName(value: unknown, fieldName?: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Validate an identifier (variable name, etc.).
|
|
60
|
+
*/
|
|
61
|
+
validateIdentifier(value: unknown, fieldName?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Validate a filename (no path separators).
|
|
64
|
+
*/
|
|
65
|
+
validateFilename(value: unknown, fieldName?: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Validate an enum-like string value.
|
|
68
|
+
*/
|
|
69
|
+
validateEnum<T extends string>(value: unknown, allowedValues: readonly T[], fieldName: string, options?: {
|
|
70
|
+
caseSensitive?: boolean;
|
|
71
|
+
}): T;
|
|
72
|
+
/**
|
|
73
|
+
* Sanitize a string by removing dangerous characters (for logging, etc.).
|
|
74
|
+
*/
|
|
75
|
+
sanitize(value: string, maxLength?: number): string;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a string appears to contain injection attempts.
|
|
78
|
+
*/
|
|
79
|
+
detectInjection(value: string): {
|
|
80
|
+
suspicious: boolean;
|
|
81
|
+
reason?: string;
|
|
82
|
+
};
|
|
83
|
+
private createError;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get the default StringGuard instance.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getStringGuard(): StringGuard;
|
|
89
|
+
/**
|
|
90
|
+
* Create a new StringGuard with custom options.
|
|
91
|
+
*/
|
|
92
|
+
export declare function createStringGuard(options: Partial<StringSecurityOptions>): StringGuard;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security profile levels that determine validation strictness.
|
|
3
|
+
*/
|
|
4
|
+
export type SecurityProfile = 'development' | 'production' | 'custom';
|
|
5
|
+
/**
|
|
6
|
+
* Path security configuration options.
|
|
7
|
+
*/
|
|
8
|
+
export interface PathSecurityOptions {
|
|
9
|
+
/** Allowed base directories for path resolution */
|
|
10
|
+
allowedBaseDirs?: string[];
|
|
11
|
+
/** Maximum path length in characters */
|
|
12
|
+
maxPathLength?: number;
|
|
13
|
+
/** Allowed file extensions (e.g., ['.yaml', '.json']) */
|
|
14
|
+
allowedExtensions?: string[];
|
|
15
|
+
/** Whether to allow hidden files (dotfiles) */
|
|
16
|
+
allowHiddenFiles?: boolean;
|
|
17
|
+
/** Whether to resolve and validate symlinks */
|
|
18
|
+
validateSymlinks?: boolean;
|
|
19
|
+
/** Whether to allow absolute paths */
|
|
20
|
+
allowAbsolutePaths?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Numeric security configuration options.
|
|
24
|
+
*/
|
|
25
|
+
export interface NumericSecurityOptions {
|
|
26
|
+
/** Whether to require explicit min/max bounds */
|
|
27
|
+
requireBounds?: boolean;
|
|
28
|
+
/** Default minimum value if not specified */
|
|
29
|
+
defaultMin?: number;
|
|
30
|
+
/** Default maximum value if not specified */
|
|
31
|
+
defaultMax?: number;
|
|
32
|
+
/** Whether to allow NaN values */
|
|
33
|
+
allowNaN?: boolean;
|
|
34
|
+
/** Whether to allow Infinity values */
|
|
35
|
+
allowInfinity?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* String security configuration options.
|
|
39
|
+
*/
|
|
40
|
+
export interface StringSecurityOptions {
|
|
41
|
+
/** Maximum string length */
|
|
42
|
+
maxLength?: number;
|
|
43
|
+
/** Whether to allow null bytes */
|
|
44
|
+
allowNullBytes?: boolean;
|
|
45
|
+
/** Whether to allow control characters */
|
|
46
|
+
allowControlChars?: boolean;
|
|
47
|
+
/** Default pattern for validation */
|
|
48
|
+
defaultPattern?: RegExp;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Complete security validation configuration.
|
|
52
|
+
*/
|
|
53
|
+
export interface SecurityValidationConfig {
|
|
54
|
+
/** Security profile to use */
|
|
55
|
+
profile: SecurityProfile;
|
|
56
|
+
/** Path security settings */
|
|
57
|
+
paths: PathSecurityOptions;
|
|
58
|
+
/** Numeric security settings */
|
|
59
|
+
numbers: NumericSecurityOptions;
|
|
60
|
+
/** Strings security settings */
|
|
61
|
+
strings: StringSecurityOptions;
|
|
62
|
+
/** Whether validation failures should throw or warn */
|
|
63
|
+
failOnError: boolean;
|
|
64
|
+
/** Whether to log security events */
|
|
65
|
+
auditLogging: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Field-level security metadata that can be attached to schema fields.
|
|
69
|
+
*/
|
|
70
|
+
export interface SecureFieldOptions {
|
|
71
|
+
/** Whether this field contains a path */
|
|
72
|
+
isPath?: boolean;
|
|
73
|
+
/** Path security options for this specific field */
|
|
74
|
+
pathOptions?: PathSecurityOptions;
|
|
75
|
+
/** Whether this field should be treated as sensitive */
|
|
76
|
+
sensitive?: boolean;
|
|
77
|
+
/** Custom validation function */
|
|
78
|
+
customValidator?: (value: unknown) => boolean | string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Result of a security validation operation.
|
|
82
|
+
*/
|
|
83
|
+
export interface SecurityValidationResult {
|
|
84
|
+
/** Whether validation passed */
|
|
85
|
+
valid: boolean;
|
|
86
|
+
/** Validation errors if any */
|
|
87
|
+
errors: SecurityValidationError[];
|
|
88
|
+
/** Warnings (used in development profile) */
|
|
89
|
+
warnings: SecurityValidationWarning[];
|
|
90
|
+
/** Source of the validated value */
|
|
91
|
+
source: 'cli' | 'config' | 'default' | 'unknown';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Security validation error details.
|
|
95
|
+
*/
|
|
96
|
+
export interface SecurityValidationError {
|
|
97
|
+
/** Field path in dot notation */
|
|
98
|
+
field: string;
|
|
99
|
+
/** Error message */
|
|
100
|
+
message: string;
|
|
101
|
+
/** Error code for programmatic handling */
|
|
102
|
+
code: SecurityErrorCode;
|
|
103
|
+
/** The invalid value (sanitized) */
|
|
104
|
+
value?: string;
|
|
105
|
+
/** Source of the invalid value */
|
|
106
|
+
source: 'cli' | 'config' | 'default' | 'unknown';
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Security validation warning (non-fatal in development mode).
|
|
110
|
+
*/
|
|
111
|
+
export interface SecurityValidationWarning {
|
|
112
|
+
/** Field path in dot notation */
|
|
113
|
+
field: string;
|
|
114
|
+
/** Warning message */
|
|
115
|
+
message: string;
|
|
116
|
+
/** Warning code */
|
|
117
|
+
code: SecurityWarningCode;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Error codes for security validation failures.
|
|
121
|
+
*/
|
|
122
|
+
export type SecurityErrorCode = 'PATH_TRAVERSAL' | 'PATH_TOO_LONG' | 'PATH_INVALID_EXTENSION' | 'PATH_HIDDEN_FILE' | 'PATH_SYMLINK_ESCAPE' | 'PATH_OUTSIDE_ALLOWED' | 'PATH_ABSOLUTE_NOT_ALLOWED' | 'NUMBER_OUT_OF_RANGE' | 'NUMBER_NAN' | 'NUMBER_INFINITY' | 'NUMBER_MISSING_BOUNDS' | 'STRING_TOO_LONG' | 'STRING_NULL_BYTE' | 'STRING_CONTROL_CHAR' | 'STRING_PATTERN_MISMATCH' | 'VALIDATION_FAILED';
|
|
123
|
+
/**
|
|
124
|
+
* Warning codes for security validation.
|
|
125
|
+
*/
|
|
126
|
+
export type SecurityWarningCode = 'MISSING_PATH_BOUNDS' | 'MISSING_NUMERIC_BOUNDS' | 'PERMISSIVE_PATTERN' | 'DEVELOPMENT_MODE';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Create a Zod schema for secure enum validation.
|
|
4
|
+
* Unlike z.enum(), this provides better error messages and case handling.
|
|
5
|
+
*
|
|
6
|
+
* @param values - Allowed enum values
|
|
7
|
+
* @param options - Enum options
|
|
8
|
+
* @returns Zod enum schema with security refinements
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const schema = z.object({
|
|
13
|
+
* logLevel: secureEnum(['debug', 'info', 'warn', 'error']),
|
|
14
|
+
* format: secureEnum(['json', 'yaml', 'xml'], { caseSensitive: false }),
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function secureEnum<T extends string>(values: readonly [T, ...T[]], options?: {
|
|
19
|
+
caseSensitive?: boolean;
|
|
20
|
+
}): z.ZodPipe<z.ZodString, z.ZodTransform<Awaited<T>, string>> | z.ZodEnum<{ [k_1 in T]: k_1; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { NumericSecurityOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create a Zod schema for secure numeric validation with required bounds.
|
|
5
|
+
*
|
|
6
|
+
* @param min - Minimum allowed value (required in production)
|
|
7
|
+
* @param max - Maximum allowed value (required in production)
|
|
8
|
+
* @param options - Additional numeric security options
|
|
9
|
+
* @returns Zod number schema with security refinements
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const schema = z.object({
|
|
14
|
+
* timeout: secureNumber(100, 60000, { integer: true }),
|
|
15
|
+
* temperature: secureNumber(0, 1),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function secureNumber(min: number, max: number, options?: Partial<NumericSecurityOptions> & {
|
|
20
|
+
integer?: boolean;
|
|
21
|
+
}): z.ZodNumber;
|
|
22
|
+
/**
|
|
23
|
+
* Create a Zod schema for a port number (1-65535).
|
|
24
|
+
*/
|
|
25
|
+
export declare function securePort(): z.ZodNumber;
|
|
26
|
+
/**
|
|
27
|
+
* Create a Zod schema for a timeout in milliseconds.
|
|
28
|
+
* @param maxMs - Maximum timeout in milliseconds (default: 5 minutes)
|
|
29
|
+
*/
|
|
30
|
+
export declare function secureTimeout(maxMs?: number): z.ZodNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Create a Zod schema for a percentage (0-100).
|
|
33
|
+
*/
|
|
34
|
+
export declare function securePercentage(): z.ZodNumber;
|
|
35
|
+
/**
|
|
36
|
+
* Create a Zod schema for a retry count.
|
|
37
|
+
* @param maxRetries - Maximum retries allowed (default: 10)
|
|
38
|
+
*/
|
|
39
|
+
export declare function secureRetryCount(maxRetries?: number): z.ZodNumber;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PathSecurityOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create a Zod schema for secure path validation.
|
|
5
|
+
*
|
|
6
|
+
* @param options - Path security options
|
|
7
|
+
* @returns Zod string schema with path security refinements
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const schema = z.object({
|
|
12
|
+
* configFile: securePath({
|
|
13
|
+
* allowedExtensions: ['.yaml', '.json'],
|
|
14
|
+
* maxPathLength: 200
|
|
15
|
+
* }),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function securePath(options?: Partial<PathSecurityOptions>): z.ZodString;
|
|
20
|
+
/**
|
|
21
|
+
* Create a Zod schema for secure directory path validation.
|
|
22
|
+
* Same as securePath but with directory-specific defaults.
|
|
23
|
+
*/
|
|
24
|
+
export declare function secureDirectory(options?: Partial<PathSecurityOptions>): z.ZodString;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { StringSecurityOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create a Zod schema for secure string validation.
|
|
5
|
+
*
|
|
6
|
+
* @param options - String security options
|
|
7
|
+
* @returns Zod string schema with security refinements
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const schema = z.object({
|
|
12
|
+
* apiKey: secureString({ minLength: 20, maxLength: 100 }),
|
|
13
|
+
* model: secureString({ pattern: /^[a-z0-9-]+$/i }),
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function secureString(options?: Partial<StringSecurityOptions> & {
|
|
18
|
+
minLength?: number;
|
|
19
|
+
pattern?: RegExp;
|
|
20
|
+
}): z.ZodString;
|
|
21
|
+
/**
|
|
22
|
+
* Create a Zod schema for model names (e.g., "gpt-4o", "claude-3-opus").
|
|
23
|
+
*/
|
|
24
|
+
export declare function secureModelName(): z.ZodString;
|
|
25
|
+
/**
|
|
26
|
+
* Create a Zod schema for environment variable names.
|
|
27
|
+
*/
|
|
28
|
+
export declare function secureEnvVarName(): z.ZodString;
|
|
29
|
+
/**
|
|
30
|
+
* Create a Zod schema for safe identifiers (no special chars).
|
|
31
|
+
*/
|
|
32
|
+
export declare function secureIdentifier(maxLength?: number): z.ZodString;
|
|
33
|
+
/**
|
|
34
|
+
* Create a Zod schema for URLs.
|
|
35
|
+
*/
|
|
36
|
+
export declare function secureUrl(options?: {
|
|
37
|
+
allowedProtocols?: string[];
|
|
38
|
+
}): z.ZodString;
|