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,106 @@
|
|
|
1
|
+
import { SimpleLoggingService } from "../../../utils/logging/simple/SimpleLoggingService";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for all event handlers
|
|
4
|
+
*/
|
|
5
|
+
export class AbstractEventHandler {
|
|
6
|
+
/**
|
|
7
|
+
* Create a new event handler
|
|
8
|
+
* @param mediator The protection mediator
|
|
9
|
+
* @param componentName The name of the component
|
|
10
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
11
|
+
*/
|
|
12
|
+
constructor(mediator, componentName, debugMode = false) {
|
|
13
|
+
this.subscriptionIds = [];
|
|
14
|
+
this.mediator = mediator;
|
|
15
|
+
this.COMPONENT_NAME = componentName;
|
|
16
|
+
this.debugMode = debugMode;
|
|
17
|
+
// Create a logger instance for this component
|
|
18
|
+
this.logger = new SimpleLoggingService(componentName, debugMode);
|
|
19
|
+
this.initialize();
|
|
20
|
+
if (this.debugMode) {
|
|
21
|
+
this.log("Initialized and subscribed to events");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Set debug mode
|
|
26
|
+
* @param enabled Whether debug mode should be enabled
|
|
27
|
+
*/
|
|
28
|
+
setDebugMode(enabled) {
|
|
29
|
+
this.debugMode = enabled;
|
|
30
|
+
this.logger.setDebugMode(enabled);
|
|
31
|
+
if (this.debugMode) {
|
|
32
|
+
this.log(`Debug mode ${enabled ? "enabled" : "disabled"}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Subscribe to an event and track the subscription ID
|
|
37
|
+
* @param eventType The event type to subscribe to
|
|
38
|
+
* @param handler The event handler function
|
|
39
|
+
* @param options Optional subscription options
|
|
40
|
+
* @returns The subscription ID
|
|
41
|
+
*/
|
|
42
|
+
subscribe(eventType, handler, options) {
|
|
43
|
+
const subId = this.mediator.subscribe(eventType, handler, {
|
|
44
|
+
...options,
|
|
45
|
+
context: options?.context || this.COMPONENT_NAME,
|
|
46
|
+
});
|
|
47
|
+
this.subscriptionIds.push(subId);
|
|
48
|
+
if (this.debugMode) {
|
|
49
|
+
this.log(`Subscribed to ${eventType} with ID ${subId}`);
|
|
50
|
+
}
|
|
51
|
+
return subId;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Log a debug message if debug mode is enabled
|
|
55
|
+
* @param message Message to log
|
|
56
|
+
* @param args Additional arguments to log
|
|
57
|
+
*/
|
|
58
|
+
log(message, ...args) {
|
|
59
|
+
if (this.debugMode) {
|
|
60
|
+
this.logger.log(message, ...args);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Log a warning message
|
|
65
|
+
* @param message Warning message
|
|
66
|
+
* @param args Additional arguments to log
|
|
67
|
+
*/
|
|
68
|
+
warn(message, ...args) {
|
|
69
|
+
if (this.debugMode) {
|
|
70
|
+
this.logger.warn(message, ...args);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// In non-debug mode, only log the message without args for brevity
|
|
74
|
+
console.warn(`${this.COMPONENT_NAME}: ${message}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Log an error message
|
|
79
|
+
* @param message Error message
|
|
80
|
+
* @param args Additional arguments to log
|
|
81
|
+
*/
|
|
82
|
+
error(message, ...args) {
|
|
83
|
+
this.logger.error(message, ...args);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Unsubscribe from all events and clean up
|
|
87
|
+
*/
|
|
88
|
+
dispose() {
|
|
89
|
+
if (this.debugMode) {
|
|
90
|
+
this.log(`Disposing handler, unsubscribing from ${this.subscriptionIds.length} events`);
|
|
91
|
+
}
|
|
92
|
+
// Unsubscribe from all events
|
|
93
|
+
for (const id of this.subscriptionIds) {
|
|
94
|
+
this.mediator.unsubscribe(id);
|
|
95
|
+
}
|
|
96
|
+
this.subscriptionIds = [];
|
|
97
|
+
this.onDispose();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Additional cleanup to be performed on disposal
|
|
101
|
+
* This method can be overridden by subclasses
|
|
102
|
+
*/
|
|
103
|
+
onDispose() {
|
|
104
|
+
// Default implementation does nothing
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ProtectionMediator } from "../../mediator/types";
|
|
2
|
+
import type { ProtectionEvent, ProtectionEventType } from "../../mediator/protection-event";
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base class for all event handlers
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseEventHandler {
|
|
7
|
+
protected mediator: ProtectionMediator;
|
|
8
|
+
protected readonly COMPONENT_NAME: string;
|
|
9
|
+
protected debugMode: boolean;
|
|
10
|
+
protected subscriptionIds: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Create a new event handler
|
|
13
|
+
* @param mediator The protection mediator
|
|
14
|
+
* @param componentName The name of the component
|
|
15
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
16
|
+
*/
|
|
17
|
+
constructor(mediator: ProtectionMediator, componentName: string, debugMode?: boolean);
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the handler and subscribe to events
|
|
20
|
+
* This method should be implemented by subclasses
|
|
21
|
+
*/
|
|
22
|
+
protected abstract initialize(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Log a debug message
|
|
25
|
+
* @param message Message to log
|
|
26
|
+
* @param args Additional arguments to log
|
|
27
|
+
*/
|
|
28
|
+
protected log(message: string, ...args: unknown[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Log a warning message
|
|
31
|
+
* @param message Warning message
|
|
32
|
+
* @param args Additional arguments to log
|
|
33
|
+
*/
|
|
34
|
+
protected warn(message: string, ...args: unknown[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Log an error message
|
|
37
|
+
* @param message Error message
|
|
38
|
+
* @param args Additional arguments to log
|
|
39
|
+
*/
|
|
40
|
+
protected error(message: string, ...args: unknown[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* Set debug mode
|
|
43
|
+
* @param enabled Whether debug mode should be enabled
|
|
44
|
+
*/
|
|
45
|
+
setDebugMode(enabled: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* Subscribe to an event and track the subscription ID
|
|
48
|
+
* @param eventType The event type to subscribe to
|
|
49
|
+
* @param handler The event handler function
|
|
50
|
+
* @param options Optional subscription options
|
|
51
|
+
* @returns The subscription ID
|
|
52
|
+
*/
|
|
53
|
+
protected subscribe(eventType: ProtectionEventType, handler: (event: ProtectionEvent) => void, options?: {
|
|
54
|
+
context?: string;
|
|
55
|
+
}): string;
|
|
56
|
+
/**
|
|
57
|
+
* Unsubscribe from all events and clean up
|
|
58
|
+
*/
|
|
59
|
+
dispose(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Additional cleanup to be performed on disposal
|
|
62
|
+
* This method can be overridden by subclasses
|
|
63
|
+
*/
|
|
64
|
+
protected onDispose(): void;
|
|
65
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all event handlers
|
|
3
|
+
*/
|
|
4
|
+
export class BaseEventHandler {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new event handler
|
|
7
|
+
* @param mediator The protection mediator
|
|
8
|
+
* @param componentName The name of the component
|
|
9
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
10
|
+
*/
|
|
11
|
+
constructor(mediator, componentName, debugMode = false) {
|
|
12
|
+
this.subscriptionIds = [];
|
|
13
|
+
this.mediator = mediator;
|
|
14
|
+
this.COMPONENT_NAME = componentName;
|
|
15
|
+
this.debugMode = debugMode;
|
|
16
|
+
this.initialize();
|
|
17
|
+
if (this.debugMode) {
|
|
18
|
+
this.log("Initialized and subscribed to events");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Log a debug message
|
|
23
|
+
* @param message Message to log
|
|
24
|
+
* @param args Additional arguments to log
|
|
25
|
+
*/
|
|
26
|
+
log(message, ...args) {
|
|
27
|
+
if (this.debugMode) {
|
|
28
|
+
console.log(`${this.COMPONENT_NAME}: ${message}`, ...args);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Log a warning message
|
|
33
|
+
* @param message Warning message
|
|
34
|
+
* @param args Additional arguments to log
|
|
35
|
+
*/
|
|
36
|
+
warn(message, ...args) {
|
|
37
|
+
if (this.debugMode) {
|
|
38
|
+
console.warn(`${this.COMPONENT_NAME}: ${message}`, ...args);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// In non-debug mode, only log the message without args for brevity
|
|
42
|
+
console.warn(`${this.COMPONENT_NAME}: ${message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Log an error message
|
|
47
|
+
* @param message Error message
|
|
48
|
+
* @param args Additional arguments to log
|
|
49
|
+
*/
|
|
50
|
+
error(message, ...args) {
|
|
51
|
+
console.error(`${this.COMPONENT_NAME}: ${message}`, ...args);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Set debug mode
|
|
55
|
+
* @param enabled Whether debug mode should be enabled
|
|
56
|
+
*/
|
|
57
|
+
setDebugMode(enabled) {
|
|
58
|
+
this.debugMode = enabled;
|
|
59
|
+
if (this.debugMode) {
|
|
60
|
+
this.log(`Debug mode ${enabled ? "enabled" : "disabled"}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Subscribe to an event and track the subscription ID
|
|
65
|
+
* @param eventType The event type to subscribe to
|
|
66
|
+
* @param handler The event handler function
|
|
67
|
+
* @param options Optional subscription options
|
|
68
|
+
* @returns The subscription ID
|
|
69
|
+
*/
|
|
70
|
+
subscribe(eventType, handler, options) {
|
|
71
|
+
const subId = this.mediator.subscribe(eventType, handler, { ...options, context: options?.context || this.COMPONENT_NAME });
|
|
72
|
+
this.subscriptionIds.push(subId);
|
|
73
|
+
if (this.debugMode) {
|
|
74
|
+
this.log(`Subscribed to ${eventType} with ID ${subId}`);
|
|
75
|
+
}
|
|
76
|
+
return subId;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Unsubscribe from all events and clean up
|
|
80
|
+
*/
|
|
81
|
+
dispose() {
|
|
82
|
+
if (this.debugMode) {
|
|
83
|
+
this.log(`Disposing handler, unsubscribing from ${this.subscriptionIds.length} events`);
|
|
84
|
+
}
|
|
85
|
+
// Unsubscribe from all events
|
|
86
|
+
for (const id of this.subscriptionIds) {
|
|
87
|
+
this.mediator.unsubscribe(id);
|
|
88
|
+
}
|
|
89
|
+
this.subscriptionIds = [];
|
|
90
|
+
this.onDispose();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Additional cleanup to be performed on disposal
|
|
94
|
+
* This method can be overridden by subclasses
|
|
95
|
+
*/
|
|
96
|
+
onDispose() {
|
|
97
|
+
// Default implementation does nothing
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProtectionMediator } from "../types";
|
|
2
|
+
import { AbstractEventHandler } from "./abstractEventHandler";
|
|
3
|
+
export declare class DevToolsEventHandler extends AbstractEventHandler {
|
|
4
|
+
constructor(mediator: ProtectionMediator, debugMode?: boolean);
|
|
5
|
+
protected initialize(): void;
|
|
6
|
+
private handleDevToolsStateChange;
|
|
7
|
+
private handleDevToolsOpened;
|
|
8
|
+
private handleDevToolsClosed;
|
|
9
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ProtectionEventType } from "../protection-event";
|
|
2
|
+
import { isEventType } from "../eventDataTypes";
|
|
3
|
+
import { AbstractEventHandler } from "./abstractEventHandler";
|
|
4
|
+
export class DevToolsEventHandler extends AbstractEventHandler {
|
|
5
|
+
constructor(mediator, debugMode = false) {
|
|
6
|
+
super(mediator, "DevToolsEventHandler", debugMode);
|
|
7
|
+
}
|
|
8
|
+
initialize() {
|
|
9
|
+
this.subscribe(ProtectionEventType.DEVTOOLS_STATE_CHANGE, this.handleDevToolsStateChange.bind(this));
|
|
10
|
+
}
|
|
11
|
+
handleDevToolsStateChange(event) {
|
|
12
|
+
// Use type guard for type-safe access
|
|
13
|
+
if (!isEventType(event, ProtectionEventType.DEVTOOLS_STATE_CHANGE)) {
|
|
14
|
+
this.error("Received invalid event type");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.log(`Handling DevTools state change, isOpen=${event.data.isOpen}`);
|
|
18
|
+
if (event.data.isOpen) {
|
|
19
|
+
this.handleDevToolsOpened(event);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.handleDevToolsClosed(event);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
handleDevToolsOpened(event) {
|
|
26
|
+
const { data } = event;
|
|
27
|
+
// Show overlay if showOverlay is enabled (defaults to true)
|
|
28
|
+
if (data.showOverlay !== false) {
|
|
29
|
+
this.mediator.publish({
|
|
30
|
+
type: ProtectionEventType.OVERLAY_SHOWN,
|
|
31
|
+
source: this.COMPONENT_NAME,
|
|
32
|
+
timestamp: Date.now(),
|
|
33
|
+
data: {
|
|
34
|
+
strategyName: this.COMPONENT_NAME,
|
|
35
|
+
overlayType: "devtools",
|
|
36
|
+
options: {
|
|
37
|
+
...data.overlayOptions,
|
|
38
|
+
blockEvents: true,
|
|
39
|
+
autoRestore: true,
|
|
40
|
+
},
|
|
41
|
+
priority: 10,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Only hide content if hideContent option is explicitly enabled
|
|
46
|
+
if (data.hideContent === true) {
|
|
47
|
+
this.mediator.publish({
|
|
48
|
+
type: ProtectionEventType.CONTENT_HIDDEN,
|
|
49
|
+
source: this.COMPONENT_NAME,
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
data: {
|
|
52
|
+
strategyName: this.COMPONENT_NAME,
|
|
53
|
+
reason: "devtools_opened",
|
|
54
|
+
options: {
|
|
55
|
+
title: data.overlayOptions?.title,
|
|
56
|
+
message: data.overlayOptions?.message,
|
|
57
|
+
secondaryMessage: data.overlayOptions?.secondaryMessage,
|
|
58
|
+
textColor: 'black',
|
|
59
|
+
backgroundColor: data.overlayOptions?.backgroundColor,
|
|
60
|
+
},
|
|
61
|
+
targetElement: data.target,
|
|
62
|
+
priority: 10,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
handleDevToolsClosed(event) {
|
|
68
|
+
const { data } = event;
|
|
69
|
+
// Remove overlay if showOverlay was enabled
|
|
70
|
+
if (data.showOverlay !== false) {
|
|
71
|
+
this.mediator.publish({
|
|
72
|
+
type: ProtectionEventType.OVERLAY_REMOVED,
|
|
73
|
+
source: this.COMPONENT_NAME,
|
|
74
|
+
timestamp: Date.now(),
|
|
75
|
+
data: {
|
|
76
|
+
strategyName: this.COMPONENT_NAME,
|
|
77
|
+
overlayType: "devtools",
|
|
78
|
+
reason: "devtools_closed",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// Only restore content if hideContent was explicitly enabled
|
|
83
|
+
if (data.hideContent === true) {
|
|
84
|
+
this.mediator.publish({
|
|
85
|
+
type: ProtectionEventType.CONTENT_RESTORED,
|
|
86
|
+
source: this.COMPONENT_NAME,
|
|
87
|
+
timestamp: Date.now(),
|
|
88
|
+
data: {
|
|
89
|
+
strategyName: this.COMPONENT_NAME,
|
|
90
|
+
targetElement: data.target,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProtectionMediator } from "../types";
|
|
2
|
+
export declare class HandlerRegistry {
|
|
3
|
+
private handlers;
|
|
4
|
+
private mediator;
|
|
5
|
+
private debugMode;
|
|
6
|
+
constructor(mediator: ProtectionMediator, debugMode?: boolean);
|
|
7
|
+
private initializeHandlers;
|
|
8
|
+
setDebugMode(enabled: boolean): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DevToolsEventHandler } from "./devToolsEventHandler";
|
|
2
|
+
import { BrowserExtensionEventHandler } from "./extensionEventHandlers";
|
|
3
|
+
import { FrameEmbeddingEventHandler } from "./iFrameEventHandlers";
|
|
4
|
+
import { ScreenshotEventHandler } from "./screenShotEventHandlers";
|
|
5
|
+
export class HandlerRegistry {
|
|
6
|
+
constructor(mediator, debugMode = false) {
|
|
7
|
+
this.handlers = {};
|
|
8
|
+
this.mediator = mediator;
|
|
9
|
+
this.debugMode = debugMode;
|
|
10
|
+
this.initializeHandlers();
|
|
11
|
+
}
|
|
12
|
+
initializeHandlers() {
|
|
13
|
+
// Initialize all handlers
|
|
14
|
+
this.handlers.devTools = new DevToolsEventHandler(this.mediator, this.debugMode);
|
|
15
|
+
this.handlers.extension = new BrowserExtensionEventHandler(this.mediator, this.debugMode);
|
|
16
|
+
this.handlers.screenshot = new ScreenshotEventHandler(this.mediator, this.debugMode);
|
|
17
|
+
this.handlers.iFrame = new FrameEmbeddingEventHandler(this.mediator, this.debugMode);
|
|
18
|
+
// Add more handlers as you implement them
|
|
19
|
+
// this.handlers.screenshot = new ScreenshotEventHandler(this.mediator, this.debugMode);
|
|
20
|
+
// this.handlers.frameEmbedding = new FrameEmbeddingEventHandler(this.mediator, this.debugMode);
|
|
21
|
+
if (this.debugMode) {
|
|
22
|
+
console.log("HandlerRegistry: Initialized all event handlers");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
setDebugMode(enabled) {
|
|
26
|
+
this.debugMode = enabled;
|
|
27
|
+
// Update debug mode for all handlers
|
|
28
|
+
Object.values(this.handlers).forEach(handler => {
|
|
29
|
+
if (typeof handler.setDebugMode === 'function') {
|
|
30
|
+
handler.setDebugMode(enabled);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ProtectionMediator } from "../types";
|
|
2
|
+
import { ProtectionEvent, ProtectionEventType } from "../protection-event";
|
|
3
|
+
import { TypedProtectionEvent } from "../eventDataTypes";
|
|
4
|
+
import { AbstractEventHandler } from "./abstractEventHandler";
|
|
5
|
+
type ExtensionDetectedEvent = TypedProtectionEvent<typeof ProtectionEventType.EXTENSION_DETECTED>;
|
|
6
|
+
/**
|
|
7
|
+
* Handler for browser extension detection events
|
|
8
|
+
*/
|
|
9
|
+
export declare class BrowserExtensionEventHandler extends AbstractEventHandler {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new BrowserExtensionEventHandler
|
|
12
|
+
* @param mediator The protection mediator
|
|
13
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
14
|
+
*/
|
|
15
|
+
constructor(mediator: ProtectionMediator, debugMode?: boolean);
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the handler and subscribe to events
|
|
18
|
+
*/
|
|
19
|
+
protected initialize(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Handle extension detection
|
|
22
|
+
* @param event the ProtectionEvent
|
|
23
|
+
*/
|
|
24
|
+
handleExtensionDetected(event: ProtectionEvent): void;
|
|
25
|
+
/**
|
|
26
|
+
* Handle extension detection
|
|
27
|
+
* @param event the typed ExtensionDetectedEvent
|
|
28
|
+
*/
|
|
29
|
+
applyExtensionProtection(event: ExtensionDetectedEvent): void;
|
|
30
|
+
/**
|
|
31
|
+
* Remove extension protection
|
|
32
|
+
* @param event The typed ExtensionDetectedEvent
|
|
33
|
+
*/
|
|
34
|
+
removeExtensionProtection(event: ExtensionDetectedEvent): void;
|
|
35
|
+
/**
|
|
36
|
+
* Additional cleanup to be performed on disposal
|
|
37
|
+
*/
|
|
38
|
+
protected onDispose(): void;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ProtectionEventType } from "../protection-event";
|
|
2
|
+
import { isEventType } from "../eventDataTypes";
|
|
3
|
+
import { AbstractEventHandler } from "./abstractEventHandler";
|
|
4
|
+
/**
|
|
5
|
+
* Handler for browser extension detection events
|
|
6
|
+
*/
|
|
7
|
+
export class BrowserExtensionEventHandler extends AbstractEventHandler {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new BrowserExtensionEventHandler
|
|
10
|
+
* @param mediator The protection mediator
|
|
11
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
12
|
+
*/
|
|
13
|
+
constructor(mediator, debugMode = false) {
|
|
14
|
+
super(mediator, "BrowserExtensionEventHandler", debugMode);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the handler and subscribe to events
|
|
18
|
+
*/
|
|
19
|
+
initialize() {
|
|
20
|
+
this.subscribe(ProtectionEventType.EXTENSION_DETECTED, this.handleExtensionDetected.bind(this));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Handle extension detection
|
|
24
|
+
* @param event the ProtectionEvent
|
|
25
|
+
*/
|
|
26
|
+
handleExtensionDetected(event) {
|
|
27
|
+
// Use type guard for type-safe access
|
|
28
|
+
if (!isEventType(event, ProtectionEventType.EXTENSION_DETECTED)) {
|
|
29
|
+
this.error("Received invalid event type");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const { data } = event;
|
|
33
|
+
this.log(`Handling extension detection state change, name=${data.extension?.name || "unknown"}`);
|
|
34
|
+
if (data.extension) {
|
|
35
|
+
this.applyExtensionProtection(event);
|
|
36
|
+
this.log("Blocking interface due to extension detection");
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.removeExtensionProtection(event);
|
|
40
|
+
this.log("Unlocking interface after extension removal");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Handle extension detection
|
|
45
|
+
* @param event the typed ExtensionDetectedEvent
|
|
46
|
+
*/
|
|
47
|
+
applyExtensionProtection(event) {
|
|
48
|
+
const { data } = event;
|
|
49
|
+
if (data.hideContent) {
|
|
50
|
+
this.mediator.publish({
|
|
51
|
+
type: ProtectionEventType.CONTENT_HIDDEN,
|
|
52
|
+
source: this.COMPONENT_NAME,
|
|
53
|
+
timestamp: Date.now(),
|
|
54
|
+
data: {
|
|
55
|
+
strategyName: this.COMPONENT_NAME,
|
|
56
|
+
reason: "extension_detected",
|
|
57
|
+
targetElement: data.target,
|
|
58
|
+
options: {
|
|
59
|
+
title: data.overlayOptions?.title,
|
|
60
|
+
message: data.overlayOptions?.message,
|
|
61
|
+
secondaryMessage: `"${data.extension?.name}" triggered this warning`,
|
|
62
|
+
textColor: "black",
|
|
63
|
+
backgroundColor: "rgba(0, 0, 0, 0.05)",
|
|
64
|
+
},
|
|
65
|
+
priority: 8,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (data.showOverlay) {
|
|
70
|
+
const extensionConfig = data.extension;
|
|
71
|
+
const additionalContent = `
|
|
72
|
+
<p style="font-size: 18px; margin-top: 20px;">Detected: ${extensionConfig.name}</p>
|
|
73
|
+
<p style="font-size: 14px; margin-top: 10px;">Risk Level: ${extensionConfig.risk.toUpperCase()}</p>
|
|
74
|
+
<button id="extension-protection-close" style="margin-top: 20px; padding: 10px 20px; background-color: white; color: black; border: none; border-radius: 4px; cursor: pointer; pointer-events: auto;">
|
|
75
|
+
I've Disabled the Extension
|
|
76
|
+
</button>
|
|
77
|
+
`;
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
const closeButton = document.getElementById("extension-protection-close");
|
|
80
|
+
if (closeButton) {
|
|
81
|
+
closeButton.addEventListener("click", () => {
|
|
82
|
+
window.location.reload();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, 0);
|
|
86
|
+
this.mediator.publish({
|
|
87
|
+
type: ProtectionEventType.OVERLAY_SHOWN,
|
|
88
|
+
source: this.COMPONENT_NAME,
|
|
89
|
+
timestamp: Date.now(),
|
|
90
|
+
data: {
|
|
91
|
+
strategyName: this.COMPONENT_NAME,
|
|
92
|
+
overlayType: "extension",
|
|
93
|
+
options: {
|
|
94
|
+
...data.overlayOptions,
|
|
95
|
+
blockEvents: true,
|
|
96
|
+
autoRestore: true,
|
|
97
|
+
additionalContent,
|
|
98
|
+
},
|
|
99
|
+
priority: 8,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Remove extension protection
|
|
106
|
+
* @param event The typed ExtensionDetectedEvent
|
|
107
|
+
*/
|
|
108
|
+
removeExtensionProtection(event) {
|
|
109
|
+
const { data } = event;
|
|
110
|
+
if (data.hideContent) {
|
|
111
|
+
this.mediator.publish({
|
|
112
|
+
type: ProtectionEventType.CONTENT_RESTORED,
|
|
113
|
+
source: this.COMPONENT_NAME,
|
|
114
|
+
timestamp: Date.now(),
|
|
115
|
+
data: {
|
|
116
|
+
strategyName: this.COMPONENT_NAME,
|
|
117
|
+
targetElement: data.target,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (data.showOverlay) {
|
|
122
|
+
this.mediator.publish({
|
|
123
|
+
type: ProtectionEventType.OVERLAY_REMOVED,
|
|
124
|
+
source: this.COMPONENT_NAME,
|
|
125
|
+
timestamp: Date.now(),
|
|
126
|
+
data: {
|
|
127
|
+
strategyName: this.COMPONENT_NAME,
|
|
128
|
+
overlayType: "extension",
|
|
129
|
+
reason: "extension_removed",
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Additional cleanup to be performed on disposal
|
|
136
|
+
*/
|
|
137
|
+
onDispose() {
|
|
138
|
+
// No additional cleanup needed for this handler
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ProtectionMediator } from "../../mediator/types";
|
|
2
|
+
import { type ProtectionEvent } from "../../mediator/protection-event";
|
|
3
|
+
import { AbstractEventHandler } from "./abstractEventHandler";
|
|
4
|
+
/**
|
|
5
|
+
* Handler for frame embedding events
|
|
6
|
+
*/
|
|
7
|
+
export declare class FrameEmbeddingEventHandler extends AbstractEventHandler {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new FrameEmbeddingEventHandler
|
|
10
|
+
* @param mediator The protection mediator
|
|
11
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
12
|
+
*/
|
|
13
|
+
constructor(mediator: ProtectionMediator, debugMode?: boolean);
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the handler and set up event subscriptions
|
|
16
|
+
*/
|
|
17
|
+
protected initialize(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Handle frame embedding detection event
|
|
20
|
+
* @param event The protection event containing frame embedding data
|
|
21
|
+
*/
|
|
22
|
+
handleFrameEmbeddingDetected(event: ProtectionEvent): void;
|
|
23
|
+
/**
|
|
24
|
+
* Clean up resources when the handler is disposed
|
|
25
|
+
*/
|
|
26
|
+
protected onDispose(): void;
|
|
27
|
+
}
|