-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlockdown.js
More file actions
60 lines (52 loc) · 1.94 KB
/
lockdown.js
File metadata and controls
60 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
window.SecurityLockdown = function (options = {}) {
const defaults = {
disableRightClick: true,
disableF12: true,
disableCtrlShiftI: true,
disableCtrlShiftC: true,
disableCtrlShiftJ: true,
disableCtrlU: true,
logAttempts: true
};
const settings = { ...defaults, ...options };
if (settings.disableRightClick) {
document.addEventListener('contextmenu', function (e) {
e.preventDefault();
if (settings.logAttempts) {
console.error("Right-click attempt mitigated.");
}
});
}
document.addEventListener('keydown', function (e) {
if (settings.disableF12 && e.keyCode == 123) {
e.preventDefault();
if (settings.logAttempts) {
console.error("Inspect element attempt mitigated (F12).");
}
}
if (settings.disableCtrlShiftI && e.ctrlKey && e.shiftKey && e.keyCode == 73) {
e.preventDefault();
if (settings.logAttempts) {
console.error("Inspect element attempt mitigated (Ctrl+Shift+I).");
}
}
if (settings.disableCtrlShiftC && e.ctrlKey && e.shiftKey && e.keyCode == 67) {
e.preventDefault();
if (settings.logAttempts) {
console.error("Inspect element attempt mitigated (Ctrl+Shift+C).");
}
}
if (settings.disableCtrlShiftJ && e.ctrlKey && e.shiftKey && e.keyCode == 74) {
e.preventDefault();
if (settings.logAttempts) {
console.error("Console attempt mitigated (Ctrl+Shift+J).");
}
}
if (settings.disableCtrlU && e.ctrlKey && e.keyCode == 85) {
e.preventDefault();
if (settings.logAttempts) {
console.error("View page source attempt mitigated (Ctrl+U).");
}
}
});
};