This commit is contained in:
Mateusz Gruszczyński committed 2026-11-13 10:42:22 +01:00
1 parent f8fc228af1
commit ad0ff60632
13 files changed
+113 -28

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
"openapi": "3.0.3",
"info": {
"title": "RustProxy Administration API",
"version": "0.36.12",
"version": "0.36.13",
"description": "Administration API for the active panel origin. Sign in through the panel; the same-origin HttpOnly cookie authenticates all private operations. Mutations also require the exact Origin, X-RustProxy-Request: 1 and a session-bound X-CSRF-Token. Loopback HTTP is the default; Settings can enable HTTPS before using a non-loopback administration bind. This document contains no live configuration or credentials. Object schemas marked extensible are summaries: full configuration validation is authoritative in Rust. The API also permits explicitly scoped GeneralApiBearer tokens on a narrow route allowlist, with RO/RW and source CIDR checks; API-token management and Prometheus-token management are browser-session-only."
},
"servers": [
+10 -4
View File
@@ -103,10 +103,9 @@ fn invalid_admin_origin(
.any(|entry| entry.trim_start().starts_with("text/html"))
});
if request.method() == Method::GET && panel_document_path(request.uri().path()) && wants_html {
return secure((
StatusCode::FORBIDDEN,
axum::response::Html("<!doctype html><html lang=\"en\"><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>RustProxy - Access blocked</title><h1>RustProxy - Could not open the panel</h1><p>The request origin was rejected. Check the proxy/URL and try again.</p><p><a href=\"\">Reload panel</a></p></html>"),
).into_response());
let html = include_str!("web/admin_origin_rejected.html")
.replace("__RUSTPROXY_ASSET_ID__", asset_build_id());
return secure((StatusCode::FORBIDDEN, axum::response::Html(html)).into_response());
}
secure(reject(StatusCode::FORBIDDEN, "auth.invalid_origin"))
}
@@ -122,6 +121,13 @@ async fn guard(State(state): State<Arc<App>>, mut request: Request, next: Next)
Ok(value) => value,
Err(()) => return secure(reject(StatusCode::FORBIDDEN, "auth.invalid_host")),
};
let path = request.uri().path();
let presentation_asset = (request.method() == Method::GET || request.method() == Method::HEAD)
&& (path == "/favicon.svg"
|| fingerprinted_path(path, "/assets/").as_deref() == Some("/assets/style.css"));
if presentation_asset {
return secure(next.run(request).await);
}
let headers = request.headers();
let trusted_host = trusted_admin_proxy(&state, peer);
let trusted_proto = trusted_admin_forwarded_proto(&state, peer);
+29 -2
View File
@@ -340,6 +340,7 @@ mod tests {
async fn invalid_origin_on_document_is_visible_but_still_forbidden() {
let (router, store, _dir, _secret, _) = fixture().await;
let response = router
.clone()
.oneshot(
Request::builder()
.uri("/overview")
@@ -359,10 +360,36 @@ mod tests {
.to_str()
.unwrap()
.starts_with("text/html"));
let body = axum::body::to_bytes(response.into_body(), 4096)
let body = axum::body::to_bytes(response.into_body(), 16 * 1024)
.await
.unwrap();
assert!(String::from_utf8_lossy(&body).contains("Could not open the panel"));
let body = String::from_utf8_lossy(&body);
assert!(body.contains("Could not open the panel"));
assert!(body.contains("class=\"auth-page\""));
assert!(body.contains("class=\"login-card\""));
assert!(body.contains(asset_build_id()));
let stylesheet = format!("/assets/style_{}.css", asset_build_id());
let style_response = router
.oneshot(
Request::builder()
.uri(stylesheet)
.header("host", "127.0.0.1:9090")
.header("origin", "null")
.header("sec-fetch-site", "cross-site")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(style_response.status(), StatusCode::OK);
assert!(style_response
.headers()
.get(http::header::CONTENT_TYPE)
.unwrap()
.to_str()
.unwrap()
.starts_with("text/css"));
store.close().await;
}
+40
View File
@@ -0,0 +1,40 @@
<!doctype html>
<html data-theme="dark" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RustProxy / Access blocked</title>
<link rel="icon" href="/favicon.svg">
<link rel="stylesheet" href="/assets/style___RUSTPROXY_ASSET_ID__.css">
</head>
<body class="auth-page">
<header class="auth-top">
<a class="brand" href="" aria-label="RustProxy">
<span class="brand-mark">r<span>/</span>p</span><span>RustProxy</span>
</a>
<span class="pill danger">403</span>
</header>
<main class="auth-main">
<section class="login-section">
<h1>Administration</h1>
<div class="login-card">
<div class="card-heading">
<h2>Could not open the panel</h2>
<span class="pill danger">Access blocked</span>
</div>
<div class="operation-message error" role="alert">
The request origin was rejected. Check the proxy/URL and try again.
</div>
<p class="fine">If you use a reverse proxy, verify the public administration URL and the forwarded Host
and protocol.</p>
<form action="" method="get">
<button class="primary" type="submit">Reload panel</button>
</form>
</div>
</section>
</main>
</body>
</html>
+5 -1
View File
@@ -375,18 +375,22 @@ main {
padding: 18px
}
}
html[data-corner-style=square] {
--rp-docs-radius-surface: 0px;
--rp-docs-radius-control: 0px;
}
html[data-corner-style=subtle] {
--rp-docs-radius-surface: 5px;
--rp-docs-radius-control: 4px;
}
html[data-corner-style=rounded] {
--rp-docs-radius-surface: 12px;
--rp-docs-radius-control: 8px;
}
html[data-corner-style=extra] {
--rp-docs-radius-surface: 18px;
--rp-docs-radius-control: 12px;
@@ -411,4 +415,4 @@ html[data-corner-style=extra] {
.swagger-ui input,
.swagger-ui textarea {
border-radius: var(--rp-docs-radius-control, 0);
}
}