@seckav/security-sdk
Version:
SecKav Security SDK - Enterprise-grade security platform with AI-powered threat detection, LLM-powered misconfiguration scanning (Gemini/GPT-4/Claude), end-to-end encryption, behavioral analysis, enhanced file scanning, adaptive rate limiting, GDPR/DPDP/C
421 lines • 14.3 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnhancedSecurityModule = void 0;
const axios_1 = __importDefault(require("axios"));
/**
* Enhanced Security Module for SecKav SDK
* Provides access to advanced AI-powered security features
*/
class EnhancedSecurityModule {
constructor(config) {
this.config = config;
}
/**
* Configure enhanced security policy
*/
async configureSecurityPolicy(token, policy) {
try {
const response = await axios_1.default.put(`${this.config.apiUrl}/api/v1/enhanced-security/policy`, policy, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 10000,
});
return {
success: true,
data: response.data,
message: 'Security policy updated successfully',
};
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
success: false,
error: error.response?.data?.error || 'Failed to configure security policy',
message: error.response?.data?.message || 'An error occurred',
};
}
}
/**
* Analyze threat patterns in real-time
*/
async analyzeThreat(token, data) {
try {
const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/enhanced-security/analyze/threat`, data, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 5000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
isThreat: false,
threatType: [],
severity: 'low',
details: ['Analysis failed'],
confidence: 0,
};
}
}
/**
* Analyze request for anomalies using AI
*/
async analyzeAnomaly(token, requestData) {
try {
const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/enhanced-security/analyze/anomaly`, requestData, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 5000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
score: 0,
factors: [],
severity: 'low',
confidence: 0,
};
}
}
/**
* Scan files for malware and threats
*/
async scanFile(token, file) {
try {
const formData = new FormData();
formData.append('filename', file.filename);
const content = file.content instanceof Buffer ? file.content.toString('base64') : file.content;
formData.append('content', content);
if (file.mimeType) {
formData.append('mimeType', file.mimeType);
}
const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/enhanced-security/scan/file`, formData, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'multipart/form-data',
},
timeout: this.config.timeout || 30000, // File scanning can take longer
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
isThreat: false,
threats: [],
severity: 'low',
confidence: 0,
details: {
fileType: 'unknown',
actualMimeType: 'unknown',
size: 0,
hash: '',
malware: {
signatures: [],
heuristics: [],
behaviorAnalysis: [],
},
steganography: {
detected: false,
suspiciousPatterns: [],
},
},
};
}
}
/**
* Get adaptive rate limiting configuration
*/
async getAdaptiveRateLimit(token, organizationId, endpoint, method) {
try {
const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/enhanced-security/rate-limit/adaptive`, {
params: { organizationId, endpoint, method },
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 5000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
currentLimit: 100,
burstLimit: 200,
windowMs: 60000,
confidence: 0,
reasons: ['Default rate limit applied due to error'],
};
}
}
/**
* Check for DDoS attacks
*/
async checkDDoSStatus(token, organizationId) {
try {
const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/enhanced-security/ddos/status`, {
params: { organizationId },
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 5000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
isUnderAttack: false,
intensity: 0,
mitigationActions: [],
recommendedLimits: {
requestsPerSecond: 100,
connectionsPerIp: 10,
payload: 1048576, // 1MB
},
};
}
}
/**
* Get comprehensive security metrics
*/
async getSecurityMetrics(token, timeRange = '24h') {
try {
const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/enhanced-security/metrics`, {
params: { timeRange },
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 10000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
requests: {
total: 0,
blocked: 0,
allowed: 0,
blockRate: 0,
},
threats: {
total: 0,
sqlInjection: 0,
xss: 0,
malware: 0,
anomalies: 0,
},
performance: {
averageResponseTime: 0,
p95ResponseTime: 0,
p99ResponseTime: 0,
},
rateLimit: {
totalRequests: 0,
limitedRequests: 0,
adaptiveLimits: 0,
},
};
}
}
/**
* Get threat intelligence feeds
*/
async getThreatIntelligence(token, ipAddress) {
try {
const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/enhanced-security/threat-intelligence`, {
params: { ipAddress },
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 5000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
isMalicious: false,
sources: [],
threatTypes: [],
confidence: 0,
reputation: 50, // Neutral reputation
};
}
}
/**
* Get behavioral fingerprint analysis
*/
async getBehavioralFingerprint(token, requests) {
try {
const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/enhanced-security/behavioral-fingerprint`, { requests }, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 10000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
fingerprint: '',
similarity: 0,
isBot: false,
confidence: 0,
patterns: [],
};
}
}
/**
* Update threat detection rules
*/
async updateThreatRules(token, rules) {
try {
const response = await axios_1.default.put(`${this.config.apiUrl}/api/v1/enhanced-security/threat-rules`, { rules }, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 10000,
});
return {
success: true,
data: response.data,
message: 'Threat rules updated successfully',
};
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
success: false,
error: error.response?.data?.error || 'Failed to update threat rules',
message: error.response?.data?.message || 'An error occurred',
};
}
}
/**
* Get security health status
*/
async getSecurityHealth(token) {
try {
const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/enhanced-security/health`, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 5000,
});
return response.data;
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
status: 'unhealthy',
components: {
threatDetection: false,
anomalyDetection: false,
rateLimiting: false,
fileScanning: false,
threatIntelligence: false,
},
lastUpdate: new Date(),
issues: ['Unable to connect to security service'],
};
}
}
/**
* Generate security report
*/
async generateSecurityReport(token, timeRange = '24h', format = 'json') {
try {
const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/enhanced-security/report`, { timeRange, format }, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
timeout: this.config.timeout || 30000, // Report generation can take time
});
return {
success: true,
data: response.data,
message: 'Security report generated successfully',
};
}
catch (error) {
if (this.config.onError) {
this.config.onError(error);
}
return {
success: false,
error: error.response?.data?.error || 'Failed to generate security report',
message: error.response?.data?.message || 'An error occurred',
};
}
}
/**
* Get module information
*/
getInfo() {
return {
name: 'Enhanced Security Module',
version: '2.0.0',
features: [
'AI-Powered Threat Detection',
'Behavioral Anomaly Analysis',
'Advanced File Scanning',
'Adaptive Rate Limiting',
'DDoS Protection',
'Threat Intelligence',
'Behavioral Fingerprinting',
'Real-time Security Metrics',
'Custom Threat Rules',
'Security Health Monitoring',
'Automated Security Reports'
],
description: 'Advanced AI-powered security features for enterprise-grade protection',
};
}
}
exports.EnhancedSecurityModule = EnhancedSecurityModule;
//# sourceMappingURL=EnhancedSecurity.js.map