v0.42.2
This commit is contained in:
1 parent
aa0a271a1c
commit
f38a2b9e5e
38 files changed
+1098
-160
No files matched your search
+21
-12
@@ -4,6 +4,7 @@ use super::{
|
||||
},
|
||||
filesystem::{list_directory_sync, path_components, FilesystemRoot},
|
||||
htaccess,
|
||||
config::FastCgiHandler,
|
||||
response::{
|
||||
add_service_headers, builtin_error_response, directory_listing, directory_redirect,
|
||||
file_response, io_response, status_response,
|
||||
@@ -22,7 +23,7 @@ use http::{
|
||||
};
|
||||
use std::{io, path::PathBuf};
|
||||
|
||||
async fn resolve_php_path_info(
|
||||
async fn resolve_script_path_info(
|
||||
service: &CompiledService,
|
||||
components: &[String],
|
||||
) -> Option<(String, String)> {
|
||||
@@ -77,7 +78,7 @@ async fn serve_inner(
|
||||
components
|
||||
.iter()
|
||||
.any(|component| htaccess::protected_component(service.htaccess.as_ref(), component))
|
||||
}) || htaccess::denied(service.htaccess.as_ref(), path)
|
||||
}) || htaccess::denied(service.htaccess.as_ref(), path, context.client_ip)
|
||||
{
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
@@ -125,18 +126,18 @@ async fn serve_inner(
|
||||
htaccess::protected_component(service.htaccess.as_ref(), component)
|
||||
})
|
||||
})
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &rewritten_path)
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &rewritten_path, context.client_ip)
|
||||
{
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
if let Ok(components) = path_components(&rewritten_path) {
|
||||
if let Some((script_path, path_info)) = resolve_php_path_info(service, &components).await {
|
||||
if let Some((script_path, path_info)) = resolve_script_path_info(service, &components).await {
|
||||
let script_components = path_components(&script_path).unwrap_or_default();
|
||||
if hardening_denied_path(service, &script_path)
|
||||
|| script_components.iter().any(|component| {
|
||||
htaccess::protected_component(service.htaccess.as_ref(), component)
|
||||
})
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &script_path)
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &script_path, context.client_ip)
|
||||
{
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
@@ -178,7 +179,7 @@ async fn serve_inner(
|
||||
|| components
|
||||
.iter()
|
||||
.any(|component| htaccess::protected_component(service.htaccess.as_ref(), component))
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &effective_path)
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &effective_path, context.client_ip)
|
||||
{
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
@@ -192,14 +193,14 @@ async fn serve_inner(
|
||||
) =>
|
||||
{
|
||||
if let Some((script_path, path_info)) =
|
||||
resolve_php_path_info(service, &components).await
|
||||
resolve_script_path_info(service, &components).await
|
||||
{
|
||||
let script_components = path_components(&script_path).unwrap_or_default();
|
||||
if hardening_denied_path(service, &script_path)
|
||||
|| script_components.iter().any(|component| {
|
||||
htaccess::protected_component(service.htaccess.as_ref(), component)
|
||||
})
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &script_path)
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &script_path, context.client_ip)
|
||||
{
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
@@ -242,7 +243,10 @@ async fn serve_inner(
|
||||
)
|
||||
.await;
|
||||
}
|
||||
if protected_script_without_handler(service, &public_path) {
|
||||
if protected_script_without_handler(service, &public_path)
|
||||
|| service.php.as_ref().is_some_and(|php| php.handler == FastCgiHandler::Fcgiwrap)
|
||||
{
|
||||
// A CGI-only root must never expose any non-executed file.
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
if method != Method::GET && method != Method::HEAD {
|
||||
@@ -276,7 +280,9 @@ async fn serve_inner(
|
||||
let mut script_path = effective_path.trim_end_matches('/').to_owned();
|
||||
script_path.push('/');
|
||||
script_path.push_str(index);
|
||||
if hardening_denied_path(service, &script_path) {
|
||||
if hardening_denied_path(service, &script_path)
|
||||
|| htaccess::denied(service.htaccess.as_ref(), &script_path, context.client_ip)
|
||||
{
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
let public_path = PathBuf::from(&script_path);
|
||||
@@ -295,7 +301,9 @@ async fn serve_inner(
|
||||
)
|
||||
.await;
|
||||
}
|
||||
if protected_script_without_handler(service, &public_path) {
|
||||
if protected_script_without_handler(service, &public_path)
|
||||
|| service.php.as_ref().is_some_and(|php| php.handler == FastCgiHandler::Fcgiwrap)
|
||||
{
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
if method != Method::GET && method != Method::HEAD {
|
||||
@@ -333,7 +341,8 @@ async fn serve_inner(
|
||||
if method != Method::GET && method != Method::HEAD {
|
||||
return method_not_allowed_response();
|
||||
}
|
||||
if !htaccess::directory_listing(
|
||||
if service.php.as_ref().is_some_and(|php| php.handler == FastCgiHandler::Fcgiwrap)
|
||||
|| !htaccess::directory_listing(
|
||||
service.htaccess.as_ref(),
|
||||
&components,
|
||||
service.directory_listing,
|
||||
|
||||
Reference in new issue
Block a user