@xbibzlibrary/security
v1.0.0
Published
security
Downloads
4
Maintainers
Readme
🛡️ Xbibz Security Manager
📋 Table of Contents
- ✨ Features
- 🎯 What It Does
- 🔧 Installation
- 📖 Usage
- ⚙️ How It Works
- 🎨 Customization
- ⚠️ Important Notes
- 📜 License
- 👨💻 Author
✨ Features
🎯 What It Does
This security library provides a comprehensive front-end protection mechanism designed to prevent non-technical users from accessing sensitive areas of your web application. The library implements multiple layers of security measures that work together to create a robust defense system.
Key Protection Mechanisms:
The library monitors and intercepts various user actions in real-time, providing instant feedback when unauthorized activities are detected. It creates a secure environment by disabling common methods used to inspect, copy, or manipulate web content.
🔧 Installation
Method 1: Direct Include
<!DOCTYPE html>
<html>
<head>
<title>Your Protected Page</title>
</head>
<body>
<!-- Your content here -->
<script src="https://cdn.jsdelivr.net/npm/@xbibzlibrary/[email protected]/private.js"></script>
</body>
</html>Method 2: Module Import
import { EnterpriseSecurityManager } from './https://cdn.jsdelivr.net/npm/@xbibzlibrary/[email protected]/private.js';
// Initialize when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
new EnterpriseSecurityManager();
});📖 Usage
Basic Implementation
The library automatically initializes when the DOM is fully loaded. Simply include the script in your HTML file, and all security features will be activated immediately.
💡 Pro Tip: Place the script tag at the end of your body section for optimal performance and to ensure all DOM elements are loaded before security measures are applied.
Advanced Implementation
For more control, you can manually instantiate the security manager:
// Wait for DOM to be ready
document.addEventListener('DOMContentLoaded', () => {
// Initialize security manager
const security = new EnterpriseSecurityManager();
// Security is now active
console.log('Security measures activated');
});⚙️ How It Works
Architecture Overview
The Xbibz Security Manager employs a multi-layered defense strategy that operates simultaneously across different vectors of potential security breaches.
1️⃣ DevTools Detection & Prevention
The library intercepts keyboard events before they reach the browser, specifically targeting common DevTools shortcuts. When a user attempts to open developer tools using F12, Ctrl+Shift+I, Ctrl+Shift+C, or Ctrl+Shift+J, the event is immediately prevented and logged.
Technical Implementation: Event listeners capture keydown events and check for specific key combinations. Upon detection, the preventDefault() method stops the default browser action, effectively blocking access to developer tools through keyboard shortcuts.
2️⃣ Context Menu Blocking
Right-click functionality is completely disabled across the entire page. This prevents users from accessing the "Inspect Element" and "View Page Source" options through the context menu.
Technical Implementation: Both contextmenu and mousedown events are monitored. When a right-click is detected (mouse button 2), the event is prevented and the console is cleared to remove any debugging information.
3️⃣ Text Selection Prevention
CSS properties are dynamically injected into the page to prevent text selection at the browser rendering level. This is reinforced by JavaScript event interception.
Technical Implementation: The library creates a style element with user-select: none properties for all major browser engines (WebKit, Mozilla, MS). Additionally, the selectstart event is blocked to provide JavaScript-level protection.
4️⃣ Anti-Debugger Mechanism
The most sophisticated feature is the continuous debugger detection system. A setInterval loop runs every second, executing a debugger statement and measuring execution time.
Technical Implementation: When DevTools is closed, the debugger statement executes instantly. When DevTools is open, the debugger statement causes a pause, resulting in a measurable delay. If the execution time exceeds 100 milliseconds, the system detects an open DevTools instance and triggers protective measures.
5️⃣ Clipboard Operation Blocking
All clipboard operations including copy, cut, and paste are intercepted and prevented. This protects content from being extracted or modified through clipboard interactions.
Technical Implementation: Event listeners monitor copy, cut, and paste events, preventing their default behavior and logging each attempt for security monitoring.
🎨 Customization
Modifying Alert Messages
logAttempt(attemptType) {
const msgElement = document.createElement('div');
msgElement.innerHTML = `
<div style="your-custom-styles">
<strong>Custom Title:</strong> ${attemptType}
</div>
`;
document.body.appendChild(msgElement);
setTimeout(() => msgElement.remove(), 3000); // Custom duration
}Adjusting Anti-Debugger Sensitivity
setupAntiDebugger() {
setInterval(() => {
const startTime = performance.now();
debugger;
const endTime = performance.now();
// Adjust threshold (default: 100ms)
if ((endTime - startTime) > 150) { // More lenient
this.logAttempt('DevTools Detected');
}
}, 2000); // Check every 2 seconds instead of 1
}⚠️ Important Notes
Security Considerations
Client-Side Limitations: This library provides protection against casual users and non-technical individuals. However, it is important to understand that determined users with technical expertise can bypass client-side security measures. This library should be used as part of a comprehensive security strategy, not as the sole protection mechanism.
Performance Impact
The anti-debugger mechanism runs continuously and may have minor performance implications on lower-end devices. Consider adjusting the interval timing based on your specific requirements and user base.
Browser Compatibility
This library is designed for modern browsers supporting ES6+ JavaScript. Testing has been conducted on Chrome, Firefox, Safari, and Edge. Internet Explorer is not supported.
Best Practices
Complement with Server-Side Security: Always implement robust server-side validation, authentication, and authorization mechanisms. Client-side security should enhance, not replace, server-side protection.
User Experience Balance: Consider the impact on legitimate users. Excessive security measures can frustrate genuine users and negatively affect usability.
Legal Compliance: Ensure your implementation complies with accessibility standards and legal requirements in your jurisdiction.
📜 License
This project is licensed under the MIT License - feel free to use, modify, and distribute as needed.
