vite-plugin-vue-security 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/README.md +87 -0
- package/index.js +179 -0
- package/package.json +37 -0
- package/vite.config.example.js +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Vite Plugin Vue Security
|
|
2
|
+
|
|
3
|
+
A Vite plugin that performs security scans on Vue.js projects during the build process. This plugin integrates the Vue Security Scanner directly into your Vite build pipeline, allowing you to detect security vulnerabilities in real-time during development and build.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install vite-plugin-vue-security --save-dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
// vite.config.js
|
|
17
|
+
import { defineConfig } from 'vite';
|
|
18
|
+
import vue from '@vitejs/plugin-vue';
|
|
19
|
+
import vueSecurityPlugin from 'vite-plugin-vue-security';
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [
|
|
23
|
+
vueSecurityPlugin(), // Add security scanning
|
|
24
|
+
vue() // Vue plugin
|
|
25
|
+
]
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Advanced Configuration
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
// vite.config.js
|
|
33
|
+
import { defineConfig } from 'vite';
|
|
34
|
+
import vue from '@vitejs/plugin-vue';
|
|
35
|
+
import vueSecurityPlugin from 'vite-plugin-vue-security';
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
plugins: [
|
|
39
|
+
vueSecurityPlugin({
|
|
40
|
+
enabled: true, // Enable/disable security scanning (default: true)
|
|
41
|
+
failOnError: false, // Fail build on security issues (default: false)
|
|
42
|
+
reportLevel: 'warning', // 'error', 'warning', or 'info' (default: 'warning')
|
|
43
|
+
outputFile: './security-report.json', // Optional output file for security report
|
|
44
|
+
exclude: [ // Patterns to exclude from scanning
|
|
45
|
+
'node_modules',
|
|
46
|
+
'dist',
|
|
47
|
+
'public'
|
|
48
|
+
]
|
|
49
|
+
}),
|
|
50
|
+
vue()
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Configuration Options
|
|
56
|
+
|
|
57
|
+
- `enabled`: Boolean to enable/disable the security scanning (default: true)
|
|
58
|
+
- `failOnError`: Boolean to make the build fail when high severity vulnerabilities are detected (default: false)
|
|
59
|
+
- `reportLevel`: Sets the level of reporting ('error', 'warning', or 'info'; default: 'warning')
|
|
60
|
+
- `outputFile`: Optional path to write a JSON security report (default: null)
|
|
61
|
+
- `exclude`: Array of patterns to exclude from scanning (default: [])
|
|
62
|
+
|
|
63
|
+
## Features
|
|
64
|
+
|
|
65
|
+
- **Real-time Security Scanning**: Scans Vue, JS, and TS files during the build process
|
|
66
|
+
- **Multiple Vulnerability Types**: Detects XSS, dependency issues, misconfigurations, hardcoded secrets, and more
|
|
67
|
+
- **Enterprise Plugin Support**: Compatible with the Vue Security Scanner plugin system
|
|
68
|
+
- **Flexible Reporting**: Configurable reporting levels and output formats
|
|
69
|
+
- **Build Integration**: Option to fail builds on security issues
|
|
70
|
+
|
|
71
|
+
## Detected Vulnerabilities
|
|
72
|
+
|
|
73
|
+
The plugin can detect various security issues including:
|
|
74
|
+
|
|
75
|
+
- Cross-Site Scripting (XSS) vulnerabilities
|
|
76
|
+
- Insecure dependencies
|
|
77
|
+
- Hardcoded secrets and credentials
|
|
78
|
+
- Misconfigurations
|
|
79
|
+
- Potential code injection issues
|
|
80
|
+
- DOM-based XSS patterns
|
|
81
|
+
- Missing security headers
|
|
82
|
+
- Sensitive data exposure in URLs
|
|
83
|
+
- Weak random number generation
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
// Import the security scanner with plugin and ignore functionality
|
|
5
|
+
const { SecurityScanner } = require('vue-security-scanner/src/scanner');
|
|
6
|
+
const VulnerabilityDetector = require('vue-security-scanner/src/core/vulnerability-detector');
|
|
7
|
+
const pluginManager = require('vue-security-scanner/src/plugin-system/plugin-manager');
|
|
8
|
+
const IgnoreManager = require('vue-security-scanner/src/utils/ignore-manager');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Vite Plugin for Vue Security Scanning
|
|
12
|
+
* Performs security scans on Vue.js projects during the build process
|
|
13
|
+
*/
|
|
14
|
+
function vueSecurityPlugin(options = {}) {
|
|
15
|
+
const config = {
|
|
16
|
+
// Default options
|
|
17
|
+
enabled: true,
|
|
18
|
+
failOnError: false, // Whether to fail the build on security issues
|
|
19
|
+
reportLevel: 'warning', // 'error', 'warning', or 'info'
|
|
20
|
+
outputFile: null, // Optional output file for security report
|
|
21
|
+
exclude: [], // Patterns to exclude from scanning
|
|
22
|
+
...options
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
let detector;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
name: 'vue-security',
|
|
29
|
+
enforce: 'pre', // Run before other transforms
|
|
30
|
+
|
|
31
|
+
async buildStart() {
|
|
32
|
+
// Initialize the security scanner with configuration
|
|
33
|
+
const scannerConfig = {
|
|
34
|
+
rules: config.rules || {},
|
|
35
|
+
scan: {
|
|
36
|
+
ignoreDirs: config.ignoreDirs || [],
|
|
37
|
+
ignorePatterns: config.ignorePatterns || [],
|
|
38
|
+
maxSize: config.maxSize || 10,
|
|
39
|
+
maxDepth: config.maxDepth || 10
|
|
40
|
+
},
|
|
41
|
+
output: {
|
|
42
|
+
showProgress: false, // Disable progress in build process
|
|
43
|
+
format: 'json'
|
|
44
|
+
},
|
|
45
|
+
plugins: {
|
|
46
|
+
enabled: true,
|
|
47
|
+
directory: config.pluginsDir || path.join(__dirname, '../plugins'),
|
|
48
|
+
settings: config.pluginSettings || {}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Initialize the security scanner
|
|
53
|
+
this.scanner = new SecurityScanner(scannerConfig);
|
|
54
|
+
|
|
55
|
+
// Load plugins if available
|
|
56
|
+
try {
|
|
57
|
+
await pluginManager.loadPluginsFromDirectory(scannerConfig.plugins.directory);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.warn('Could not load security plugins:', error.message);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Initialize ignore manager
|
|
63
|
+
this.ignoreManager = new IgnoreManager(process.cwd());
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
async transform(code, id) {
|
|
67
|
+
// Skip if disabled
|
|
68
|
+
if (!config.enabled) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Skip excluded files
|
|
73
|
+
if (config.exclude.some(pattern => id.includes(pattern))) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Only scan Vue files and JS/TS files
|
|
78
|
+
if (!id.endsWith('.vue') && !id.endsWith('.js') && !id.endsWith('.ts') && !id.endsWith('.jsx') && !id.endsWith('.tsx')) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Check if file should be ignored
|
|
83
|
+
if (this.ignoreManager && this.ignoreManager.shouldIgnoreFile(id)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
// Perform security scan using the new scanner
|
|
89
|
+
const result = await this.scanner.scanFile(id, code);
|
|
90
|
+
const vulnerabilities = result.vulnerabilities || [];
|
|
91
|
+
|
|
92
|
+
// Report vulnerabilities
|
|
93
|
+
if (vulnerabilities.length > 0) {
|
|
94
|
+
vulnerabilities.forEach(vuln => {
|
|
95
|
+
let message = `[VUE-SECURITY] ${vuln.type} - ${vuln.severity} SEVERITY\n`;
|
|
96
|
+
message += `File: ${vuln.file}\n`;
|
|
97
|
+
if (vuln.line !== 'N/A') {
|
|
98
|
+
message += `Line: ${vuln.line}\n`;
|
|
99
|
+
}
|
|
100
|
+
message += `Description: ${vuln.description}\n`;
|
|
101
|
+
message += `Recommendation: ${vuln.recommendation}\n`;
|
|
102
|
+
if (vuln.plugin) {
|
|
103
|
+
message += `Plugin: ${vuln.plugin}\n`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Log based on report level
|
|
107
|
+
if (config.reportLevel === 'error' ||
|
|
108
|
+
(config.reportLevel === 'warning' && vuln.severity !== 'Low')) {
|
|
109
|
+
this.error(message);
|
|
110
|
+
} else {
|
|
111
|
+
this.warn(message);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Optionally write to output file
|
|
116
|
+
if (config.outputFile) {
|
|
117
|
+
await writeSecurityReport(config.outputFile, vulnerabilities);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Fail build if configured to do so
|
|
121
|
+
if (config.failOnError) {
|
|
122
|
+
const highSeverityVulns = vulnerabilities.filter(v => v.severity === 'High' || v.severity === 'Critical');
|
|
123
|
+
if (highSeverityVulns.length > 0) {
|
|
124
|
+
this.error(`Build failed due to ${highSeverityVulns.length} high severity security vulnerabilities.`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.warn(`Security scan error for ${id}:`, error.message);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Return the original code (we're only scanning, not modifying)
|
|
133
|
+
return {
|
|
134
|
+
code,
|
|
135
|
+
map: null // No source map transformation
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
// Hook to generate final report
|
|
140
|
+
async buildEnd(errors) {
|
|
141
|
+
if (errors && errors.length > 0) {
|
|
142
|
+
console.log(`Build completed with ${errors.length} errors.`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Write security report to file
|
|
150
|
+
*/
|
|
151
|
+
async function writeSecurityReport(outputFile, vulnerabilities) {
|
|
152
|
+
try {
|
|
153
|
+
const report = {
|
|
154
|
+
timestamp: new Date().toISOString(),
|
|
155
|
+
totalVulnerabilities: vulnerabilities.length,
|
|
156
|
+
vulnerabilities: vulnerabilities.map(v => ({
|
|
157
|
+
type: v.type,
|
|
158
|
+
severity: v.severity,
|
|
159
|
+
file: v.file,
|
|
160
|
+
line: v.line,
|
|
161
|
+
description: v.description,
|
|
162
|
+
recommendation: v.recommendation,
|
|
163
|
+
plugin: v.plugin
|
|
164
|
+
}))
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const dir = path.dirname(outputFile);
|
|
168
|
+
if (!fs.existsSync(dir)) {
|
|
169
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
await fs.promises.writeFile(outputFile, JSON.stringify(report, null, 2));
|
|
173
|
+
console.log(`Security report written to ${outputFile}`);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error('Error writing security report:', error.message);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
module.exports = vueSecurityPlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-vue-security",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Vite plugin that performs security scans on Vue.js projects during the build process",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"vite",
|
|
11
|
+
"plugin",
|
|
12
|
+
"vue",
|
|
13
|
+
"security",
|
|
14
|
+
"scanner",
|
|
15
|
+
"vulnerability",
|
|
16
|
+
"xss",
|
|
17
|
+
"owasp"
|
|
18
|
+
],
|
|
19
|
+
"author": "Vue Security Team",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"vite": "^4.0.0 || ^5.0.0",
|
|
23
|
+
"vue": "^3.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"cheerio": "^1.0.0-rc.12",
|
|
27
|
+
"vue-security-scanner": "^1.1.0"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/ereddate/vue-security-scanner.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/ereddate/vue-security-scanner/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/ereddate/vue-security-scanner#readme"
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// 示例:如何在Vite项目中使用Vue安全插件
|
|
2
|
+
// vite.config.js
|
|
3
|
+
|
|
4
|
+
import { defineConfig } from 'vite';
|
|
5
|
+
import vue from '@vitejs/plugin-vue';
|
|
6
|
+
import vueSecurityPlugin from 'vite-plugin-vue-security';
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
plugins: [
|
|
10
|
+
// 启用Vue安全扫描插件
|
|
11
|
+
vueSecurityPlugin({
|
|
12
|
+
enabled: true, // 启用安全扫描
|
|
13
|
+
failOnError: false, // 发现安全问题时不中断构建
|
|
14
|
+
reportLevel: 'warning', // 报告级别:'error', 'warning', 或 'info'
|
|
15
|
+
outputFile: './security-report.json', // 安全报告输出文件
|
|
16
|
+
exclude: [ // 排除扫描的文件模式
|
|
17
|
+
'node_modules',
|
|
18
|
+
'dist',
|
|
19
|
+
'public'
|
|
20
|
+
]
|
|
21
|
+
}),
|
|
22
|
+
|
|
23
|
+
// Vue插件
|
|
24
|
+
vue()
|
|
25
|
+
],
|
|
26
|
+
|
|
27
|
+
// 其他Vite配置...
|
|
28
|
+
});
|