Skip to content

Commit

Permalink
fix(config): Validate hostname, url and pasword fields in config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Göran Sander committed Sep 20, 2024
1 parent 6e7043b commit 4a7671e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
56 changes: 45 additions & 11 deletions src/lib/config-file-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const confifgFileSchema = {
type: 'object',
properties: {
enable: { type: 'boolean' },
host: { type: 'string' },
host: {
type: 'string',
format: 'hostname',
},
port: { type: 'number' },
obfuscate: { type: 'boolean' },
},
Expand All @@ -27,7 +30,10 @@ export const confifgFileSchema = {
type: 'object',
properties: {
enable: { type: 'boolean' },
remoteURL: { type: 'string' },
remoteURL: {
type: 'string',
format: 'uri',
},
frequency: { type: 'string' },
},
required: ['enable', 'remoteURL', 'frequency'],
Expand Down Expand Up @@ -246,7 +252,10 @@ export const confifgFileSchema = {
udpServerConfig: {
type: 'object',
properties: {
serverHost: { type: 'string' },
serverHost: {
type: 'string',
format: 'hostname',
},
portUserActivityEvents: { type: 'number' },
},
required: ['serverHost', 'portUserActivityEvents'],
Expand Down Expand Up @@ -363,7 +372,10 @@ export const confifgFileSchema = {
udpServerConfig: {
type: 'object',
properties: {
serverHost: { type: 'string' },
serverHost: {
type: 'string',
format: 'hostname',
},
portLogEvents: { type: 'number' },
},
required: ['serverHost', 'portLogEvents'],
Expand Down Expand Up @@ -868,6 +880,7 @@ export const confifgFileSchema = {
clientCertCA: { type: 'string' },
clientCertPassphrase: {
type: ['string', 'null'],
format: 'password',
},
},
required: ['clientCert', 'clientCertKey', 'clientCertCA'],
Expand All @@ -877,7 +890,10 @@ export const confifgFileSchema = {
type: 'object',
properties: {
enable: { type: 'boolean' },
brokerHost: { type: 'string' },
brokerHost: {
type: 'string',
format: 'hostname',
},
brokerPort: { type: 'number' },
baseTopic: { type: 'string' },
},
Expand All @@ -891,7 +907,10 @@ export const confifgFileSchema = {
event: {
type: 'object',
properties: {
url: { type: 'string' },
url: {
type: 'string',
format: 'uri',
},
header: {
type: ['array', 'null'],
items: {
Expand Down Expand Up @@ -950,7 +969,10 @@ export const confifgFileSchema = {
type: 'string',
},
},
url: { type: 'string' },
url: {
type: 'string',
format: 'uri',
},
header: {
type: ['array', 'null'],
items: {
Expand Down Expand Up @@ -1166,7 +1188,10 @@ export const confifgFileSchema = {
type: 'object',
properties: {
enable: { type: 'boolean' },
host: { type: 'string' },
host: {
type: 'string',
format: 'hostname',
},
port: { type: 'number' },
},
required: ['enable', 'port'],
Expand All @@ -1176,7 +1201,10 @@ export const confifgFileSchema = {
type: 'object',
properties: {
enable: { type: 'boolean' },
host: { type: 'string' },
host: {
type: 'string',
format: 'hostname',
},
port: { type: 'number' },
version: { type: 'number' },
v2Config: {
Expand Down Expand Up @@ -1205,7 +1233,10 @@ export const confifgFileSchema = {
properties: {
enable: { type: 'boolean' },
username: { type: 'string' },
password: { type: 'string' },
password: {
type: 'string',
format: 'password',
},
},
required: ['enable', 'username', 'password'],
additionalProperties: false,
Expand Down Expand Up @@ -1251,7 +1282,10 @@ export const confifgFileSchema = {
properties: {
enableAppNameExtract: { type: 'boolean' },
extractInterval: { type: 'number' },
hostIP: { type: 'string' },
hostIP: {
type: 'string',
format: 'hostname',
},
},
required: ['enableAppNameExtract', 'extractInterval', 'hostIP'],
additionalProperties: false,
Expand Down
6 changes: 6 additions & 0 deletions src/lib/config-file-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export async function verifyConfigFile() {
// Add keywords to ajv instance
ajvKeywords.default(ajv);

// Dynamically import ajv-formats
const ajvFormats = await import('ajv-formats');

// Add formats to ajv instance
ajvFormats.default(ajv);

// Load the YAML schema file, identified by globals.configFile, from file
const fileContent = await fs.readFile(globals.configFile, 'utf8');

Expand Down

0 comments on commit 4a7671e

Please sign in to comment.