@secfn/core 0.0.1 → 0.0.3
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 +30 -322
- package/dist/encryption.d.ts +8 -0
- package/dist/encryption.d.ts.map +1 -0
- package/dist/encryption.js +83 -0
- package/dist/encryption.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/id.d.ts +3 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +11 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +9 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -11
- package/dist/index.js.map +1 -1
- package/dist/scanner/reporters.d.ts +14 -0
- package/dist/scanner/reporters.d.ts.map +1 -0
- package/dist/scanner/reporters.js +85 -0
- package/dist/scanner/reporters.js.map +1 -0
- package/dist/scanner/rules.d.ts +24 -0
- package/dist/scanner/rules.d.ts.map +1 -0
- package/dist/scanner/rules.js +141 -0
- package/dist/scanner/rules.js.map +1 -0
- package/dist/scanner/scanner.d.ts +28 -0
- package/dist/scanner/scanner.d.ts.map +1 -0
- package/dist/scanner/scanner.js +104 -0
- package/dist/scanner/scanner.js.map +1 -0
- package/dist/scanner/utils.d.ts +15 -0
- package/dist/scanner/utils.d.ts.map +1 -0
- package/dist/scanner/utils.js +41 -0
- package/dist/scanner/utils.js.map +1 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +249 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +261 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +32 -27
- package/dist/access-control/rbac.d.ts +0 -48
- package/dist/access-control/rbac.d.ts.map +0 -1
- package/dist/access-control/rbac.js +0 -203
- package/dist/access-control/rbac.js.map +0 -1
- package/dist/core/secfn.d.ts +0 -28
- package/dist/core/secfn.d.ts.map +0 -1
- package/dist/core/secfn.js +0 -73
- package/dist/core/secfn.js.map +0 -1
- package/dist/monitoring/security-monitor.d.ts +0 -46
- package/dist/monitoring/security-monitor.d.ts.map +0 -1
- package/dist/monitoring/security-monitor.js +0 -172
- package/dist/monitoring/security-monitor.js.map +0 -1
- package/dist/rate-limiting/rate-limiter.d.ts +0 -31
- package/dist/rate-limiting/rate-limiter.d.ts.map +0 -1
- package/dist/rate-limiting/rate-limiter.js +0 -140
- package/dist/rate-limiting/rate-limiter.js.map +0 -1
- package/dist/scanning/patterns.d.ts +0 -3
- package/dist/scanning/patterns.d.ts.map +0 -1
- package/dist/scanning/patterns.js +0 -139
- package/dist/scanning/patterns.js.map +0 -1
- package/dist/scanning/scanner.d.ts +0 -36
- package/dist/scanning/scanner.d.ts.map +0 -1
- package/dist/scanning/scanner.js +0 -152
- package/dist/scanning/scanner.js.map +0 -1
- package/dist/secrets/encryption.d.ts +0 -17
- package/dist/secrets/encryption.d.ts.map +0 -1
- package/dist/secrets/encryption.js +0 -47
- package/dist/secrets/encryption.js.map +0 -1
- package/dist/secrets/vault.d.ts +0 -43
- package/dist/secrets/vault.d.ts.map +0 -1
- package/dist/secrets/vault.js +0 -126
- package/dist/secrets/vault.js.map +0 -1
- package/dist/storage/indexeddb-storage.d.ts +0 -37
- package/dist/storage/indexeddb-storage.d.ts.map +0 -1
- package/dist/storage/indexeddb-storage.js +0 -284
- package/dist/storage/indexeddb-storage.js.map +0 -1
- package/dist/types/index.d.ts +0 -189
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/utils/helpers.d.ts +0 -8
- package/dist/utils/helpers.d.ts.map +0 -1
- package/dist/utils/helpers.js +0 -73
- package/dist/utils/helpers.js.map +0 -1
- package/examples/basic-usage.ts +0 -143
- package/src/access-control/rbac.ts +0 -271
- package/src/core/secfn.ts +0 -90
- package/src/index.ts +0 -27
- package/src/monitoring/security-monitor.ts +0 -245
- package/src/rate-limiting/rate-limiter.ts +0 -181
- package/src/scanning/patterns.ts +0 -140
- package/src/scanning/scanner.ts +0 -199
- package/src/secrets/encryption.ts +0 -74
- package/src/secrets/vault.ts +0 -187
- package/src/storage/indexeddb-storage.ts +0 -355
- package/src/types/index.ts +0 -213
- package/src/utils/helpers.ts +0 -84
- package/tsconfig.json +0 -26
package/src/types/index.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
export type Severity = 'critical' | 'high' | 'medium' | 'low' | 'info';
|
|
2
|
-
export type Environment = 'development' | 'staging' | 'production';
|
|
3
|
-
|
|
4
|
-
export interface StorageConfig {
|
|
5
|
-
type: 'indexeddb' | 'file' | 'db';
|
|
6
|
-
dbName?: string;
|
|
7
|
-
path?: string;
|
|
8
|
-
adapter?: any;
|
|
9
|
-
retentionDays?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface SecretPattern {
|
|
13
|
-
name: string;
|
|
14
|
-
pattern: RegExp;
|
|
15
|
-
entropy?: number;
|
|
16
|
-
description: string;
|
|
17
|
-
severity: Severity;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface SecretScanResult {
|
|
21
|
-
id: string;
|
|
22
|
-
timestamp: number;
|
|
23
|
-
file: string;
|
|
24
|
-
line: number;
|
|
25
|
-
column: number;
|
|
26
|
-
pattern: string;
|
|
27
|
-
match: string;
|
|
28
|
-
redactedMatch: string;
|
|
29
|
-
severity: Severity;
|
|
30
|
-
entropy: number;
|
|
31
|
-
context: string;
|
|
32
|
-
resolved: boolean;
|
|
33
|
-
falsePositive: boolean;
|
|
34
|
-
metadata?: Record<string, unknown>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface Secret {
|
|
38
|
-
id: string;
|
|
39
|
-
key: string;
|
|
40
|
-
value: string;
|
|
41
|
-
encrypted: boolean;
|
|
42
|
-
version: number;
|
|
43
|
-
tags: string[];
|
|
44
|
-
environment?: Environment;
|
|
45
|
-
expiresAt?: number;
|
|
46
|
-
rotateEvery?: number;
|
|
47
|
-
lastRotated?: number;
|
|
48
|
-
lastAccessed?: number;
|
|
49
|
-
accessCount: number;
|
|
50
|
-
createdBy: string;
|
|
51
|
-
createdAt: number;
|
|
52
|
-
updatedAt: number;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface SecretAccess {
|
|
56
|
-
id: string;
|
|
57
|
-
secretId: string;
|
|
58
|
-
userId: string;
|
|
59
|
-
action: 'read' | 'write' | 'delete' | 'rotate';
|
|
60
|
-
timestamp: number;
|
|
61
|
-
ip?: string;
|
|
62
|
-
userAgent?: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface Role {
|
|
66
|
-
id: string;
|
|
67
|
-
name: string;
|
|
68
|
-
description: string;
|
|
69
|
-
permissions: string[];
|
|
70
|
-
inherits?: string[];
|
|
71
|
-
metadata?: Record<string, unknown>;
|
|
72
|
-
createdAt: number;
|
|
73
|
-
updatedAt: number;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface Permission {
|
|
77
|
-
id: string;
|
|
78
|
-
resource: string;
|
|
79
|
-
action: string;
|
|
80
|
-
conditions?: PolicyCondition[];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface UserRole {
|
|
84
|
-
userId: string;
|
|
85
|
-
roleId: string;
|
|
86
|
-
resourceIds?: string[];
|
|
87
|
-
expiresAt?: number;
|
|
88
|
-
assignedAt: number;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface PolicyCondition {
|
|
92
|
-
field: string;
|
|
93
|
-
operator: 'eq' | 'ne' | 'in' | 'nin' | 'gt' | 'lt' | 'contains';
|
|
94
|
-
value: unknown;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface AccessRequest {
|
|
98
|
-
userId: string;
|
|
99
|
-
action: string;
|
|
100
|
-
resourceId?: string;
|
|
101
|
-
context?: Record<string, unknown>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface RateLimitRule {
|
|
105
|
-
id?: string;
|
|
106
|
-
name?: string;
|
|
107
|
-
type?: 'global' | 'perUser' | 'perIP' | 'perEndpoint';
|
|
108
|
-
requests: number;
|
|
109
|
-
window: number;
|
|
110
|
-
blockDuration?: number;
|
|
111
|
-
endpoints?: string[];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface RateLimitEntry {
|
|
115
|
-
key: string;
|
|
116
|
-
count: number;
|
|
117
|
-
resetAt: number;
|
|
118
|
-
blocked: boolean;
|
|
119
|
-
blockedUntil?: number;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface RateLimitResult {
|
|
123
|
-
allowed: boolean;
|
|
124
|
-
remaining: number;
|
|
125
|
-
resetAt: number;
|
|
126
|
-
retryAfter?: number;
|
|
127
|
-
limit?: number;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface RateLimitViolation {
|
|
131
|
-
id: string;
|
|
132
|
-
timestamp: number;
|
|
133
|
-
key: string;
|
|
134
|
-
ip: string;
|
|
135
|
-
userId?: string;
|
|
136
|
-
endpoint: string;
|
|
137
|
-
requestCount: number;
|
|
138
|
-
limit: number;
|
|
139
|
-
window: number;
|
|
140
|
-
blocked: boolean;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export type SecurityEventType =
|
|
144
|
-
| 'auth_failure'
|
|
145
|
-
| 'rate_limit_exceeded'
|
|
146
|
-
| 'unauthorized_access'
|
|
147
|
-
| 'secret_accessed'
|
|
148
|
-
| 'permission_denied'
|
|
149
|
-
| 'suspicious_activity'
|
|
150
|
-
| 'secret_exposed'
|
|
151
|
-
| 'policy_violation';
|
|
152
|
-
|
|
153
|
-
export interface SecurityEvent {
|
|
154
|
-
id: string;
|
|
155
|
-
timestamp: number;
|
|
156
|
-
type: SecurityEventType;
|
|
157
|
-
severity: Severity;
|
|
158
|
-
userId?: string;
|
|
159
|
-
ip: string;
|
|
160
|
-
userAgent?: string;
|
|
161
|
-
resource?: string;
|
|
162
|
-
action?: string;
|
|
163
|
-
metadata: Record<string, unknown>;
|
|
164
|
-
resolved: boolean;
|
|
165
|
-
resolvedAt?: number;
|
|
166
|
-
resolvedBy?: string;
|
|
167
|
-
notes?: string;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export interface SecurityMetrics {
|
|
171
|
-
timeRange: { start: number; end: number };
|
|
172
|
-
totalEvents: number;
|
|
173
|
-
eventsByType: Record<string, number>;
|
|
174
|
-
eventsBySeverity: Record<string, number>;
|
|
175
|
-
topIPs: Array<{ ip: string; count: number }>;
|
|
176
|
-
topUsers: Array<{ userId: string; count: number }>;
|
|
177
|
-
anomalies?: SecurityAnomaly[];
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export type AnomalyType =
|
|
181
|
-
| 'unusual_access_pattern'
|
|
182
|
-
| 'geographic_anomaly'
|
|
183
|
-
| 'spike_in_failures'
|
|
184
|
-
| 'new_endpoint_access'
|
|
185
|
-
| 'unusual_time';
|
|
186
|
-
|
|
187
|
-
export interface SecurityAnomaly {
|
|
188
|
-
id: string;
|
|
189
|
-
timestamp: number;
|
|
190
|
-
type: AnomalyType;
|
|
191
|
-
score: number;
|
|
192
|
-
description: string;
|
|
193
|
-
relatedEvents: string[];
|
|
194
|
-
userId?: string;
|
|
195
|
-
ip?: string;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export interface EventQuery {
|
|
199
|
-
type?: SecurityEventType | SecurityEventType[];
|
|
200
|
-
severity?: Severity | Severity[];
|
|
201
|
-
userId?: string;
|
|
202
|
-
ip?: string;
|
|
203
|
-
startDate?: number;
|
|
204
|
-
endDate?: number;
|
|
205
|
-
resolved?: boolean;
|
|
206
|
-
limit?: number;
|
|
207
|
-
offset?: number;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export interface TimeRange {
|
|
211
|
-
start: number;
|
|
212
|
-
end: number;
|
|
213
|
-
}
|
package/src/utils/helpers.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from 'crypto';
|
|
2
|
-
|
|
3
|
-
export function generateId(prefix?: string): string {
|
|
4
|
-
const random = randomBytes(16).toString('hex');
|
|
5
|
-
return prefix ? `${prefix}_${random}` : random;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function calculateEntropy(str: string): number {
|
|
9
|
-
if (!str) return 0;
|
|
10
|
-
|
|
11
|
-
const len = str.length;
|
|
12
|
-
const frequencies: Record<string, number> = {};
|
|
13
|
-
|
|
14
|
-
for (let i = 0; i < len; i++) {
|
|
15
|
-
const char = str[i];
|
|
16
|
-
frequencies[char] = (frequencies[char] || 0) + 1;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let entropy = 0;
|
|
20
|
-
for (const char in frequencies) {
|
|
21
|
-
const probability = frequencies[char] / len;
|
|
22
|
-
entropy -= probability * Math.log2(probability);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return entropy;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function redactSecret(secret: string, visibleChars = 4): string {
|
|
29
|
-
if (secret.length <= visibleChars) {
|
|
30
|
-
return '*'.repeat(secret.length);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const start = secret.slice(0, visibleChars);
|
|
34
|
-
const rest = '*'.repeat(secret.length - visibleChars);
|
|
35
|
-
return start + rest;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function isExpired(timestamp?: number): boolean {
|
|
39
|
-
if (!timestamp) return false;
|
|
40
|
-
return Date.now() > timestamp;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function delay(ms: number): Promise<void> {
|
|
44
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function sanitizeForLog(obj: Record<string, unknown>): Record<string, unknown> {
|
|
48
|
-
const sanitized: Record<string, unknown> = {};
|
|
49
|
-
const sensitiveKeys = ['password', 'secret', 'token', 'key', 'apiKey', 'api_key'];
|
|
50
|
-
|
|
51
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
52
|
-
const lowerKey = key.toLowerCase();
|
|
53
|
-
if (sensitiveKeys.some(sk => lowerKey.includes(sk))) {
|
|
54
|
-
sanitized[key] = '[REDACTED]';
|
|
55
|
-
} else if (typeof value === 'object' && value !== null) {
|
|
56
|
-
sanitized[key] = sanitizeForLog(value as Record<string, unknown>);
|
|
57
|
-
} else {
|
|
58
|
-
sanitized[key] = value;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return sanitized;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function parseTimeWindow(window: string | number): number {
|
|
66
|
-
if (typeof window === 'number') return window;
|
|
67
|
-
|
|
68
|
-
const match = window.match(/^(\d+)(ms|s|m|h|d)$/);
|
|
69
|
-
if (!match) {
|
|
70
|
-
throw new Error(`Invalid time window format: ${window}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const [, value, unit] = match;
|
|
74
|
-
const num = parseInt(value, 10);
|
|
75
|
-
|
|
76
|
-
switch (unit) {
|
|
77
|
-
case 'ms': return num;
|
|
78
|
-
case 's': return num * 1000;
|
|
79
|
-
case 'm': return num * 60 * 1000;
|
|
80
|
-
case 'h': return num * 60 * 60 * 1000;
|
|
81
|
-
case 'd': return num * 24 * 60 * 60 * 1000;
|
|
82
|
-
default: throw new Error(`Unknown time unit: ${unit}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ES2022", "DOM"],
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"resolveJsonModule": true,
|
|
8
|
-
"allowJs": false,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"rootDir": "./src",
|
|
11
|
-
"declaration": true,
|
|
12
|
-
"declarationMap": true,
|
|
13
|
-
"sourceMap": true,
|
|
14
|
-
"strict": true,
|
|
15
|
-
"noUnusedLocals": true,
|
|
16
|
-
"noUnusedParameters": true,
|
|
17
|
-
"noImplicitReturns": true,
|
|
18
|
-
"noFallthroughCasesInSwitch": true,
|
|
19
|
-
"skipLibCheck": true,
|
|
20
|
-
"esModuleInterop": true,
|
|
21
|
-
"allowSyntheticDefaultImports": true,
|
|
22
|
-
"forceConsistentCasingInFileNames": true
|
|
23
|
-
},
|
|
24
|
-
"include": ["src/**/*"],
|
|
25
|
-
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
26
|
-
}
|