Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
🔐 Adds local path checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed May 1, 2022
1 parent 437ec2e commit 8c15ab4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions services/save-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
const fsPromises = require('fs').promises;

module.exports = async (newConfig, render) => {
/* Either returns nothing (if using default path), or strips navigational characters from path */
const makeSafeFileName = (configObj) => {
if (!configObj || !configObj.filename) return undefined;
return configObj.filename.replaceAll('/', '').replaceAll('..', '');
};

const usersFileName = makeSafeFileName(newConfig);

// Define constants for the config file
const settings = {
defaultLocation: './public/',
Expand All @@ -16,11 +24,11 @@ module.exports = async (newConfig, render) => {
};

// Make the full file name and path to save the backup config file
const backupFilePath = `${settings.defaultLocation}${newConfig.filename || settings.filename}-`
const backupFilePath = `${settings.defaultLocation}${usersFileName || settings.filename}-`
+ `${Math.round(new Date() / 1000)}${settings.backupDenominator}`;

// The path where the main conf.yml should be read and saved to
const defaultFilePath = settings.defaultLocation + (newConfig.filename || settings.defaultFile);
const defaultFilePath = settings.defaultLocation + (usersFileName || settings.defaultFile);

// Returns a string confirming successful job
const getSuccessMessage = () => `Successfully backed up ${settings.defaultFile} to`
Expand Down

0 comments on commit 8c15ab4

Please sign in to comment.