v0.43.1
This commit is contained in:
1 parent
5b6d4a7903
commit
4d1087e357
160 files changed
+2407
-1933
No files matched your search
@@ -462,9 +462,6 @@ impl Service {
|
||||
name: self.name.clone(),
|
||||
sendfile: self.sendfile,
|
||||
root,
|
||||
// Keep explicit index priorities unchanged. For the stock static
|
||||
// default, PHP-capable services also try index.php when the HTML
|
||||
// indexes are absent, matching common PHP application installs.
|
||||
index: {
|
||||
let mut index = self.index.clone();
|
||||
if self.php.enabled && self.php.handler == FastCgiHandler::PhpFpm
|
||||
|
||||
@@ -278,10 +278,7 @@ pub struct Php {
|
||||
#[serde(default = "default_php_extensions")]
|
||||
pub extensions: Vec<String>,
|
||||
pub endpoint: String,
|
||||
/// Existing configurations default to PHP-FPM; fcgiwrap runs installed CGI scripts.
|
||||
pub handler: FastCgiHandler,
|
||||
/// Public URL prefix when a Vhost location rewrites a mount path.
|
||||
/// SCRIPT_FILENAME stays confined to document_root; SCRIPT_NAME gains this prefix.
|
||||
pub script_name_prefix: String,
|
||||
#[serde(default = "default_php_connect_timeout_ms")]
|
||||
pub connect_timeout_ms: u64,
|
||||
|
||||
@@ -73,8 +73,6 @@ pub struct CompiledService {
|
||||
}
|
||||
|
||||
impl CompiledService {
|
||||
// Read-only diagnostics for the authenticated administration UI. Warnings
|
||||
// come from the active compiled snapshot, not from another filesystem scan.
|
||||
pub fn htaccess_diagnostics(&self) -> Option<(usize, &[String])> {
|
||||
self.htaccess.as_ref().map(|compiled| (compiled.files_loaded, compiled.warnings.as_slice()))
|
||||
}
|
||||
|
||||
@@ -32,11 +32,8 @@ const FCGI_STDERR: u8 = 7;
|
||||
const FCGI_RESPONDER: u16 = 1;
|
||||
const FCGI_REQUEST_ID: u16 = 1;
|
||||
const FCGI_HEADER_LEN: usize = 8;
|
||||
/// Request records (BEGIN, PARAMS, STDIN) are coalesced into a few socket writes.
|
||||
const FASTCGI_WRITE_BUFFER_BYTES: usize = 16 * 1024;
|
||||
/// Response records are read through one buffer instead of 2-3 reads per record.
|
||||
const FASTCGI_READ_BUFFER_BYTES: usize = 32 * 1024;
|
||||
/// Already-received STDOUT records are merged into one body chunk up to this size.
|
||||
const FASTCGI_BODY_CHUNK_BYTES: usize = 64 * 1024;
|
||||
|
||||
pub(super) trait FastCgiIo: AsyncRead + AsyncWrite + Unpin + Send {}
|
||||
@@ -48,16 +45,12 @@ async fn connect_fastcgi(endpoint: &FastCgiEndpoint) -> io::Result<Box<dyn FastC
|
||||
FastCgiEndpoint::Unix(path) => Ok(Box::new(tokio::net::UnixStream::connect(path).await?)),
|
||||
FastCgiEndpoint::Tcp(address) => {
|
||||
let stream = tokio::net::TcpStream::connect(address).await?;
|
||||
// FastCGI is a request/response exchange of small records; Nagle's
|
||||
// algorithm would only delay the final record of a request.
|
||||
stream.set_nodelay(true)?;
|
||||
Ok(Box::new(stream))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Type of the next FastCGI record when it is already complete in the read
|
||||
/// buffer, so it can be consumed without waiting for the socket.
|
||||
fn buffered_fcgi_record(io: &BufReader<Box<dyn FastCgiIo>>) -> Option<u8> {
|
||||
let buffer = io.buffer();
|
||||
if buffer.len() < FCGI_HEADER_LEN {
|
||||
@@ -370,9 +363,6 @@ async fn drain_fastcgi_body(
|
||||
metrics: std::sync::Arc<crate::web_server::metrics::PhpMetrics>,
|
||||
_permit: OwnedSemaphorePermit,
|
||||
) {
|
||||
// Body bytes waiting to be sent. Records that have already arrived are
|
||||
// merged into one chunk; nothing is held back while waiting for the socket,
|
||||
// so flush() from the application still reaches the client immediately.
|
||||
let mut pending = if send_body { initial } else { Vec::new() };
|
||||
let mut stderr = Vec::new();
|
||||
loop {
|
||||
|
||||
@@ -111,8 +111,6 @@ async fn php_response_inner(
|
||||
write_fcgi_record(&mut writer, FCGI_PARAMS, &[]).await?;
|
||||
|
||||
let mut body = body;
|
||||
// Requests without a body go out in one write. With a body, deliver the
|
||||
// parameters first so the responder can start while the client uploads.
|
||||
if !http_body::Body::is_end_stream(&body) {
|
||||
writer.flush().await?;
|
||||
}
|
||||
@@ -151,7 +149,6 @@ async fn php_response_inner(
|
||||
}
|
||||
}
|
||||
|
||||
// The request is fully flushed; from here on the connection is only read.
|
||||
let mut io = BufReader::with_capacity(FASTCGI_READ_BUFFER_BYTES, writer.into_inner());
|
||||
let mut stdout = Vec::new();
|
||||
let mut stderr = Vec::new();
|
||||
|
||||
@@ -106,7 +106,6 @@ struct Scope {
|
||||
file_rules: Vec<FileAccessRule>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum AcceptPathInfoMode {
|
||||
On,
|
||||
@@ -114,8 +113,6 @@ enum AcceptPathInfoMode {
|
||||
Default,
|
||||
}
|
||||
|
||||
// Apache Files / FilesMatch rules apply to filenames below their directory.
|
||||
// Only bounded access-control directives are accepted inside these blocks.
|
||||
#[derive(Debug, Clone)]
|
||||
struct FileAccessRule {
|
||||
matcher: Regex,
|
||||
@@ -132,9 +129,6 @@ impl FileAccessRule {
|
||||
}
|
||||
}
|
||||
|
||||
// Apache 2.2 mod_access_compat's Order/Allow/Deny are access rules, not
|
||||
// harmless unsupported directives. Evaluate them instead of silently skipping
|
||||
// them and accidentally publishing protected files.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
enum LegacyOrder {
|
||||
#[default]
|
||||
|
||||
@@ -43,9 +43,6 @@ fn redirect_rule(parts: &[String], regex: bool) -> Result<SimpleRedirect> {
|
||||
Ok(SimpleRedirect { matcher, replacement, status })
|
||||
}
|
||||
|
||||
// Only a safe, deterministic subset of Apache access rules is allowed in
|
||||
// <Files> and <FilesMatch>. Unknown directives inside a security scope must
|
||||
// fail closed, including when the general "ignore unsupported" option is off.
|
||||
fn file_rule_start(line: &str) -> Result<FileAccessRule> {
|
||||
let inner = line.trim().strip_prefix('<').and_then(|s| s.strip_suffix('>'))
|
||||
.context("unterminated Files or FilesMatch tag")?;
|
||||
@@ -56,7 +53,6 @@ fn file_rule_start(line: &str) -> Result<FileAccessRule> {
|
||||
ensure!(values.len() == 1, "FilesMatch needs one quoted regex");
|
||||
values[0].clone()
|
||||
} else {
|
||||
// Apache also accepts <Files ~ "regex"> as an alias of FilesMatch.
|
||||
if values.len() == 2 && values[0] == "~" {
|
||||
values[1].clone()
|
||||
} else {
|
||||
@@ -395,8 +391,6 @@ fn matching_scopes<'a>(compiled: &'a Compiled, path: &str) -> Vec<&'a Scope> {
|
||||
pub fn denied(compiled: Option<&Compiled>, path: &str, client_ip: IpAddr) -> bool {
|
||||
let Some(compiled) = compiled else { return false; };
|
||||
let scopes = matching_scopes(compiled, path);
|
||||
// A matching <Files>/<FilesMatch> denial is additive. A narrower file
|
||||
// grant must not cancel a directory denial or another matched file rule.
|
||||
let basename = path_components(path).ok().and_then(|parts| parts.last().cloned());
|
||||
if let Some(name) = basename {
|
||||
for scope in &scopes {
|
||||
|
||||
@@ -22,7 +22,6 @@ pub async fn apply_rewrites(
|
||||
let mut changed = false;
|
||||
let mut end = false;
|
||||
'scope: for scope in scopes {
|
||||
// Apache mod_alias Redirect / RedirectMatch, independently of RewriteEngine.
|
||||
for rule in &scope.redirects {
|
||||
let tail = match &rule.matcher {
|
||||
RedirectMatcher::Prefix(prefix) => {
|
||||
|
||||
@@ -9,7 +9,6 @@ pub struct RequestContext {
|
||||
pub server_port: u16,
|
||||
pub tls: bool,
|
||||
pub version: Version,
|
||||
/// Set only after Vhost Basic authentication has succeeded.
|
||||
pub authenticated_user: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ async fn resolve_script_path_info(
|
||||
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('/'))
|
||||
@@ -272,7 +270,6 @@ async fn serve_inner(
|
||||
.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 {
|
||||
@@ -446,17 +443,12 @@ 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
|
||||
@@ -472,8 +464,6 @@ pub async fn serve(
|
||||
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,
|
||||
@@ -504,9 +494,6 @@ pub async fn serve(
|
||||
}
|
||||
}
|
||||
}
|
||||
// Keep application-generated errors and explicit local ErrorDocument bodies.
|
||||
// Static filesystem errors are generated by RustProxy and may be replaced
|
||||
// by Vhost/global pages in the outer HTTP response pipeline.
|
||||
if used_local_error_document
|
||||
|| matches!(
|
||||
response
|
||||
@@ -525,8 +512,6 @@ pub async fn serve(
|
||||
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"));
|
||||
|
||||
@@ -2668,7 +2668,6 @@ async fn generic_fcgiwrap_mount_passes_public_script_name_without_exposing_other
|
||||
};
|
||||
config.validate().unwrap();
|
||||
let service = config.compile().unwrap();
|
||||
// The Vhost strips /app/cgi-bin before invoking the mounted Web Service.
|
||||
let uri = "/app/cgi-bin/health.cgi/more?query=1";
|
||||
let response = serve_request(&service, &request(Method::GET, uri), "/health.cgi/more").await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
@@ -3251,7 +3250,6 @@ async fn htaccess_php_error_document_preserves_status_and_passes_its_own_query()
|
||||
assert_eq!(params["REQUEST_URI"], "/error.php?404");
|
||||
}
|
||||
|
||||
/// One encoded FastCGI record (request id 1), as a responder writes it.
|
||||
fn fcgi_record_bytes(kind: u8, content: &[u8]) -> Vec<u8> {
|
||||
let padding = (8 - content.len() % 8) % 8;
|
||||
let mut record = vec![1, kind, 0, 1];
|
||||
@@ -3283,7 +3281,6 @@ fn php_fixture_service(root: &Path, address: std::net::SocketAddr) -> CompiledSe
|
||||
configured.compile().unwrap()
|
||||
}
|
||||
|
||||
/// Reads one complete FastCGI request and returns (params, stdin).
|
||||
async fn read_fastcgi_request(stream: &mut tokio::net::TcpStream) -> (Vec<u8>, Vec<u8>) {
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
let (mut params, mut stdin) = (Vec::new(), Vec::new());
|
||||
@@ -3310,8 +3307,6 @@ async fn fastcgi_buffered_exchange_keeps_many_records_stderr_and_body_intact() {
|
||||
let (mut stream, _) = listener.accept().await.unwrap();
|
||||
let (params, stdin) = read_fastcgi_request(&mut stream).await;
|
||||
let _ = seen_tx.send((decode_fastcgi_params(¶ms), stdin));
|
||||
// Headers split across records, interleaved STDERR, then many small
|
||||
// body records written in one burst (as PHP output buffers do).
|
||||
let mut burst = Vec::new();
|
||||
for record in [
|
||||
&b"Status: 200 OK\r\nContent-"[..],
|
||||
@@ -3367,8 +3362,6 @@ async fn fastcgi_streamed_output_is_not_held_back_for_coalescing() {
|
||||
.await
|
||||
.unwrap();
|
||||
stream.flush().await.unwrap();
|
||||
// The rest is produced only after the client has seen the first chunk,
|
||||
// like an application calling flush() between slow steps.
|
||||
release_rx.await.unwrap();
|
||||
write_fcgi_record(&mut stream, FCGI_STDOUT, b"-second")
|
||||
.await
|
||||
@@ -3409,7 +3402,6 @@ async fn fastcgi_truncated_stream_delivers_received_bytes_then_errors() {
|
||||
let mut burst = fcgi_record_bytes(FCGI_STDOUT, b"Content-Type: text/plain\r\n\r\nkept");
|
||||
burst.extend_from_slice(&fcgi_record_bytes(FCGI_STDOUT, b"-also"));
|
||||
stream.write_all(&burst).await.unwrap();
|
||||
// Half a record header, then the responder disappears.
|
||||
stream.write_all(&[1, FCGI_STDOUT, 0]).await.unwrap();
|
||||
stream.flush().await.unwrap();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user