v0.42.2_fix2
This commit is contained in:
1 parent
15c7f9ff9e
commit
25148f26eb
14 files changed
+407
-54
No files matched your search
+62
-10
@@ -26,13 +26,18 @@ use std::{io, path::PathBuf};
|
||||
async fn resolve_script_path_info(
|
||||
service: &CompiledService,
|
||||
components: &[String],
|
||||
requested_path: &str,
|
||||
) -> Option<(String, String)> {
|
||||
let php = service.php.as_ref().filter(|php| php.path_info)?;
|
||||
if components.len() < 2 {
|
||||
return None;
|
||||
}
|
||||
for script_end in 0..components.len() - 1 {
|
||||
let php = service.php.as_ref()?;
|
||||
for script_end in 0..components.len() {
|
||||
let script_path = format!("/{}", components[..=script_end].join("/"));
|
||||
// Preserve the exact suffix, including its final slash. Apache
|
||||
// front controllers depend on PATH_INFO retaining that slash.
|
||||
let Some(path_info) = requested_path.strip_prefix(&script_path)
|
||||
.filter(|suffix| suffix.starts_with('/')) else { continue; };
|
||||
if !htaccess::accept_path_info(service.htaccess.as_ref(), &script_path, php.path_info) {
|
||||
continue;
|
||||
}
|
||||
if !php.extensions.iter().any(|extension| {
|
||||
PathBuf::from(&script_path)
|
||||
.extension()
|
||||
@@ -43,8 +48,7 @@ async fn resolve_script_path_info(
|
||||
}
|
||||
match open_components(service, components[..=script_end].to_vec()).await {
|
||||
Ok(opened) if opened.metadata.is_file() => {
|
||||
let path_info = format!("/{}", components[script_end + 1..].join("/"));
|
||||
return Some((script_path, path_info));
|
||||
return Some((script_path, path_info.to_owned()));
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
@@ -113,7 +117,9 @@ async fn serve_inner(
|
||||
return builtin_error_response(status, &method)
|
||||
}
|
||||
Ok(htaccess::RewriteOutcome::Internal { path, query }) => (path, query),
|
||||
Err(_) => {
|
||||
Err(error) => {
|
||||
tracing::warn!(service = %service.id, path = %path, error = %error,
|
||||
".htaccess rewrite rejected Web Service request");
|
||||
return status_response(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"RustProxy: invalid .htaccess rewrite target\n",
|
||||
@@ -134,7 +140,7 @@ async fn serve_inner(
|
||||
return builtin_error_response(StatusCode::FORBIDDEN, &method);
|
||||
}
|
||||
if let Ok(components) = path_components(&rewritten_path) {
|
||||
if let Some((script_path, path_info)) = resolve_script_path_info(service, &components).await {
|
||||
if let Some((script_path, path_info)) = resolve_script_path_info(service, &components, &rewritten_path).await {
|
||||
let script_components = path_components(&script_path).unwrap_or_default();
|
||||
if hardening_denied_path(service, &script_path)
|
||||
|| script_components.iter().any(|component| {
|
||||
@@ -196,7 +202,7 @@ async fn serve_inner(
|
||||
) =>
|
||||
{
|
||||
if let Some((script_path, path_info)) =
|
||||
resolve_script_path_info(service, &components).await
|
||||
resolve_script_path_info(service, &components, &effective_path).await
|
||||
{
|
||||
let script_components = path_components(&script_path).unwrap_or_default();
|
||||
if hardening_denied_path(service, &script_path)
|
||||
@@ -416,12 +422,58 @@ pub async fn serve(
|
||||
let _in_flight =
|
||||
crate::web_server::metrics::HeadersInFlight::new(&service.web_metrics.in_flight_headers);
|
||||
let request_method = method.clone();
|
||||
// Copy request metadata only for services that actually have local error
|
||||
// documents. Normal requests without that feature avoid header cloning.
|
||||
let error_request = ((request_method == Method::GET || request_method == Method::HEAD)
|
||||
&& htaccess::has_error_documents(service.htaccess.as_ref()))
|
||||
.then(|| (headers.clone(), context.clone()));
|
||||
let mut response = serve_inner(service, method, headers, uri, path, body, context).await;
|
||||
let original_status = response.status();
|
||||
let mut used_local_error_document = false;
|
||||
// Only replace server-generated errors. FastCGI applications may already
|
||||
// provide their own error body; do not open a second FastCGI request while
|
||||
// the first one's streamed response could still hold a backend permit.
|
||||
if (original_status.is_client_error() || original_status.is_server_error())
|
||||
&& !matches!(response.extensions().get::<crate::web_server::metrics::ResponseKind>(),
|
||||
Some(crate::web_server::metrics::ResponseKind::Php))
|
||||
{
|
||||
if let Some((mut error_headers, replacement_context)) = error_request {
|
||||
if let Some(target) = htaccess::error_document(service.htaccess.as_ref(), path, original_status) {
|
||||
let target_path = target.split('?').next().unwrap_or_default();
|
||||
if target_path != path {
|
||||
if let Ok(target_uri) = target.parse::<Uri>() {
|
||||
// Serve the full error document, never a Range or 304
|
||||
// response produced from the original request headers.
|
||||
for name in [
|
||||
http::header::RANGE, http::header::IF_RANGE,
|
||||
http::header::IF_MODIFIED_SINCE, http::header::IF_NONE_MATCH,
|
||||
http::header::IF_MATCH, http::header::IF_UNMODIFIED_SINCE,
|
||||
] { error_headers.remove(name); }
|
||||
let replacement = serve_inner(
|
||||
service, request_method.clone(), error_headers, target_uri,
|
||||
target_path, Body::empty(), replacement_context,
|
||||
).await;
|
||||
if replacement.status() == StatusCode::OK {
|
||||
response = replacement;
|
||||
used_local_error_document = true;
|
||||
*response.status_mut() = original_status;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if request_method == Method::HEAD {
|
||||
*response.body_mut() = Body::empty();
|
||||
}
|
||||
add_service_headers(&mut response, service);
|
||||
htaccess::apply_response(service.htaccess.as_ref(), &mut response, path);
|
||||
if used_local_error_document {
|
||||
// A local ErrorDocument is still an error response, even if the page's
|
||||
// normal Cache-Control or Expires rules say that successful pages are public.
|
||||
response.headers_mut().insert(CACHE_CONTROL, HeaderValue::from_static("no-store"));
|
||||
response.headers_mut().remove(http::header::EXPIRES);
|
||||
}
|
||||
strip_unnecessary_headers(&mut response, service);
|
||||
let kind = response
|
||||
.extensions()
|
||||
|
||||
Reference in new issue
Block a user