packfs-core
Version:
Semantic filesystem operations for LLM agent frameworks with natural language understanding. See LLM_AGENT_GUIDE.md for copy-paste examples.
58 lines • 1.64 kB
JavaScript
/**
* Security engine for filesystem operations
*/
export class SecurityEngine {
constructor(config) {
this.config = config;
}
/**
* Validate if a file operation is allowed
*/
validateOperation(path, _operation) {
// Stub implementation - will be expanded
if (this.isBlockedPath(path)) {
return false;
}
if (this.config.validatePaths && !this.isValidPath(path)) {
return false;
}
return true;
}
/**
* Check if path is in blocked list
*/
isBlockedPath(path) {
return this.config.blockedPaths.some(blocked => path.startsWith(blocked) || path.includes(blocked));
}
/**
* Validate path format and security
*/
isValidPath(path) {
// Basic validation - prevent path traversal
if (path.includes('..') || path.includes('~')) {
return false;
}
// Ensure path is within sandbox if configured
if (this.config.sandboxPath && !path.startsWith(this.config.sandboxPath)) {
return false;
}
return true;
}
/**
* Check if file extension is allowed
*/
isAllowedExtension(filename) {
if (this.config.allowedExtensions.length === 0) {
return true; // No restrictions
}
const ext = filename.split('.').pop()?.toLowerCase();
return ext ? this.config.allowedExtensions.includes(ext) : false;
}
/**
* Validate file size
*/
isValidFileSize(size) {
return size <= this.config.maxFileSize;
}
}
//# sourceMappingURL=security.js.map