Skip to content
Merged
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
21 changes: 13 additions & 8 deletions be/src/http/download_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sstream>

#include "boost/lexical_cast.hpp"
#include <boost/filesystem.hpp>

#include "agent/cgroups_mgr.h"
#include "http/http_channel.h"
Expand All @@ -38,6 +39,8 @@
#include "util/filesystem_util.h"
#include "runtime/exec_env.h"

using boost::filesystem::canonical;

namespace doris {

const std::string FILE_PARAMETER = "file";
Expand All @@ -47,16 +50,16 @@ const std::string TOKEN_PARAMETER = "token";

DownloadAction::DownloadAction(ExecEnv* exec_env, const std::vector<std::string>& allow_dirs) :
_exec_env(exec_env),
_download_type(NORMAL),
_allow_paths(allow_dirs) {

_download_type(NORMAL) {
for (auto& dir : allow_dirs) {
_allow_paths.emplace_back(canonical(dir).string());
}
}

DownloadAction::DownloadAction(ExecEnv* exec_env, const std::string& error_log_root_dir) :
_exec_env(exec_env),
_download_type(ERROR_LOG),
_error_log_root_dir(error_log_root_dir) {

_download_type(ERROR_LOG) {
_error_log_root_dir = canonical(error_log_root_dir).string();
}

void DownloadAction::handle_normal(
Expand Down Expand Up @@ -243,8 +246,9 @@ Status DownloadAction::check_token(HttpRequest *req) {

Status DownloadAction::check_path_is_allowed(const std::string& file_path) {
DCHECK_EQ(_download_type, NORMAL);
std::string canonical_file_path = canonical(file_path).string();
for (auto& allow_path : _allow_paths) {
if (FileSystemUtil::contain_path(allow_path, file_path)) {
if (FileSystemUtil::contain_path(allow_path, canonical_file_path)) {
return Status::OK;
}
}
Expand All @@ -254,7 +258,8 @@ Status DownloadAction::check_path_is_allowed(const std::string& file_path) {

Status DownloadAction::check_log_path_is_allowed(const std::string& file_path) {
DCHECK_EQ(_download_type, ERROR_LOG);
if (FileSystemUtil::contain_path(_error_log_root_dir, file_path)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to get canonical path in a unified place?
Or you may miss somewhere.

std::string canonical_file_path = canonical(file_path).string();
if (FileSystemUtil::contain_path(_error_log_root_dir, canonical_file_path)) {
return Status::OK;
}

Expand Down