mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Disallow /ui when any Forwarded header is detected
This commit is contained in:
parent
a35cc5b9c0
commit
dc419e28c0
@ -1,6 +1,6 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::{ConnectInfo, State},
|
extract::{ConnectInfo, State},
|
||||||
http::{header::SET_COOKIE, HeaderValue},
|
http::{header::SET_COOKIE, HeaderMap, HeaderValue},
|
||||||
response::{Html, IntoResponse},
|
response::{Html, IntoResponse},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
@ -22,14 +22,19 @@ pub fn router(secret_token: String) -> Router {
|
|||||||
|
|
||||||
async fn ui(
|
async fn ui(
|
||||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||||
|
headers: HeaderMap,
|
||||||
State(token): State<UiApiToken>,
|
State(token): State<UiApiToken>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
if !addr.ip().is_loopback() {
|
const X_FORWARDED_FOR: &'_ str = "X-Forwarded-For";
|
||||||
|
if !addr.ip().is_loopback()
|
||||||
|
|| headers.contains_key(axum::http::header::FORWARDED)
|
||||||
|
|| headers.contains_key(X_FORWARDED_FOR)
|
||||||
|
{
|
||||||
return Html(
|
return Html(
|
||||||
r#"<!DOCTYPE html>
|
r#"<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
Ui is only accessible from 127.0.0.1
|
Ui is only accessible from 127.0.0.1. Usage of proxies is forbidden.
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"#
|
"#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user