feat: 0.1.11 修复第三方hack log方法导致的误伤

This commit is contained in:
tackchen 2021-12-09 08:06:36 +08:00
parent 565593f7c2
commit 62eaa7b87a
16 changed files with 40 additions and 200 deletions

View File

@ -21,7 +21,7 @@ function copyPkg () {
}
function copyFiles () {
gulp.src(['README.md', 'README.cn.md', 'LICENSE', 'src/index.d.ts'], {
gulp.src(['README.md', 'LICENSE', 'src/index.d.ts'], {
allowEmpty: true
})
.pipe(gulp.dest('npm'));

View File

@ -11,5 +11,15 @@
md5='d4de605ccb923b7e876b3218a1474653'
tk-name='tk'
src="../npm/disable-devtool.min.js"></script>
<!-- <script>
DisableDevtool({
ondevtoolopen(t){
debugger
alert(t)
return false
},
url: 'https://www.baidu.com'
})
</script> -->
</body>
</html>

View File

@ -70,4 +70,7 @@
1. Fix the bug of accidental injury in IFrame
## 0.1.10
3. Fix the problem that sizeDetector is accidentally injured in browser zoom mode
1. Fix the problem that sizeDetector is accidentally injured in browser zoom mode
## 0.1.11
1. Fix the accidental injury caused by the third-party hack console.log method

View File

@ -70,4 +70,7 @@
1. 修复IFrame中误伤的bug
## 0.1.10
1. 修复sizeDetector在浏览器缩放模式下误伤的问题
1. 修复sizeDetector在浏览器缩放模式下误伤的问题
## 0.1.11
1. 修复第三方 hack console.log方法 导致的误伤

View File

@ -182,7 +182,7 @@ declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;</code></p>
<script
disable-devtool-auto
md5='1aabac6d068eef6a7bad3fdf50a05cc8'
src='https://cdn.jsdelivr.net/npm/disable-devtool@0.1.10/disable-devtool.min.js#use'
src='https://cdn.jsdelivr.net/npm/disable-devtool@0.1.11/disable-devtool.min.js#use'
></script>
<!-- <script disable-devtool-auto md5='1aabac6d068eef6a7bad3fdf50a05cc8' src='./npm/disable-devtool.min.js'></script> -->
<script>

View File

@ -1,182 +0,0 @@
<h1><a href='https://www.github.com/theajack/disable-devtool'>Disable-devtool</a></h1>
<h2>🚀 一行代码搞定禁用web开发者工具 </h2>
----
<p>
<a href="https://www.github.com/theajack/disable-devtool/stargazers" target="_black">
<img src="https://img.shields.io/github/stars/theajack/disable-devtool?logo=github" alt="stars" />
</a>
<a href="https://www.github.com/theajack/disable-devtool/network/members" target="_black">
<img src="https://img.shields.io/github/forks/theajack/disable-devtool?logo=github" alt="forks" />
</a>
<a href="https://www.npmjs.com/package/disable-devtool" target="_black">
<img src="https://img.shields.io/npm/v/disable-devtool?logo=npm" alt="version" />
</a>
<a href="https://www.npmjs.com/package/disable-devtool" target="_black">
<img src="https://img.shields.io/npm/dm/disable-devtool?color=%23ffca28&logo=npm" alt="downloads" />
</a>
<a href="https://www.jsdelivr.com/package/npm/disable-devtool" target="_black">
<img src="https://data.jsdelivr.com/v1/package/npm/disable-devtool/badge" alt="jsdelivr" />
</a>
<a href="https://github.com/theajack/disable-devtool/issues"><img src="https://img.shields.io/github/issues-closed/theajack/disable-devtool.svg" alt="issue"></a>
</p>
<p>
<a href="https://github.com/theajack" target="_black">
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?&logo=github" alt="author" />
</a>
<a href="https://www.github.com/theajack/disable-devtool/blob/master/LICENSE" target="_black">
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89&logo=github" alt="license" />
</a>
<a href="https://cdn.jsdelivr.net/npm/disable-devtool/disable-devtool.min.js"><img src="https://img.shields.io/bundlephobia/minzip/disable-devtool.svg" alt="Size"></a>
<a href="https://github.com/theajack/disable-devtool/search?l=javascript"><img src="https://img.shields.io/github/languages/top/theajack/disable-devtool.svg" alt="TopLang"></a>
<a href="https://www.github.com/theajack/disable-devtool"><img src="https://img.shields.io/librariesio/dependent-repos/npm/disable-devtool.svg" alt="Dependent"></a>
<a href="https://github.com/theajack/disable-devtool/blob/master/test/test-report.txt"><img src="https://img.shields.io/badge/test-passed-44BB44" alt="test"></a>
</p>
**[English](https://github.com/theajack/disable-devtool/blob/master/README.md) | [在线试用/文档](https://theajack.gitee.io/disable-devtool) | [更新日志](https://github.com/theajack/disable-devtool/blob/master/helper/version.md) | [Gitee](https://gitee.com/theajack/disable-devtool)**
## 1. 快速使用
### 1.1 npm 引用
```
npm i disable-devtool
```
```js
import disableDevtool from 'disable-devtool';
disableDevtool();
```
### 1.2 script属性配置
```html
<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool/disable-devtool.min.js'></script>
```
或者通过版本引用:
```html
<!--使用指定版本-->
<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool@x.x.x/disable-devtool.min.js'></script>
<!--使用最新版本-->
<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool@latest/disable-devtool.min.js'></script>
```
## 2.功能
disable-devtool 可以禁用所有一切可以进入开发者工具的方法,防止通过开发者工具进行的 ‘代码搬运’
该库有以下特性:
1. 支持可配置是否禁用右键菜单
2. 禁用 f12 和 ctrl+shift+i 快捷键
3. 支持识别从浏览器菜单栏打开开发者工具并关闭当前页面
4. 开发者可以绕过禁用 (url参数使用tk配合md5加密)
5. 多种监测模式支持几乎所有浏览器IE,360,qq浏览器,FireFox,Chrome,Edge...
6. 高度可配置
7. 使用极简、体积小巧 (仅7kb)
8. 支持npm引用和script标签引用(属性配置)
9. 识别真移动端与浏览器开发者工具设置插件伪造的移动端,为移动端节省性能
## 3. 使用
### 3.1 npm使用时的配置参数
安装 disable-devtool
```
npm i disable-devtool
```
```js
import disableDevtool from 'disable-devtool';
disableDevtool(options);
```
options中的参数与说明如下
```ts
declare interface optionStatic {
md5?: string; // 绕过禁用的md5值详情见3.2,默认不启用绕过禁用
url?: string; // 关闭页面失败时的跳转页面默认值为localhost
tkName?: string; // 绕过禁用时的url参数名称默认为 ddtk
ondevtoolopen?(type: DetectorType): void; // 开发者面板打开的回调启用时url参数无效type 为监测模式详见3.5
interval?: number; // 定时器的时间间隔 默认200ms
disableMenu?: boolean; // 是否禁用右键菜单 默认为true
stopIntervalTime?: number; // 在移动端时取消监视的等待时长
clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控 默认为false
detactors?: Array<DETECTOR_TYPE>; // 启用的检测器 检测器详情见 3.5 默认为全部,建议使用全部
}
declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3 | 4; // 检测器详情见 3.5
```
### 3.2 md5 与 tk 绕过禁用
该库中使用 key 与 md5 配合的方式使得开发者可以在线上绕过禁用。
流程如下:
先指定一个 key a该值不要记录在代码中使用 md5 加密得到一个值 b将b作为 md5 参数传入,开发者在访问 url 的时候只需要带上url参数 ddtk=a便可以绕过禁用。
disableDevtool对象暴露了 md5 方法,可供开发者加密时使用:
```js
disableDevtool.md5('xxx');
```
### 3.3 script使用属性配置
```html
<script
disable-devtool-auto
src='https://cdn.jsdelivr.net/npm/disable-devtool/disable-devtool.min.js'
md5='xxx'
url='xxx'
tk-name='xxx'
interval='xxx'
disable-menu='xxx'
detectors='xxx'
></script>
```
注:
1. 如希望自动禁用,属性配置时必须要带上 `disable-devtool-auto` 属性
2. 属性配置都是可选的字段与3.1中一致,区别是将驼峰形式改成横线分割
3. 该script标签建议放在body最底部
4. detectors 需要使用空格分割,如 detectors='1 2 3'
### 3.4 script不使用属性配置
```html
<script src='https://cdn.jsdelivr.net/npm/disable-devtool/disable-devtool.min.js'></script>
<script>
DisableDevtool({
// 参数与3.1中一致
})
</script>
```
### 3.5 监测模式
Disable-Devtool 有五种监测模式, DisableDevtool.DETECTOR_TYPE 为所有的监测模式枚举
```js
const DETECTOR_TYPE = {
UNKONW: -1,
REG_TO_STRING: 0, // 根据正则检测
DEFINE_ID: 1, // 根据dom id检测
SIZE: 2, // 根据窗口尺寸检测
DATE_TO_STRING: 3, // 根据Date.toString 检测
FUNC_TO_STRING: 4, // 根据Function.toString 检测
}
```
ondevtoolopen 事件的回调参数就是被触发的监测模式

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "disable-devtool",
"version": "0.1.10",
"version": "0.1.11",
"description": "Disable web developer tools from the f12 button, right-click and browser ",
"main": "disable-devtool.min.js",
"unpkg": "disable-devtool.min.js",

View File

@ -1,6 +1,6 @@
{
"name": "disable-devtool",
"version": "0.1.10",
"version": "0.1.11",
"description": "Disable web developer tools from the f12 button, right-click and browser ",
"main": "disable-devtool.min.js",
"unpkg": "disable-devtool.min.js",

View File

@ -9,6 +9,7 @@
import {registInterval} from '../interval';
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
import {log} from '../util';
export default function detector () {
let count = 0;
@ -20,7 +21,7 @@ export default function detector () {
const checkIsOpen = () => {
count = 0;
console.log(date);
log(date);
console.clear();
if (count >= 2) {
triggerOnDevOpen(DETECTOR_TYPE.DATE_TO_STRING);

View File

@ -7,6 +7,7 @@
*/
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
import {registInterval} from '../interval';
import {log} from '../util';
export default function detector () {
const div = document.createElement('div');
@ -19,6 +20,6 @@ export default function detector () {
},
});
registInterval(() => {
console.log(div);
log(div);
});
}

View File

@ -9,6 +9,7 @@
import {registInterval} from '../interval';
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
import {log} from '../util';
export default function detector () {
let count = 0;
@ -20,7 +21,7 @@ export default function detector () {
const checkIsOpen = () => {
count = 0;
console.log(func);
log(func);
console.clear();
if (count >= 2) {
triggerOnDevOpen(DETECTOR_TYPE.FUNC_TO_STRING);

View File

@ -2,17 +2,18 @@
* @Author: theajack
* @Date: 2021-07-24 23:15:22
* @LastEditor: theajack
* @LastEditTime: 2021-07-26 10:42:58
* @LastEditTime: 2021-12-09 08:00:47
* @Description: Coding something
*/
// import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
// import {registInterval} from '../interval';
// import {log} from '../util';
// function logTime () {
// const d = new Date();
// for (let i = 0; i < 2000; i++) {
// console.log(1);
// log(1);
// }
// console.clear();
// if (new Date() - d > 100) {

View File

@ -2,12 +2,12 @@
* @Author: theajack
* @Date: 2021-07-24 23:15:01
* @LastEditor: theajack
* @LastEditTime: 2021-11-15 22:26:29
* @LastEditTime: 2021-12-09 07:58:29
* @Description: Coding something
*/
import {registInterval} from '../interval';
import {isFirefox, isQQBrowser} from '../util';
import {isFirefox, isQQBrowser, log} from '../util';
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
// 这个方法在chrome 中无论是否打开都会触发
@ -17,7 +17,7 @@ export default function detector () {
if (!isQQ && !isFF) return;
let lastTime = 0;
const reg = /./;
console.log(reg);
log(reg);
reg.toString = function () {
if (isQQ) { // ! qq浏览器在控制台没有打开的时候也会触发 打开的时候会连续触发两次 使用这个来判断
const time = new Date().getTime();
@ -33,6 +33,6 @@ export default function detector () {
};
registInterval(() => {
console.log(reg);
log(reg);
});
}

View File

@ -129,4 +129,6 @@ export function isInIframe () {
} catch (e) {
return true;
}
}
}
export const log = console.log;

View File

@ -1 +1 @@
export default '0.1.10';
export default '0.1.11';