From 08a73c00a347eed1e9b4483f2b9f2d0b833174fe Mon Sep 17 00:00:00 2001 From: zhoupeiheng Date: Mon, 4 Jul 2022 16:05:01 +0800 Subject: fix: static file support route_prefix --- src/config.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 2ee014f..0a5c945 100644 --- a/src/config.rs +++ b/src/config.rs @@ -151,8 +151,11 @@ impl MiniserveConfig { // Generate some random routes for the favicon and css so that they are very unlikely to conflict with // real files. - let favicon_route = format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)); - let css_route = format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)); + let (favicon_route, css_route) = if args.random_route { + (format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)), format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET))) + } else { + (format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)), format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET))) + }; let default_color_scheme = args.color_scheme; let default_color_scheme_dark = args.color_scheme_dark; -- cgit v1.2.3 From e57125850d232c4f4eaafa4c3e7552df6bf80e2f Mon Sep 17 00:00:00 2001 From: zhoupeiheng Date: Wed, 20 Jul 2022 18:04:50 +0800 Subject: test: check_static_file_route_pattern --- src/config.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 0a5c945..d3aa845 100644 --- a/src/config.rs +++ b/src/config.rs @@ -152,9 +152,15 @@ impl MiniserveConfig { // Generate some random routes for the favicon and css so that they are very unlikely to conflict with // real files. let (favicon_route, css_route) = if args.random_route { - (format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)), format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET))) + ( + format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)), + format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)), + ) } else { - (format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)), format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET))) + ( + format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)), + format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)), + ) }; let default_color_scheme = args.color_scheme; -- cgit v1.2.3 From ff3bab81e9dc515e687c9bfea5dea0a719297131 Mon Sep 17 00:00:00 2001 From: zhoupeiheng Date: Thu, 28 Jul 2022 16:36:20 +0800 Subject: Apply suggestions from code review --- src/config.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index d3aa845..ec7ec66 100644 --- a/src/config.rs +++ b/src/config.rs @@ -151,6 +151,9 @@ impl MiniserveConfig { // Generate some random routes for the favicon and css so that they are very unlikely to conflict with // real files. + // If --random-route is enabled , in order to not leak the random generated route, we must not use it + // as static files prefix. + // Otherwise, we should apply route_prefix to static files. let (favicon_route, css_route) = if args.random_route { ( format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)), -- cgit v1.2.3