aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarson McManus <carson.mcmanus1@gmail.com>2024-01-29 00:51:06 +0000
committerCarson McManus <carson.mcmanus1@gmail.com>2024-01-29 00:51:06 +0000
commit2b029e95570312de19b039c74f55298a439d6ad2 (patch)
treeebfd1d33374606548b8c477746a97af750f57ef8
parentBump deps (diff)
downloadminiserve-2b029e95570312de19b039c74f55298a439d6ad2.tar.gz
miniserve-2b029e95570312de19b039c74f55298a439d6ad2.zip
add `--disable-indexing` cli flag to completely disable directory indexing
-rw-r--r--src/args.rs6
-rw-r--r--src/config.rs4
-rw-r--r--src/listing.rs9
-rw-r--r--src/renderer.rs2
4 files changed, 20 insertions, 1 deletions
diff --git a/src/args.rs b/src/args.rs
index e42d2ff..7502d9f 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -294,6 +294,12 @@ pub struct CliArgs {
/// Enable README.md rendering in directories
#[arg(long, env = "MINISERVE_README")]
pub readme: bool,
+
+ /// Disable indexing
+ /// This will prevent miniserve from generating directory listings
+ /// and will return a 404 instead.
+ #[arg(long, env = "MINISERVE_DISABLE_INDEXING")]
+ pub disable_indexing: bool,
}
/// Checks whether an interface is valid, i.e. it can be parsed into an IP address
diff --git a/src/config.rs b/src/config.rs
index 43414b2..3643502 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -146,6 +146,9 @@ pub struct MiniserveConfig {
/// If enabled, render the readme from the current directory
pub readme: bool,
+ /// If enabled, indexing is disabled.
+ pub disable_indexing: bool,
+
/// If set, use provided rustls config for TLS
#[cfg(feature = "tls")]
pub tls_rustls_config: Option<rustls::ServerConfig>,
@@ -311,6 +314,7 @@ impl MiniserveConfig {
hide_theme_selector: args.hide_theme_selector,
show_wget_footer: args.show_wget_footer,
readme: args.readme,
+ disable_indexing: args.disable_indexing,
tls_rustls_config: tls_rustls_server_config,
compress_response: args.compress_response,
})
diff --git a/src/listing.rs b/src/listing.rs
index faa0918..a8668e3 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -376,6 +376,15 @@ pub fn directory_listing(
.body(actix_web::body::BodyStream::new(rx)),
))
} else {
+ if conf.disable_indexing {
+ return Ok(ServiceResponse::new(
+ req.clone(),
+ HttpResponse::NotFound()
+ .content_type(mime::TEXT_PLAIN_UTF_8)
+ .body("File not found."),
+ ));
+ }
+
Ok(ServiceResponse::new(
req.clone(),
HttpResponse::Ok().content_type(mime::TEXT_HTML_UTF_8).body(
diff --git a/src/renderer.rs b/src/renderer.rs
index 3b62704..b691bca 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -687,7 +687,7 @@ pub fn render_error(
p { (error) }
}
// WARN don't expose random route!
- @if conf.route_prefix.is_empty() {
+ @if conf.route_prefix.is_empty() && !conf.disable_indexing {
div.error-nav {
a.error-back href=(return_address) {
"Go back to file listing"