New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

output-obfuscator-plugin

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

output-obfuscator-plugin

CLI tool for obfuscating URLs in JavaScript/TypeScript files

latest
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

Output Obfuscator Plugin

CLI 工具,用于混淆 JavaScript/TypeScript 文件中的 URL 字符串。

特性

  • 两种混淆模式:Simple(URL 混淆)和 Advanced(完整混淆)
  • 支持 TypeScript 配置文件
  • 零配置开箱即用
  • 通过 npx 直接运行,无需安装

快速开始

基本使用

直接运行:

npx -y output-obfuscator-plugin@latest ./dist

集成到构建流程

package.json 的 scripts 中添加 postbuild 脚本,构建完成后自动执行混淆:

{
  "scripts": {
    "build": "vite build",
    "postbuild": "npx -y output-obfuscator-plugin@latest ./dist"
  }
}

提示-y 参数让 npx 自动同意安装,适用于 CI/CD 环境(GitHub Actions、GitLab CI 等)。

配置文件(可选)

在项目根目录创建 output_obfuscator.tsoutput_obfuscator.js

// output_obfuscator.ts
import type { CLIConfig } from 'output-obfuscator-plugin'

export default {
  mode: 'simple',
  extensions: ['.js'],
  exclude: ['**/vendor/**'],
  logLevel: 'info'
} satisfies CLIConfig

配置参数

参数类型默认值说明
mode'simple' | 'advanced''simple'混淆模式
extensionsstring[]['.js', '.ts', '.jsx', '.tsx']处理的文件扩展名
excludestring[]['**/node_modules/**']排除的文件 Glob 模式
urlPatternRegExp见下方URL 匹配正则
obfuscatorOptionsObfuscatorOptions-Advanced 模式配置
logLevel'silent' | 'info' | 'debug''info'日志级别

默认 URL 匹配正则

/(?:https?|wss?):\/\/[^\s"'`\)]+/g

混淆模式

Simple 模式

专注于 URL 字符串混淆,随机使用以下三种方式之一:

方式示例
Base64atob("aHR0cHM6Ly9leGFtcGxlLmNvbQ==")
Unicode"\u0068\u0074\u0074\u0070\u0073..."
CharCodesString.fromCharCode(104, 116, 116, 112, ...)

优点:轻量、快速、对代码体积影响小

Advanced 模式

基于 javascript-obfuscator,提供完整的代码混淆功能。

预设级别

预设特性
low字符串数组(50%),紧凑格式
medium控制流扁平化(50%),字符串数组+Base64(75%)
high控制流扁平化(75%),死代码注入(40%),对象键转换,Unicode 转义

配置示例

基础配置

// output_obfuscator.ts
export default {
  mode: 'simple',
  extensions: ['.js'],
  logLevel: 'info'
}

使用 Advanced 模式

// output_obfuscator.ts
export default {
  mode: 'advanced',
  extensions: ['.js'],
  exclude: ['**/vendor/**', '**/lib/**'],
  obfuscatorOptions: {
    preset: 'medium'
  }
}

自定义 obfuscator 配置

// output_obfuscator.ts
export default {
  mode: 'advanced',
  obfuscatorOptions: {
    compact: true,
    controlFlowFlattening: true,
    controlFlowFlatteningThreshold: 0.5,
    stringArray: true,
    stringArrayEncoding: ['base64']
  }
}

完整配置项参考 javascript-obfuscator 文档

自定义 URL 匹配

// output_obfuscator.ts
export default {
  mode: 'simple',
  urlPattern: /https:\/\/api\.[^\s"']+/g  // 只匹配 api. 开头的 URL
}

兼容性

环境版本要求
Node.js>= 18

浏览器环境

  • Simple 模式的 Base64 混淆需要 atob() 支持(IE10+)
  • Unicode 和 CharCodes 方式兼容所有浏览器

注意事项

  • 仅在生产环境使用 - 开发环境启用会影响调试体验
  • 性能影响 - Advanced 模式的 high 预设会显著增加代码体积和执行时间
  • 建议从低级别开始 - 先用 lowmedium 测试,再根据需要提升
  • Source Map - 混淆后 Source Map 将失效

⚠️ 免责声明

本工具仅供学习和测试使用,可能存在未知问题。

使用前请务必:

  • 在测试环境充分验证混淆后的代码功能
  • 确保混淆后的代码运行正常
  • 不要直接在生产环境使用未经验证的混淆代码

作者不对因使用本工具导致的任何问题承担责任。

License

MIT

Keywords

obfuscator

FAQs

Package last updated on 13 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts