[core] Schema: reject wildcard header names, cap file size and upstreams, require <hostname>.toml

This commit is contained in:
2026-11-07 15:44:09 +01:00
parent 58d0397875
commit 60aee5d78a
11 changed files with 221 additions and 59 deletions
+4 -2
View File
@@ -10,7 +10,7 @@
use serde_json::{Map, Value, json};
use super::{CompileOptions, join};
use super::{CompileOptions, join, strip_headers};
use crate::{
AccessLog, AuthMode, ForwardAuth, HeaderRule, HeaderValue, Host, Model, Scheme, TlsMode,
Upstream,
@@ -204,11 +204,13 @@ fn logging(file: &str) -> Value {
fn host_route(h: &Host, fa: Option<&ForwardAuth>, o: &CompileOptions) -> Value {
let mut steps = Vec::new();
if let (AuthMode::ForwardAuth, Some(fa)) = (h.auth, fa) {
// Client-sent identity headers never reach the auth server or the upstream.
steps.push(json!({ "handle": [{ "handler": "headers", "request": { "delete": strip_headers(fa) } }] }));
steps.push(json!({ "handle": [forward_auth(fa)] }));
}
if !h.websockets {
steps.push(json!({
"match": [{ "header_regexp": { "Upgrade": { "pattern": "(?i)^websocket$" } } }],
"match": [{ "header_regexp": { "Upgrade": { "pattern": "(?i)(^|,)\\s*websocket\\s*(,|$)" } } }],
"handle": [{ "handler": "static_response", "status_code": 403 }]
}));
}
+2 -1
View File
@@ -4,7 +4,7 @@
//! Model → [`EdgeConfig`] for the Pingora data plane.
use super::{CompileOptions, join};
use super::{CompileOptions, join, strip_headers};
use crate::edge_config::{
EDGE_CONFIG_VERSION, EdgeAcme, EdgeConfig, EdgeForwardAuth, EdgeHeaderOp, EdgeHealthCheck,
EdgeHost, EdgeTls, EdgeUpstream, EdgeValue,
@@ -30,6 +30,7 @@ pub(super) fn compile(model: &Model, o: &CompileOptions) -> EdgeConfig {
upstream: upstream(&fa.upstream),
path_and_query: fa.path_and_query.clone(),
copy_headers: fa.copy_headers.clone(),
strip_headers: strip_headers(fa),
}),
hosts: model
.hosts()
+15
View File
@@ -108,6 +108,21 @@ fn check_path(p: &str) -> Result<(), &'static str> {
Ok(())
}
/// 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> {
let mut out: Vec<String> = crate::AUTHELIA_COPY_HEADERS
.iter()
.map(|h| (*h).to_owned())
.collect();
for h in &fa.copy_headers {
if !out.iter().any(|o| o.eq_ignore_ascii_case(h)) {
out.push(h.clone());
}
}
out
}
/// Join a validated directory and a validated file name.
fn join(dir: &str, file: &str) -> String {
format!("{}/{}", dir.trim_end_matches('/'), file)