actix / actix/actix-web

realip_remote_addr behavior easily leads to insecure code

Đang mở
#3,750 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
A-web C-improvement
Ngôn ngữ chính
Rust
Star
24.8k
Fork
1.9k
Merge trung bình
23 giờ 10 phút
Pull request đã merge (30 ngày)
26

Mô tả

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).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with the linked ConnectionInfo::realip_remote_addr documentation and compare its behavior with remote_addr and host. Review Werkzeug's linked ProxyFix middleware for its opt-in proxy and trusted-proxy handling. Done should include a settled configuration/API direction, coverage for direct and proxied requests, and documentation that makes unsafe unconditional use clear.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
backend-api-design, security
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.