queckezz / koa-views

Template rendering middleware for koa (hbs, swig, pug, anything! :sparkles:)
MIT License
710 stars 87 forks source link

[Bug] Can render specific files at any path outside the root dir #142

Closed 21k closed 3 years ago

21k commented 4 years ago

// path outside root if (UP_PATH_REGEXP.test(normalize('.' + sep + path))) { throw createError(403) }

- If the file is other
the code is https://github.com/queckezz/koa-views/blob/master/src/index.js#L49
it uses map or consolidate, if map is not set, the render  will be  consolidate[file_ suffix], at last it uses **resolve**  in node **path** package to handle the rootPath and the relPath, there is no crontrol of  path outside root, the problem is here, thus if the render engine exists, such file can be rendered, for examples:

http://127.0.0.1:7000/doc/..%2F..%2F..%2F..%2Fnode_modules%2Fkoa-views%2Ftest%2Ffixtures%2Fbasic.ejs http://127.0.0.1:7000/doc?file=../../../../node_modules/koa-views/test/fixtures/basic.ejs

int64ago commented 4 years ago

Nice catch! I'll fix it later.

int64ago commented 3 years ago

Fixed