-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some validation for remove_job_data in the executor server #468
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -720,13 +720,45 @@ impl<T: 'static + AsLogicalPlan, U: 'static + AsExecutionPlan> ExecutorGrpc | |
request: Request<RemoveJobDataParams>, | ||
) -> Result<Response<RemoveJobDataResult>, Status> { | ||
let job_id = request.into_inner().job_id; | ||
info!("Remove data for job {:?}", job_id); | ||
|
||
// Verify whether it's a legal job id | ||
{ | ||
if job_id.is_empty() { | ||
return Err(Status::internal( | ||
"Job id should not be empty!!!".to_string(), | ||
)); | ||
} | ||
if job_id.contains('.') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to prevent files with extensions? Or parent directories? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's for prevent deleting parent directory. Generally, a directory should not contain '.' |
||
return Err(Status::internal(format!( | ||
"Job id {} should not contain char '.'!!!", | ||
job_id | ||
))); | ||
} | ||
} | ||
|
||
let work_dir = self.executor.work_dir.clone(); | ||
let mut path = PathBuf::from(work_dir); | ||
path.push(job_id.clone()); | ||
if path.is_dir() { | ||
info!("Remove data for job {:?}", job_id); | ||
std::fs::remove_dir_all(&path)?; | ||
path.push(job_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love the |
||
|
||
// Verify whether the path is for an existing directory | ||
{ | ||
if !path.exists() { | ||
return Err(Status::internal(format!( | ||
"Path {:?} does not exist!!!", | ||
path | ||
))); | ||
} | ||
if !path.is_dir() { | ||
return Err(Status::internal(format!( | ||
"Path {:?} is not for a directory!!!", | ||
path | ||
))); | ||
} | ||
} | ||
|
||
std::fs::remove_dir_all(&path)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs we have a vulnerability here:
I can bypass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. I'll refine it to use a more standard and robust way for the subdirectory check. |
||
|
||
Ok(Response::new(RemoveJobDataResult {})) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the redundant scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unnecessary. Just for making the verification steps more clearly