[control] Previews: POST/GET/DELETE /api/v1/previews, tokens scoped to previews only, the upstream allow list, expiry; Windows drive paths in compile options (tests first)
This commit is contained in:
@@ -109,9 +109,13 @@ fn check_options(o: &CompileOptions) -> Result<(), CompileError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Paths end up inside JSON strings and Caddy `{file.*}` placeholders.
|
||||
/// Paths end up inside JSON strings and Caddy `{file.*}` placeholders. Absolute: `/…` on
|
||||
/// Linux, or a drive path with forward slashes on Windows (`C:/ProgramData/Ianitor/…`, which
|
||||
/// Caddy and Go read as is; control writes backslashes as `/`, see [`windows_path`]).
|
||||
fn check_path(p: &str) -> Result<(), &'static str> {
|
||||
if !p.starts_with('/') {
|
||||
let drive =
|
||||
p.len() >= 3 && p.as_bytes()[0].is_ascii_alphabetic() && &p.as_bytes()[1..3] == b":/";
|
||||
if !p.starts_with('/') && !drive {
|
||||
return Err("it must be an absolute path");
|
||||
}
|
||||
if p.len() > 1024 {
|
||||
@@ -126,6 +130,19 @@ fn check_path(p: &str) -> Result<(), &'static str> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A Windows path as the compilers take it: `C:\ProgramData\Ianitor` → `C:/ProgramData/Ianitor`.
|
||||
/// Anything that is not a drive path is returned unchanged (and a Linux path with a backslash
|
||||
/// is still refused by the option check).
|
||||
pub fn windows_path(p: &str) -> String {
|
||||
let b = p.as_bytes();
|
||||
if b.len() >= 3 && b[0].is_ascii_alphabetic() && b[1] == b':' && (b[2] == b'\\' || b[2] == b'/')
|
||||
{
|
||||
p.replace('\\', "/")
|
||||
} else {
|
||||
p.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
/// Identity headers never accepted from clients on forward-auth hosts: Authelia's four, then
|
||||
/// any other configured copy header (case-insensitive, no duplicates).
|
||||
fn strip_headers(fa: &crate::ForwardAuth) -> Vec<String> {
|
||||
|
||||
@@ -32,8 +32,8 @@ use ring::rand::{SecureRandom, SystemRandom};
|
||||
|
||||
pub use domi_pki::{
|
||||
CertInfo, DEVICE_DAYS, EkuInfo, INTERMEDIATE_DAYS, INTERMEDIATE_OPENSSL_EXT, KeyPair,
|
||||
KeyUsageInfo, ORG, ROOT_CN, ROOT_DAYS, SERVER_DAYS, SERVER_RENEW_DAYS, der_to_pem,
|
||||
match_code, openssl_sign_command, sha256_hex,
|
||||
KeyUsageInfo, ORG, ROOT_CN, ROOT_DAYS, SERVER_DAYS, SERVER_RENEW_DAYS, der_to_pem, match_code,
|
||||
openssl_sign_command, sha256_hex,
|
||||
};
|
||||
|
||||
/// Subject CN of the intermediate. Signers refuse a CSR whose CN does not start with this.
|
||||
|
||||
@@ -124,7 +124,11 @@ fn part(shown: &str, original: &str, max: usize, min: usize) -> String {
|
||||
cut.pop();
|
||||
}
|
||||
let h = short_hash(original);
|
||||
if cut.is_empty() { h } else { format!("{cut}-{h}") }
|
||||
if cut.is_empty() {
|
||||
h
|
||||
} else {
|
||||
format!("{cut}-{h}")
|
||||
}
|
||||
}
|
||||
|
||||
/// The DNS label of a branch's preview.
|
||||
|
||||
Reference in New Issue
Block a user