Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packager/react-packager/src/AssetServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,23 @@ class AssetServer {
_findRoot(roots, dir) {
return Promise.all(
roots.map(root => {
const absPath = path.join(root, dir);
// important: we want to resolve root + dir
// to ensure the requested path doesn't traverse beyond root
const absPath = path.resolve(root, dir);
return stat(absPath).then(fstat => {
return {path: absPath, isDirectory: fstat.isDirectory()};
// keep asset requests from traversing files
// up from the root (e.g. ../../../etc/hosts)
if (absPath.startsWith(root)) {
return {path: absPath, isValid: false};
}
return {path: absPath, isValid: fstat.isDirectory()};
}, err => {
return {path: absPath, isDirectory: false};
return {path: absPath, isValid: false};
});
})
).then(stats => {
for (let i = 0; i < stats.length; i++) {
if (stats[i].isDirectory) {
if (stats[i].isValid) {
return stats[i].path;
}
}
Expand Down