mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
提高http文件服务器安全性
This commit is contained in:
parent
f36ccee3de
commit
06a6d26491
@ -549,6 +549,13 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, Sess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto ret = File::absolutePath(enableVhost ? media_info.vhost + url : url, path);
|
auto ret = File::absolutePath(enableVhost ? media_info.vhost + url : url, path);
|
||||||
|
auto http_root = File::absolutePath(enableVhost ? media_info.vhost + "/" : "/", path);
|
||||||
|
if (!start_with(ret, http_root)) {
|
||||||
|
// 访问的http文件不得在http根目录之外
|
||||||
|
throw std::runtime_error("Attempting to access files outside of the http root directory");
|
||||||
|
}
|
||||||
|
// 替换url,防止返回的目录索引网页被注入非法内容
|
||||||
|
const_cast<Parser&>(parser).setUrl("/" + ret.substr(http_root.size()));
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpBeforeAccess, parser, ret, static_cast<SockInfo &>(sender));
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpBeforeAccess, parser, ret, static_cast<SockInfo &>(sender));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user