v0.42.2_fix1
This commit is contained in:
1 parent
f38a2b9e5e
commit
15c7f9ff9e
24 files changed
+464
-77
No files matched your search
@@ -5,27 +5,33 @@ fn redirect_status(value: &str) -> Option<StatusCode> {
|
||||
"seeother" | "303" => Some(StatusCode::SEE_OTHER),
|
||||
"307" => Some(StatusCode::TEMPORARY_REDIRECT),
|
||||
"308" => Some(StatusCode::PERMANENT_REDIRECT),
|
||||
"404" => Some(StatusCode::NOT_FOUND),
|
||||
"gone" | "410" => Some(StatusCode::GONE),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn redirect_rule(parts: &[String], regex: bool) -> Result<SimpleRedirect> {
|
||||
let (status, source_index) = if parts.len() == 4 {
|
||||
(redirect_status(&parts[1]).context("unsupported Redirect status")?, 2)
|
||||
} else {
|
||||
ensure!(parts.len() == 3, "Redirect / RedirectMatch expects [status] source target");
|
||||
(StatusCode::FOUND, 1)
|
||||
};
|
||||
let explicit = parts.get(1).and_then(|value| redirect_status(value));
|
||||
let (status, source_index) = explicit.map_or((StatusCode::FOUND, 1), |status| (status, 2));
|
||||
let status_only = matches!(status, StatusCode::NOT_FOUND | StatusCode::GONE);
|
||||
ensure!(parts.len() == source_index + if status_only { 1 } else { 2 },
|
||||
"Redirect / RedirectMatch expects [status] source target, or 404/gone source without target");
|
||||
let source = &parts[source_index];
|
||||
let replacement = &parts[source_index + 1];
|
||||
ensure!(!source.is_empty() && source.len() <= 512 && replacement.len() <= 1024,
|
||||
"Redirect source/target is invalid");
|
||||
ensure!((replacement.starts_with('/') && !replacement.starts_with("//"))
|
||||
|| replacement.starts_with("http://") || replacement.starts_with("https://"),
|
||||
"Redirect target must be a local absolute path or an explicit http(s) URL");
|
||||
ensure!(!replacement.contains('\\') && !replacement.contains('\r') && !replacement.contains('\n'),
|
||||
"Redirect target contains unsafe characters");
|
||||
HeaderValue::from_str(replacement).context("invalid Redirect target")?;
|
||||
ensure!(!source.is_empty() && source.len() <= 512, "Redirect source is invalid");
|
||||
let replacement = if status_only {
|
||||
None
|
||||
} else {
|
||||
let replacement = &parts[source_index + 1];
|
||||
ensure!(replacement.len() <= 1024, "Redirect target is too long");
|
||||
ensure!((replacement.starts_with('/') && !replacement.starts_with("//"))
|
||||
|| replacement.starts_with("http://") || replacement.starts_with("https://"),
|
||||
"Redirect target must be a local absolute path or an explicit http(s) URL");
|
||||
ensure!(!replacement.contains('\\') && !replacement.contains('\r') && !replacement.contains('\n'),
|
||||
"Redirect target contains unsafe characters");
|
||||
HeaderValue::from_str(replacement).context("invalid Redirect target")?;
|
||||
Some(replacement.to_owned())
|
||||
};
|
||||
let matcher = if regex {
|
||||
RedirectMatcher::Regex(Regex::new(source).context("invalid RedirectMatch regex")?)
|
||||
} else {
|
||||
@@ -34,7 +40,7 @@ fn redirect_rule(parts: &[String], regex: bool) -> Result<SimpleRedirect> {
|
||||
&& !source.contains('#') && !source.contains('\\'), "invalid Redirect path prefix");
|
||||
RedirectMatcher::Prefix(source.to_owned())
|
||||
};
|
||||
Ok(SimpleRedirect { matcher, replacement: replacement.to_owned(), status })
|
||||
Ok(SimpleRedirect { matcher, replacement, status })
|
||||
}
|
||||
|
||||
// Only a safe, deterministic subset of Apache access rules is allowed in
|
||||
|
||||
Reference in new issue
Block a user