Skip to content

Commit a115508

Browse files
committed
add schema utils lib to validate user input
1 parent 69beba5 commit a115508

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const spawn = require('child_process').spawn;
2+
const validateOptions = require('schema-utils');
3+
const schema = require('./schema.json');
24

35
class HTMLValidatePlugin {
46
constructor(options = {}) {
7+
// validate the options being passed through the plugin options
8+
validateOptions(schema, options, 'HTMLValidatePlugin');
9+
510
Object.assign(
611
this,
712
{
@@ -41,9 +46,11 @@ class HTMLValidatePlugin {
4146

4247
runCliBasedOnScope(userParams, spawnParams) {
4348
/*
44-
arguments are in an array and shell option is "false" by default; this is better for security
45-
https://stackoverflow.com/a/50424976d
46-
https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
49+
Attempts at better security:
50+
- schema utils used to validate user input
51+
- spawn command (by default) is not exec under a shell env
52+
https://gist.github.com/evilpacket/5a9655c752982faf7c4ec6450c1cbf1b
53+
https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
4754
*/
4855
return this.global
4956
? spawn('html-validate', [`${userParams}`], spawnParams)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525
"homepage": "https://github.com/waldronmatt/html-validate-webpack-plugin#readme",
2626
"devDependencies": {
2727
"prettier": "^2.2.1"
28+
},
29+
"dependencies": {
30+
"schema-utils": "^1.0.0"
2831
}
2932
}

schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"path": {
5+
"type": "string"
6+
},
7+
"extensions": {
8+
"type": "array"
9+
},
10+
"config": {
11+
"type": "string"
12+
},
13+
"global": {
14+
"type": "boolean"
15+
}
16+
},
17+
"additionalProperties": false
18+
}

0 commit comments

Comments
 (0)