Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect to https depends on Source IP #3190

Closed
timo-42 opened this issue Apr 22, 2024 · 2 comments
Closed

Redirect to https depends on Source IP #3190

timo-42 opened this issue Apr 22, 2024 · 2 comments

Comments

@timo-42
Copy link

timo-42 commented Apr 22, 2024

I'm not sure if this is intended behavior or not, but the HTTP Scheme of the location header is different depending on the Source IP(https vs http):

curl -I -H 'x-forwarded-proto: https' localhost:8000/hello_world
HTTP/1.1 308 PERMANENT REDIRECT
Server: gunicorn
Date: Mon, 22 Apr 2024 16:44:38 GMT
Connection: close
Content-Type: text/html; charset=utf-8
Content-Length: 257
Location: https://localhost:8000/hello_world/
curl --interface '192.168.0.144' -I -H 'x-forwarded-proto: https' localhost:8000/hello_world
HTTP/1.1 308 PERMANENT REDIRECT
Server: gunicorn
Date: Mon, 22 Apr 2024 16:45:04 GMT
Connection: close
Content-Type: text/html; charset=utf-8
Content-Length: 255
Location: http://localhost:8000/hello_world/

How to reproduce:

echo "from flask import Flask
app = Flask(__name__)

@app.route('/hello_world/')
def hello_world():
    return 'Hello, World!'" > hello.py
pip install flask gunicorn
gunicorn 'hello:app'
@pajod
Copy link
Contributor

pajod commented Apr 23, 2024

Assuming your first example demonstrates a source IPv4 of 127.0.0.1, this is documented and intended behaviour. The X-FORWARDED-PROTO is only used when sent by a permissible forwarder, as configured by forwarded_allow_ips.

@timo-42
Copy link
Author

timo-42 commented Apr 23, 2024

Thank you for the fast feedback. I took a while to find this Issue in combination with the linked Istio Change. It would be nice if there was a better, HTTP Return message like:
The request is not coming from a trusted source, do not switch HTTP scheme to https.

@timo-42 timo-42 closed this as completed Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants