Debug Protection
Protection ID: debugProtection
Debug Protection is a specialized security feature that makes debugging of your JavaScript code extremely difficult by implementing countermeasures against browser developer tools. This significantly raises the barrier for reverse engineering attempts.
This protection is available in all editions of ByteHide Shield.
How It Works
Debug Protection adds special code to your application that detects when developer tools are open and implements countermeasures that make debugging nearly impossible. When someone tries to use debugger functionality, the protection actively interferes with the debugging process.
The protection works by detecting debug sessions and creating conditions that prevent normal step-through debugging, dramatically slowing down reverse engineering efforts.
This protection can impact browser performance when developer tools are open. It's designed to interfere with debugging attempts, which may lead to browser slowdowns when debug tools are active.
Parameters
Enabled boolean : Enables Debug Protection for your code. false by default
Interval number : Sets an interval in milliseconds to periodically force debug mode on the Console tab, making it harder to use other Developer Tools features. 0 by default (disabled)
Setting an interval value (between 2000-4000ms is recommended) intensifies the protection but may cause browser slowdowns. Use this option with caution, especially for production applications.
Configuration Examples
Basic Configuration (shield.config.json)
{
"debugProtection": true
}
Advanced Configuration
{
"debugProtection": true,
"debugProtectionInterval": 3000
}
Build Tool Integration (Webpack)
// webpack.config.js
const ByteHideShieldPlugin = require('@bytehide/webpack-shield');
module.exports = {
// ... other webpack config
plugins: [
new ByteHideShieldPlugin({
projectToken: 'your-project-token',
config: {
debugProtection: true,
debugProtectionInterval: 2500
}
})
]
}
Code Implementation
Debug Protection works by injecting protection code that interferes with debugging tools. The actual implementation is highly technical and automatically handled by ByteHide Shield. Below is a simplified conceptual example of how the protection works:
// Original code
function calculatePrice(product, quantity) {
return product.price * quantity;
}
// Conceptual representation of code with Debug Protection
// (actual implementation is much more complex)
(function() {
let debuggerTriggered = false;
setInterval(function() {
try {
// Techniques to detect debugger presence
debuggerTriggered = true;
debugger; // Strategic debugger statements that interfere with debugging flow
debuggerTriggered = false;
} catch (e) {}
}, 3000);
// Original function wrapped with protection
function calculatePrice(product, quantity) {
if (debuggerTriggered) {
// Code that runs when debugging is detected
// This creates unpredictable behavior for anyone debugging
}
return product.price * quantity;
}
window.calculatePrice = calculatePrice;
})();
When to Use
Debug Protection is particularly valuable in these scenarios:
- Premium software: Protecting paid applications from unauthorized access
- License validation code: Securing code that implements licensing logic
- Critical business logic: Preventing competitors from analyzing your algorithms
- Financial applications: Adding an extra layer of security to financial logic
For optimal implementation:
- Enable this protection in production builds only
- Consider using it without the interval option for less aggressive protection
- Use in combination with other Shield protections for maximum security
Compatibility Notes
Debug Protection has the following compatibility considerations:
- Browser compatibility: Works in all major browsers (Chrome, Firefox, Safari, Edge)
- Target environment: Not suitable for Node.js applications (only works in browser environments)
- User experience: Does not affect normal users who don't open developer tools
- Development: Should be disabled during development and testing phases
If using the interval option, be aware that it may cause high CPU usage when developer tools are open, potentially freezing the browser tab. This is intentional behavior to prevent debugging.
Related Protections
For maximum security, combine Debug Protection with: