koajs / static-cache

[MAINTAINERS WANTED] Static cache for koa
293 stars 47 forks source link

app can be view any directory and files #63

Closed tonylinyy closed 7 years ago

tonylinyy commented 7 years ago

hi when I use the middleware like this: app.use(staticCache(path.resolve(__dirname, '../public'), { gzip: true, dynamic: true })) anyone can view any directory and files like this in windows, http://xxx.xx.xx/..%5c..%5c/xxx it is very dangerous how to avoid?

tonylinyy commented 7 years ago

we add a middleware like this to avoid,any better solution? app.use(function *(next) { let filename = decodeURIComponent(path.normalize(this.path)); if(filename.indexOf('..')>=0){ this.status = 200; this.body = 'Not Found'; return; } yield next; });

dead-horse commented 7 years ago

closes by #66 #67