content-security-toolkit 1.0.0
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/LICENSE +9 -0
- package/README.md +171 -0
- package/dist/config/default-extensions-config.json +103 -0
- package/dist/core/ContentProtector.d.ts +63 -0
- package/dist/core/ContentProtector.js +279 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/mediator/ContentProtectionMediator.d.ts +86 -0
- package/dist/core/mediator/ContentProtectionMediator.js +238 -0
- package/dist/core/mediator/eventDataTypes.d.ts +205 -0
- package/dist/core/mediator/eventDataTypes.js +23 -0
- package/dist/core/mediator/handlers/abstractEventHandler.d.ts +67 -0
- package/dist/core/mediator/handlers/abstractEventHandler.js +106 -0
- package/dist/core/mediator/handlers/baseEventHandler.d.ts +65 -0
- package/dist/core/mediator/handlers/baseEventHandler.js +99 -0
- package/dist/core/mediator/handlers/devToolsEventHandler.d.ts +9 -0
- package/dist/core/mediator/handlers/devToolsEventHandler.js +95 -0
- package/dist/core/mediator/handlers/eventHandlerRegistry.d.ts +9 -0
- package/dist/core/mediator/handlers/eventHandlerRegistry.js +34 -0
- package/dist/core/mediator/handlers/extensionEventHandlers.d.ts +40 -0
- package/dist/core/mediator/handlers/extensionEventHandlers.js +140 -0
- package/dist/core/mediator/handlers/iFrameEventHandlers.d.ts +27 -0
- package/dist/core/mediator/handlers/iFrameEventHandlers.js +93 -0
- package/dist/core/mediator/handlers/index.d.ts +9 -0
- package/dist/core/mediator/handlers/index.js +34 -0
- package/dist/core/mediator/handlers/screenShotEventHandlers.d.ts +34 -0
- package/dist/core/mediator/handlers/screenShotEventHandlers.js +111 -0
- package/dist/core/mediator/protection-event.d.ts +94 -0
- package/dist/core/mediator/protection-event.js +43 -0
- package/dist/core/mediator/types.d.ts +105 -0
- package/dist/core/mediator/types.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/strategies/AbstractStrategy.d.ts +152 -0
- package/dist/strategies/AbstractStrategy.js +296 -0
- package/dist/strategies/AbstractStrategy.mediator.d.ts +162 -0
- package/dist/strategies/AbstractStrategy.mediator.js +349 -0
- package/dist/strategies/ClipboardStrategy.d.ts +67 -0
- package/dist/strategies/ClipboardStrategy.js +291 -0
- package/dist/strategies/ContextMenuStrategy.d.ts +60 -0
- package/dist/strategies/ContextMenuStrategy.js +454 -0
- package/dist/strategies/DevToolsStrategy copy.d.ts +85 -0
- package/dist/strategies/DevToolsStrategy copy.js +362 -0
- package/dist/strategies/DevToolsStrategy-detectorManager.d.ts +70 -0
- package/dist/strategies/DevToolsStrategy-detectorManager.js +309 -0
- package/dist/strategies/DevToolsStrategy-simple.d.ts +75 -0
- package/dist/strategies/DevToolsStrategy-simple.js +366 -0
- package/dist/strategies/DevToolsStrategy.d.ts +55 -0
- package/dist/strategies/DevToolsStrategy.js +314 -0
- package/dist/strategies/ExtensionStrategy.d.ts +66 -0
- package/dist/strategies/ExtensionStrategy.js +486 -0
- package/dist/strategies/IFrameStrategy.d.ts +49 -0
- package/dist/strategies/IFrameStrategy.js +255 -0
- package/dist/strategies/KeyboardStrategy.d.ts +35 -0
- package/dist/strategies/KeyboardStrategy.js +130 -0
- package/dist/strategies/PrintStrategy.d.ts +47 -0
- package/dist/strategies/PrintStrategy.js +201 -0
- package/dist/strategies/ScreenshotStrategy.d.ts +90 -0
- package/dist/strategies/ScreenshotStrategy.js +488 -0
- package/dist/strategies/SelectionStrategy.d.ts +49 -0
- package/dist/strategies/SelectionStrategy.js +216 -0
- package/dist/strategies/StrategyRegistry.d.ts +133 -0
- package/dist/strategies/StrategyRegistry.js +379 -0
- package/dist/strategies/WatermarkStrategy.d.ts +47 -0
- package/dist/strategies/WatermarkStrategy.js +273 -0
- package/dist/strategies/index.d.ts +9 -0
- package/dist/strategies/index.js +10 -0
- package/dist/types/index.d.ts +271 -0
- package/dist/types/index.js +16 -0
- package/dist/utils/DOMObserver.d.ts +68 -0
- package/dist/utils/DOMObserver.js +134 -0
- package/dist/utils/base/LoggableComponent.d.ts +62 -0
- package/dist/utils/base/LoggableComponent.js +95 -0
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.d.ts +6 -0
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.js +24 -0
- package/dist/utils/debuggerDetector/debuggerDetector.d.ts +55 -0
- package/dist/utils/debuggerDetector/debuggerDetector.js +158 -0
- package/dist/utils/debuggerDetector/firefoxDetector.d.ts +8 -0
- package/dist/utils/debuggerDetector/firefoxDetector.js +64 -0
- package/dist/utils/detection.d.ts +29 -0
- package/dist/utils/detection.js +267 -0
- package/dist/utils/detectors/AbstractDevToolsDetector.d.ts +105 -0
- package/dist/utils/detectors/AbstractDevToolsDetector.js +136 -0
- package/dist/utils/detectors/dateToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/dateToStringDetector.js +96 -0
- package/dist/utils/detectors/debugLibDetector.d.ts +64 -0
- package/dist/utils/detectors/debugLibDetector.js +195 -0
- package/dist/utils/detectors/debuggerDetectionWorker.d.ts +6 -0
- package/dist/utils/detectors/debuggerDetectionWorker.js +24 -0
- package/dist/utils/detectors/debuggerDetector.d.ts +51 -0
- package/dist/utils/detectors/debuggerDetector.js +211 -0
- package/dist/utils/detectors/defineGetterDetector.d.ts +48 -0
- package/dist/utils/detectors/defineGetterDetector.js +150 -0
- package/dist/utils/detectors/detectorInterface.d.ts +36 -0
- package/dist/utils/detectors/detectorInterface.js +1 -0
- package/dist/utils/detectors/devToolsDetectorManager.d.ts +88 -0
- package/dist/utils/detectors/devToolsDetectorManager.js +246 -0
- package/dist/utils/detectors/firefoxDetector.d.ts +8 -0
- package/dist/utils/detectors/firefoxDetector.js +64 -0
- package/dist/utils/detectors/funcToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/funcToStringDetector.js +90 -0
- package/dist/utils/detectors/regToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/regToStringDetector.js +129 -0
- package/dist/utils/detectors/sizeDetector.d.ts +54 -0
- package/dist/utils/detectors/sizeDetector.js +134 -0
- package/dist/utils/detectors/timingDetector.d.ts +55 -0
- package/dist/utils/detectors/timingDetector.js +143 -0
- package/dist/utils/dom.d.ts +20 -0
- package/dist/utils/dom.js +83 -0
- package/dist/utils/environment.d.ts +29 -0
- package/dist/utils/environment.js +267 -0
- package/dist/utils/eventManager.d.ts +167 -0
- package/dist/utils/eventManager.js +556 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/intervalManager.d.ts +96 -0
- package/dist/utils/intervalManager.js +229 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.d.ts +41 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.js +135 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcuts.d.ts +18 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcuts.js +195 -0
- package/dist/utils/logging/LogLevel.d.ts +21 -0
- package/dist/utils/logging/LogLevel.js +46 -0
- package/dist/utils/logging/LoggingConfig.d.ts +68 -0
- package/dist/utils/logging/LoggingConfig.js +64 -0
- package/dist/utils/logging/LoggingFactory.d.ts +22 -0
- package/dist/utils/logging/LoggingFactory.js +61 -0
- package/dist/utils/logging/LoggingService.d.ts +235 -0
- package/dist/utils/logging/LoggingService.js +385 -0
- package/dist/utils/logging/SimpleLoggingService.d.ts +39 -0
- package/dist/utils/logging/SimpleLoggingService.js +58 -0
- package/dist/utils/logging/advanced/LogLevel.d.ts +21 -0
- package/dist/utils/logging/advanced/LogLevel.js +46 -0
- package/dist/utils/logging/advanced/LoggingConfig.d.ts +68 -0
- package/dist/utils/logging/advanced/LoggingConfig.js +64 -0
- package/dist/utils/logging/advanced/LoggingFactory.d.ts +22 -0
- package/dist/utils/logging/advanced/LoggingFactory.js +61 -0
- package/dist/utils/logging/advanced/LoggingService.d.ts +235 -0
- package/dist/utils/logging/advanced/LoggingService.js +385 -0
- package/dist/utils/logging/simple/Loggable.d.ts +33 -0
- package/dist/utils/logging/simple/Loggable.js +1 -0
- package/dist/utils/logging/simple/LoggingDelegate.d.ts +42 -0
- package/dist/utils/logging/simple/LoggingDelegate.js +53 -0
- package/dist/utils/logging/simple/SimpleLoggingService.d.ts +39 -0
- package/dist/utils/logging/simple/SimpleLoggingService.js +58 -0
- package/dist/utils/orientation.d.ts +15 -0
- package/dist/utils/orientation.js +32 -0
- package/dist/utils/protectedContentManager-simple.d.ts +86 -0
- package/dist/utils/protectedContentManager-simple.js +180 -0
- package/dist/utils/protectedContentManager.d.ts +162 -0
- package/dist/utils/protectedContentManager.js +427 -0
- package/dist/utils/screenshotDetector.d.ts +72 -0
- package/dist/utils/screenshotDetector.js +179 -0
- package/dist/utils/securityOverlayManager-observer-pause.d.ts +283 -0
- package/dist/utils/securityOverlayManager-observer-pause.js +878 -0
- package/dist/utils/securityOverlayManager-simple.d.ts +197 -0
- package/dist/utils/securityOverlayManager-simple.js +552 -0
- package/dist/utils/securityOverlayManager.d.ts +260 -0
- package/dist/utils/securityOverlayManager.js +774 -0
- package/dist/utils/timeoutManager.d.ts +55 -0
- package/dist/utils/timeoutManager.js +121 -0
- package/package.json +54 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { isBrowser, getBrowser } from "../utils/detection";
|
|
2
|
+
import { ProtectedContentManager } from "../utils/protectedContentManager";
|
|
3
|
+
import { SecurityOverlayManager } from "../utils/securityOverlayManager";
|
|
4
|
+
import { intervalManager } from "../utils/intervalManager";
|
|
5
|
+
import { AbstractStrategy, StrategyErrorType } from "./AbstractStrategy";
|
|
6
|
+
import { DebuggerDetector } from "../utils/detectors/debuggerDetector";
|
|
7
|
+
import { TimingDetector } from "../utils/detectors/timingDetector";
|
|
8
|
+
import { DateToStringDetector } from "../utils/detectors/dateToStringDetector";
|
|
9
|
+
/**
|
|
10
|
+
* Strategy for detecting and responding to DevTools usage
|
|
11
|
+
*/
|
|
12
|
+
export class DevToolsStrategy extends AbstractStrategy {
|
|
13
|
+
/**
|
|
14
|
+
* Create a new DevToolsStrategy
|
|
15
|
+
* @param options Options for customizing the DevTools protection
|
|
16
|
+
* @param targetElement Element containing sensitive content
|
|
17
|
+
* @param customHandler Optional custom handler for DevTools detection
|
|
18
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
19
|
+
*/
|
|
20
|
+
constructor(options, targetElement = null, customHandler, debugMode = false) {
|
|
21
|
+
super("DevToolsStrategy", debugMode);
|
|
22
|
+
this.intervalId = null;
|
|
23
|
+
this.taskId = null;
|
|
24
|
+
this.isDevToolsOpen = false;
|
|
25
|
+
this.targetElement = null;
|
|
26
|
+
this.contentManager = null;
|
|
27
|
+
// Detectors
|
|
28
|
+
this.debuggerDetector = null;
|
|
29
|
+
this.timingDetector = null;
|
|
30
|
+
this.dateToStringDetector = null;
|
|
31
|
+
this.activeDetector = null;
|
|
32
|
+
this.options = {
|
|
33
|
+
overlayOptions: {
|
|
34
|
+
title: "Developer Tools Detected",
|
|
35
|
+
message: "For security reasons, this content is not available while developer tools are open.",
|
|
36
|
+
secondaryMessage: "Please close developer tools to continue viewing this content.",
|
|
37
|
+
textColor: "white",
|
|
38
|
+
backgroundColor: "rgba(255, 0, 0, 0.7)",
|
|
39
|
+
},
|
|
40
|
+
showOverlay: true,
|
|
41
|
+
checkFrequency: 1000,
|
|
42
|
+
hideContent: false,
|
|
43
|
+
...options,
|
|
44
|
+
};
|
|
45
|
+
this.targetElement = targetElement;
|
|
46
|
+
this.customHandler = customHandler;
|
|
47
|
+
this.browserInfo = getBrowser();
|
|
48
|
+
// Initialize content manager if target element is provided
|
|
49
|
+
if (targetElement) {
|
|
50
|
+
this.contentManager = new ProtectedContentManager(targetElement, debugMode);
|
|
51
|
+
}
|
|
52
|
+
// Initialize overlay manager
|
|
53
|
+
this.overlayManager = new SecurityOverlayManager(debugMode);
|
|
54
|
+
this.log("Initialized with checkFrequency:", this.options.checkFrequency);
|
|
55
|
+
this.log("Detected browser:", this.browserInfo.name, this.browserInfo.version);
|
|
56
|
+
// Initialize the appropriate detector based on browser
|
|
57
|
+
this.initDetectors();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Initialize the appropriate detector based on browser
|
|
61
|
+
*/
|
|
62
|
+
initDetectors() {
|
|
63
|
+
return this.safeExecute("initDetectors", StrategyErrorType.INITIALIZATION, () => {
|
|
64
|
+
if (!isBrowser())
|
|
65
|
+
return;
|
|
66
|
+
try {
|
|
67
|
+
// Common callback for all detectors
|
|
68
|
+
const onDevToolsChange = (isOpen) => {
|
|
69
|
+
this.handleDevToolsStateChange(isOpen);
|
|
70
|
+
};
|
|
71
|
+
// Initialize the debugger detector (for Chrome and Edge)
|
|
72
|
+
this.debuggerDetector = new DebuggerDetector({
|
|
73
|
+
timeoutDuration: 50, // 50ms timeout for detection
|
|
74
|
+
onDevToolsChange,
|
|
75
|
+
debugMode: this.debugMode,
|
|
76
|
+
});
|
|
77
|
+
// Initialize the timing detector (for Firefox)
|
|
78
|
+
this.timingDetector = new TimingDetector({
|
|
79
|
+
onDevToolsChange,
|
|
80
|
+
debugMode: this.debugMode,
|
|
81
|
+
thresholdMultiplier: 4, // Adjust sensitivity
|
|
82
|
+
});
|
|
83
|
+
// Initialize the date-to-string detector (for Safari and fallback)
|
|
84
|
+
if (DateToStringDetector.isSupported()) {
|
|
85
|
+
this.dateToStringDetector = new DateToStringDetector({
|
|
86
|
+
onDevToolsChange,
|
|
87
|
+
debugMode: this.debugMode,
|
|
88
|
+
threshold: 2, // Default threshold
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// Set the active detector based on browser
|
|
92
|
+
if (this.browserInfo.name === "firefox") {
|
|
93
|
+
this.activeDetector = this.timingDetector;
|
|
94
|
+
this.log("Using TimingDetector for Firefox");
|
|
95
|
+
}
|
|
96
|
+
else if (this.browserInfo.name === "safari") {
|
|
97
|
+
if (this.dateToStringDetector) {
|
|
98
|
+
this.activeDetector = this.dateToStringDetector;
|
|
99
|
+
this.log("Using DateToStringDetector for Safari");
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.activeDetector = this.debuggerDetector;
|
|
103
|
+
this.log("Using DebuggerDetector for Safari (fallback)");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.activeDetector = this.debuggerDetector;
|
|
108
|
+
this.log("Using DebuggerDetector for", this.browserInfo.name);
|
|
109
|
+
}
|
|
110
|
+
this.log("Detectors initialized");
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
this.handleError(StrategyErrorType.INITIALIZATION, "Failed to initialize detectors", error);
|
|
114
|
+
// Log more details about the error to help with troubleshooting
|
|
115
|
+
if (this.debugMode) {
|
|
116
|
+
console.error("Detector initialization error details:", error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Handle DevTools state changes from any detection method
|
|
123
|
+
*/
|
|
124
|
+
handleDevToolsStateChange(isOpen) {
|
|
125
|
+
return this.safeExecute("handleDevToolsStateChange", StrategyErrorType.APPLICATION, () => {
|
|
126
|
+
// Only take action if state has changed
|
|
127
|
+
if (isOpen !== this.isDevToolsOpen) {
|
|
128
|
+
this.isDevToolsOpen = isOpen;
|
|
129
|
+
this.log(`DevTools state changed: ${isOpen ? "open" : "closed"}`);
|
|
130
|
+
if (isOpen) {
|
|
131
|
+
this.applyDevToolsProtection();
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.removeDevToolsProtection();
|
|
135
|
+
}
|
|
136
|
+
// Call custom handler if provided
|
|
137
|
+
if (this.customHandler) {
|
|
138
|
+
this.customHandler(isOpen);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Start monitoring for DevTools usage
|
|
145
|
+
*/
|
|
146
|
+
startMonitoring() {
|
|
147
|
+
return this.safeExecute("startMonitoring", StrategyErrorType.APPLICATION, () => {
|
|
148
|
+
if (typeof window === "undefined")
|
|
149
|
+
return;
|
|
150
|
+
this.log("Starting DevTools monitoring");
|
|
151
|
+
// Register with IntervalManager for periodic checks
|
|
152
|
+
this.taskId = intervalManager.registerTask("devtools-detection", () => this.safeExecute("intervalTask", StrategyErrorType.APPLICATION, () => {
|
|
153
|
+
// Use the active detector
|
|
154
|
+
if (this.activeDetector) {
|
|
155
|
+
this.activeDetector.checkDevTools();
|
|
156
|
+
}
|
|
157
|
+
// Always check overlay state if DevTools are open
|
|
158
|
+
if (this.isDevToolsOpen) {
|
|
159
|
+
this.overlayManager.checkAndRestoreOverlay();
|
|
160
|
+
}
|
|
161
|
+
}), this.options.checkFrequency);
|
|
162
|
+
// Force initial check
|
|
163
|
+
if (this.activeDetector) {
|
|
164
|
+
this.activeDetector.checkDevTools();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Apply DevTools protection by creating overlay and event blocker
|
|
170
|
+
*/
|
|
171
|
+
applyDevToolsProtection() {
|
|
172
|
+
return this.safeExecute("applyDevToolsProtection", StrategyErrorType.APPLICATION, () => {
|
|
173
|
+
if (!isBrowser())
|
|
174
|
+
return;
|
|
175
|
+
if (this.options.hideContent) {
|
|
176
|
+
// Hide sensitive content
|
|
177
|
+
this.hideSensitiveContent();
|
|
178
|
+
}
|
|
179
|
+
if (this.options.showOverlay) {
|
|
180
|
+
// Create overlay using the overlay manager
|
|
181
|
+
this.overlayManager.showOverlay({
|
|
182
|
+
...this.options.overlayOptions,
|
|
183
|
+
blockEvents: true, // Block all events
|
|
184
|
+
autoRestore: true, // Restore overlay if removed from DOM
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
this.log("DevTools protection applied");
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Hide sensitive content when DevTools is open
|
|
192
|
+
*/
|
|
193
|
+
hideSensitiveContent() {
|
|
194
|
+
return this.safeExecute("hideSensitiveContent", StrategyErrorType.APPLICATION, () => {
|
|
195
|
+
if (!this.targetElement || !this.contentManager)
|
|
196
|
+
return;
|
|
197
|
+
this.contentManager.hideContent({
|
|
198
|
+
title: this.options.overlayOptions?.title,
|
|
199
|
+
message: this.options.overlayOptions?.message,
|
|
200
|
+
secondaryMessage: this.options.overlayOptions?.secondaryMessage,
|
|
201
|
+
textColor: "black",
|
|
202
|
+
backgroundColor: "rgba(0, 0, 0, 0.05)",
|
|
203
|
+
});
|
|
204
|
+
this.log("Sensitive content hidden");
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Restore sensitive content when DevTools is closed
|
|
209
|
+
*/
|
|
210
|
+
restoreSensitiveContent() {
|
|
211
|
+
return this.safeExecute("restoreSensitiveContent", StrategyErrorType.REMOVAL, () => {
|
|
212
|
+
if (!this.contentManager)
|
|
213
|
+
return;
|
|
214
|
+
this.contentManager.restoreContent();
|
|
215
|
+
this.log("Sensitive content restored");
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Remove DevTools protection
|
|
220
|
+
*/
|
|
221
|
+
removeDevToolsProtection() {
|
|
222
|
+
return this.safeExecute("removeDevToolsProtection", StrategyErrorType.REMOVAL, () => {
|
|
223
|
+
if (typeof document === "undefined")
|
|
224
|
+
return;
|
|
225
|
+
if (this.options.hideContent) {
|
|
226
|
+
// Restore sensitive content
|
|
227
|
+
this.restoreSensitiveContent();
|
|
228
|
+
}
|
|
229
|
+
if (this.options.showOverlay) {
|
|
230
|
+
// Remove overlay using the overlay manager
|
|
231
|
+
this.overlayManager.removeOverlay();
|
|
232
|
+
}
|
|
233
|
+
this.log("DevTools protection removed");
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Apply the protection strategy
|
|
238
|
+
*/
|
|
239
|
+
apply() {
|
|
240
|
+
return this.safeExecute("apply", StrategyErrorType.APPLICATION, () => {
|
|
241
|
+
if (this.isAppliedFlag) {
|
|
242
|
+
this.log("Protection already applied");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.startMonitoring();
|
|
246
|
+
this.isAppliedFlag = true;
|
|
247
|
+
this.log("Protection applied");
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Remove the protection strategy
|
|
252
|
+
* Override the base implementation to handle additional cleanup
|
|
253
|
+
*/
|
|
254
|
+
remove() {
|
|
255
|
+
return this.safeExecute("remove", StrategyErrorType.REMOVAL, () => {
|
|
256
|
+
if (!this.isAppliedFlag) {
|
|
257
|
+
this.log("Protection not applied");
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
// Clean up the detectors
|
|
261
|
+
if (this.debuggerDetector) {
|
|
262
|
+
this.debuggerDetector.dispose();
|
|
263
|
+
this.debuggerDetector = null;
|
|
264
|
+
}
|
|
265
|
+
if (this.timingDetector) {
|
|
266
|
+
this.timingDetector.dispose();
|
|
267
|
+
this.timingDetector = null;
|
|
268
|
+
}
|
|
269
|
+
if (this.dateToStringDetector) {
|
|
270
|
+
this.dateToStringDetector.dispose();
|
|
271
|
+
this.dateToStringDetector = null;
|
|
272
|
+
}
|
|
273
|
+
this.activeDetector = null;
|
|
274
|
+
// Clear interval via IntervalManager
|
|
275
|
+
if (this.taskId !== null) {
|
|
276
|
+
intervalManager.unregisterTask(this.taskId);
|
|
277
|
+
this.taskId = null;
|
|
278
|
+
this.log("Interval task unregistered");
|
|
279
|
+
}
|
|
280
|
+
// Also clear the old interval for backwards compatibility or if both are used
|
|
281
|
+
if (this.intervalId !== null && typeof window !== "undefined") {
|
|
282
|
+
window.clearInterval(this.intervalId);
|
|
283
|
+
this.intervalId = null;
|
|
284
|
+
this.log("Legacy interval cleared");
|
|
285
|
+
}
|
|
286
|
+
// Call the parent class remove method to handle event cleanup
|
|
287
|
+
super.remove();
|
|
288
|
+
// Remove protections
|
|
289
|
+
this.removeDevToolsProtection();
|
|
290
|
+
this.isAppliedFlag = false;
|
|
291
|
+
this.isDevToolsOpen = false;
|
|
292
|
+
this.log("Protection removed");
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Update DevTools protection options
|
|
297
|
+
* @param options New options
|
|
298
|
+
*/
|
|
299
|
+
updateOptions(options) {
|
|
300
|
+
return this.safeExecute("updateOptions", StrategyErrorType.OPTION_UPDATE, () => {
|
|
301
|
+
const typedOptions = options;
|
|
302
|
+
this.log("Updating options", typedOptions);
|
|
303
|
+
// Store previous options for comparison
|
|
304
|
+
const previousOptions = { ...this.options };
|
|
305
|
+
this.options = {
|
|
306
|
+
...this.options,
|
|
307
|
+
...typedOptions,
|
|
308
|
+
};
|
|
309
|
+
// If protection is already applied, update the overlay if needed
|
|
310
|
+
if (this.isAppliedFlag && this.isDevToolsOpen) {
|
|
311
|
+
// Check if any visual options changed
|
|
312
|
+
const visualOptionsChanged = previousOptions.overlayOptions?.title !== this.options.overlayOptions?.title ||
|
|
313
|
+
previousOptions.overlayOptions?.message !== this.options.overlayOptions?.message ||
|
|
314
|
+
previousOptions.overlayOptions?.secondaryMessage !== this.options.overlayOptions?.secondaryMessage ||
|
|
315
|
+
previousOptions.overlayOptions?.backgroundColor !== this.options.overlayOptions?.backgroundColor ||
|
|
316
|
+
previousOptions.overlayOptions?.textColor !== this.options.overlayOptions?.textColor;
|
|
317
|
+
if (visualOptionsChanged) {
|
|
318
|
+
this.removeDevToolsProtection();
|
|
319
|
+
this.applyDevToolsProtection();
|
|
320
|
+
this.log("Reapplied protection with updated visual options");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// Update check frequency if it changed
|
|
324
|
+
if (typedOptions.checkFrequency &&
|
|
325
|
+
this.taskId !== null &&
|
|
326
|
+
previousOptions.checkFrequency !== typedOptions.checkFrequency) {
|
|
327
|
+
// Unregister and re-register with new frequency
|
|
328
|
+
intervalManager.unregisterTask(this.taskId);
|
|
329
|
+
this.taskId = intervalManager.registerTask("devtools-detection", () => this.safeExecute("intervalTask", StrategyErrorType.APPLICATION, () => {
|
|
330
|
+
// Use active detector
|
|
331
|
+
if (this.activeDetector) {
|
|
332
|
+
this.activeDetector.checkDevTools();
|
|
333
|
+
}
|
|
334
|
+
if (this.isDevToolsOpen) {
|
|
335
|
+
this.overlayManager.checkAndRestoreOverlay();
|
|
336
|
+
}
|
|
337
|
+
}), this.options.checkFrequency);
|
|
338
|
+
this.log(`Check frequency updated to ${this.options.checkFrequency}ms`);
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Set debug mode
|
|
344
|
+
* @param enabled Whether debug mode should be enabled
|
|
345
|
+
*/
|
|
346
|
+
setDebugMode(enabled) {
|
|
347
|
+
return this.safeExecute("setDebugMode", StrategyErrorType.OPTION_UPDATE, () => {
|
|
348
|
+
super.setDebugMode(enabled);
|
|
349
|
+
// Update debug mode for the detectors
|
|
350
|
+
if (this.debuggerDetector) {
|
|
351
|
+
this.debuggerDetector.setDebugMode(enabled);
|
|
352
|
+
}
|
|
353
|
+
if (this.timingDetector) {
|
|
354
|
+
this.timingDetector.setDebugMode(enabled);
|
|
355
|
+
}
|
|
356
|
+
if (this.dateToStringDetector) {
|
|
357
|
+
this.dateToStringDetector.setDebugMode(enabled);
|
|
358
|
+
}
|
|
359
|
+
// Also update debug mode for managers
|
|
360
|
+
if (this.contentManager && this.targetElement) {
|
|
361
|
+
this.contentManager = new ProtectedContentManager(this.targetElement, enabled);
|
|
362
|
+
}
|
|
363
|
+
this.overlayManager = new SecurityOverlayManager(enabled);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { CustomEventHandlers, DevToolsOptions } from "../types";
|
|
2
|
+
import { AbstractStrategy } from "./AbstractStrategy";
|
|
3
|
+
/**
|
|
4
|
+
* Strategy for detecting and responding to DevTools usage
|
|
5
|
+
*/
|
|
6
|
+
export declare class DevToolsStrategy extends AbstractStrategy {
|
|
7
|
+
private intervalId;
|
|
8
|
+
private taskId;
|
|
9
|
+
private initTimeoutId;
|
|
10
|
+
private customHandler?;
|
|
11
|
+
private isDevToolsOpen;
|
|
12
|
+
private targetElement;
|
|
13
|
+
private options;
|
|
14
|
+
private browserInfo;
|
|
15
|
+
private detectorManager;
|
|
16
|
+
/**
|
|
17
|
+
* Create a new DevToolsStrategy
|
|
18
|
+
* @param options Options for customizing the DevTools protection
|
|
19
|
+
* @param targetElement Element containing sensitive content
|
|
20
|
+
* @param customHandler Optional custom handler for DevTools detection
|
|
21
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: DevToolsOptions, targetElement?: HTMLElement | null, customHandler?: CustomEventHandlers["onDevToolsOpen"], debugMode?: boolean);
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the detector manager
|
|
26
|
+
*/
|
|
27
|
+
private initDetectorManager;
|
|
28
|
+
/**
|
|
29
|
+
* Handle DevTools state changes from any detection method
|
|
30
|
+
*/
|
|
31
|
+
private handleDevToolsStateChange;
|
|
32
|
+
/**
|
|
33
|
+
* Start monitoring for DevTools usage
|
|
34
|
+
*/
|
|
35
|
+
private startMonitoring;
|
|
36
|
+
/**
|
|
37
|
+
* Apply the protection strategy
|
|
38
|
+
*/
|
|
39
|
+
apply(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Remove the protection strategy
|
|
42
|
+
* Override the base implementation to handle additional cleanup
|
|
43
|
+
*/
|
|
44
|
+
remove(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Update DevTools protection options
|
|
47
|
+
* @param options New options
|
|
48
|
+
*/
|
|
49
|
+
updateOptions(options: Record<string, unknown>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Set debug mode
|
|
52
|
+
* @param enabled Whether debug mode should be enabled
|
|
53
|
+
*/
|
|
54
|
+
setDebugMode(enabled: boolean): void;
|
|
55
|
+
}
|