vite-plugin-vue-security 1.0.0 → 1.1.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.
Files changed (2) hide show
  1. package/index.js +166 -179
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,179 +1,166 @@
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;
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ // Import the security scanner with rule-based architecture
5
+ const { SecurityScanner } = require('vue-security-scanner/src/scanner');
6
+ const IgnoreManager = require('vue-security-scanner/src/utils/ignore-manager');
7
+
8
+ /**
9
+ * Vite Plugin for Vue Security Scanning
10
+ * Performs security scans on Vue.js projects during the build process
11
+ */
12
+ function vueSecurityPlugin(options = {}) {
13
+ const config = {
14
+ // Default options
15
+ enabled: true,
16
+ failOnError: false, // Whether to fail the build on security issues
17
+ reportLevel: 'warning', // 'error', 'warning', or 'info'
18
+ outputFile: null, // Optional output file for security report
19
+ exclude: [], // Patterns to exclude from scanning
20
+ ...options
21
+ };
22
+
23
+ let scanner;
24
+ let ignoreManager;
25
+
26
+ return {
27
+ name: 'vue-security',
28
+ enforce: 'pre', // Run before other transforms
29
+
30
+ async buildStart() {
31
+ // Initialize the security scanner with configuration
32
+ const scannerConfig = {
33
+ rules: config.rules || {},
34
+ scan: {
35
+ ignoreDirs: config.ignoreDirs || [],
36
+ ignorePatterns: config.ignorePatterns || [],
37
+ maxSize: config.maxSize || 10,
38
+ maxDepth: config.maxDepth || 10
39
+ },
40
+ output: {
41
+ showProgress: false, // Disable progress in build process
42
+ format: 'json'
43
+ }
44
+ };
45
+
46
+ // Initialize security scanner
47
+ scanner = new SecurityScanner(scannerConfig);
48
+
49
+ // Initialize ignore manager
50
+ ignoreManager = new IgnoreManager(process.cwd());
51
+ },
52
+
53
+ async transform(code, id) {
54
+ // Skip if disabled
55
+ if (!config.enabled) {
56
+ return null;
57
+ }
58
+
59
+ // Skip excluded files
60
+ if (config.exclude.some(pattern => id.includes(pattern))) {
61
+ return null;
62
+ }
63
+
64
+ // Only scan Vue files and JS/TS files
65
+ if (!id.endsWith('.vue') && !id.endsWith('.js') && !id.endsWith('.ts') && !id.endsWith('.jsx') && !id.endsWith('.tsx')) {
66
+ return null;
67
+ }
68
+
69
+ // Check if file should be ignored
70
+ if (ignoreManager && ignoreManager.shouldIgnoreFile(id)) {
71
+ return null;
72
+ }
73
+
74
+ try {
75
+ // Perform security scan using new scanner
76
+ const result = await scanner.scanFile(id, code);
77
+ const vulnerabilities = result.vulnerabilities || [];
78
+
79
+ // Report vulnerabilities
80
+ if (vulnerabilities.length > 0) {
81
+ vulnerabilities.forEach(vuln => {
82
+ let message = `[VUE-SECURITY] ${vuln.type} - ${vuln.severity} SEVERITY\n`;
83
+ message += `File: ${vuln.file}\n`;
84
+ if (vuln.line !== 'N/A') {
85
+ message += `Line: ${vuln.line}\n`;
86
+ }
87
+ message += `Description: ${vuln.description}\n`;
88
+ message += `Recommendation: ${vuln.recommendation}\n`;
89
+ if (vuln.ruleId) {
90
+ message += `Rule: ${vuln.ruleId}\n`;
91
+ }
92
+
93
+ // Log based on report level
94
+ if (config.reportLevel === 'error' ||
95
+ (config.reportLevel === 'warning' && vuln.severity !== 'Low')) {
96
+ this.error(message);
97
+ } else {
98
+ this.warn(message);
99
+ }
100
+ });
101
+
102
+ // Optionally write to output file
103
+ if (config.outputFile) {
104
+ await writeSecurityReport(config.outputFile, vulnerabilities);
105
+ }
106
+
107
+ // Fail build if configured to do so
108
+ if (config.failOnError) {
109
+ const highSeverityVulns = vulnerabilities.filter(v => v.severity === 'High' || v.severity === 'Critical');
110
+ if (highSeverityVulns.length > 0) {
111
+ this.error(`Build failed due to ${highSeverityVulns.length} high severity security vulnerabilities.`);
112
+ }
113
+ }
114
+ }
115
+ } catch (error) {
116
+ console.warn(`Security scan error for ${id}:`, error.message);
117
+ }
118
+
119
+ // Return of original code (we're only scanning, not modifying)
120
+ return {
121
+ code,
122
+ map: null // No source map transformation
123
+ };
124
+ },
125
+
126
+ // Hook to generate final report
127
+ async buildEnd(errors) {
128
+ if (errors && errors.length > 0) {
129
+ console.log(`Build completed with ${errors.length} errors.`);
130
+ }
131
+ }
132
+ };
133
+ }
134
+
135
+ /**
136
+ * Write security report to file
137
+ */
138
+ async function writeSecurityReport(outputFile, vulnerabilities) {
139
+ try {
140
+ const report = {
141
+ timestamp: new Date().toISOString(),
142
+ totalVulnerabilities: vulnerabilities.length,
143
+ vulnerabilities: vulnerabilities.map(v => ({
144
+ type: v.type,
145
+ severity: v.severity,
146
+ file: v.file,
147
+ line: v.line,
148
+ description: v.description,
149
+ recommendation: v.recommendation,
150
+ ruleId: v.ruleId
151
+ }))
152
+ };
153
+
154
+ const dir = path.dirname(outputFile);
155
+ if (!fs.existsSync(dir)) {
156
+ fs.mkdirSync(dir, { recursive: true });
157
+ }
158
+
159
+ await fs.promises.writeFile(outputFile, JSON.stringify(report, null, 2));
160
+ console.log(`Security report written to ${outputFile}`);
161
+ } catch (error) {
162
+ console.error('Error writing security report:', error.message);
163
+ }
164
+ }
165
+
166
+ module.exports = vueSecurityPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vue-security",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A Vite plugin that performs security scans on Vue.js projects during the build process",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "cheerio": "^1.0.0-rc.12",
27
- "vue-security-scanner": "^1.1.0"
27
+ "vue-security-scanner": "^1.2.1"
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",