actix / actix/actix-web

realip_remote_addr behavior easily leads to insecure code

Abierto
#3,750 1 comentario 0 reacciones 0 asignados Ver en GitHub
A-web C-improvement
Lenguaje dominante
Rust
Estrellas
24.8k
Forks
1.9k
Merge medio
23 h 10 min
PR fusionados (30 d)
26

Descripción

https://docs.rs/actix-web/3.3.2/actix_web/dev/struct.ConnectionInfo.html#method.realip_remote_addr

This means that you have to use different functions depending on whether the application is behind a reverse proxy or not. But you tpyically do not want to recompile an application for something like this.

It would be much better if there was a config option indicating that the application is behind a proxy, and in that case have `remote_addr` return the correct one.

Realistically, there's a good chance that applications just use `realip_remote_addr` unconditionally, making it vulnerable to IP spoofing when it's not running behind a reverse proxy.

FWIW, the `host` logic seems to be similarly broken, since you can most likely pass a "bad" host header to an application if it's not behind a reverse proxy or that proxy does not filter out all the header this create uses.

FWIW, I recommend looking at how the [ProxyFix middleware for the werkzeug Python web framework](https://github.com/pallets/werkzeug/blob/main/src/werkzeug/middleware/proxy_fix.py) is implemented. It's opt-in, and lets you specify which proxy adds the data you want (in case of multiple proxies all adding to the headers).

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.