Skip to content

Commit 95313a7

Browse files
committed
Added file path security and removed the feedback of what file isn't found
1 parent 5856039 commit 95313a7

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ module.exports = (http) => {
113113
if (this.assetPaths.hasOwnProperty(fileType) && this.assetPaths[fileType].hasOwnProperty('path')) {
114114
const { path: filePath } = this.assetPaths[file];
115115
file = filePath.replace(`${assetType}/`, '');
116+
this.renderAsset(assetType, file, assetType, res);
116117
}
117-
118-
this.renderAsset(assetType, file, assetType, res);
119118
}
120119
}
121120
else {
@@ -199,12 +198,14 @@ module.exports = (http) => {
199198
* @param string stripFromPath
200199
*/
201200
renderAsset(path, file, assetType, res, stripFromPath) {
201+
file = file.replace(/\.\.\//g, '');
202202
const filePath = `${path}${file}`.replace(stripFromPath, '');
203203

204204
fs.readFile(filePath, (err, data) => {
205205
if (err) {
206+
// console.error(err);
206207
res.statusCode = 404;
207-
res.end(`File ${filePath} doesn't exist`);
208+
res.end(`File not found`);
208209
}
209210

210211
if (assetType == 'js') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "small-router",
3-
"version": "1.1.10",
3+
"version": "1.1.12",
44
"description": "Small router module that creates http server and runs callbacks that have have been added for a route via the api",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)