feat(server): honor X-Forward-* headers (#61)

* honor X-Forward-* headers

Behind a reverse proxy, the log entries always showed the IP address of the reverse proxy.
With this change the real IP address of the client is shown.
Since the IP address is only used for info in the log, there are no security implications.

* style(format): apply formatting

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
Helmut K. C. Tessarek 2023-06-12 19:00:55 -04:00 committed by GitHub
parent 917074158a
commit f7beaef502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -157,7 +157,9 @@ async fn main() -> IoResult<()> {
App::new()
.app_data(Data::clone(&config))
.app_data(Data::new(http_client))
.wrap(Logger::default())
.wrap(Logger::new(
"%{r}a \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\" %T",
))
.wrap(ContentLengthLimiter::new(
server_config.max_content_length.get_bytes(),
))
@ -197,7 +199,9 @@ async fn actix_web(
web::scope("")
.app_data(Data::clone(&config))
.app_data(Data::new(http_client))
.wrap(Logger::default())
.wrap(Logger::new(
"%{r}a \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\" %T",
))
.wrap(ContentLengthLimiter::new(
server_config.max_content_length.get_bytes(),
))

View File

@ -128,7 +128,7 @@ async fn version(
.read()
.map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?;
let connection = request.connection_info().clone();
let host = connection.peer_addr().unwrap_or("unknown host");
let host = connection.realip_remote_addr().unwrap_or("unknown host");
auth::check(
host,
request.headers(),
@ -153,7 +153,7 @@ async fn upload(
config: web::Data<RwLock<Config>>,
) -> Result<HttpResponse, Error> {
let connection = request.connection_info().clone();
let host = connection.peer_addr().unwrap_or("unknown host");
let host = connection.realip_remote_addr().unwrap_or("unknown host");
let server_url = match config
.read()
.map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?