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

OpenID HTTPS redirect fix #91

Merged
merged 6 commits into from
Oct 8, 2024
Merged

OpenID HTTPS redirect fix #91

merged 6 commits into from
Oct 8, 2024

Conversation

megascatterbomb
Copy link
Contributor

Fixes some edge cases where the openid config wasn't properly forcing HTTPS.

@jayceslesar
Copy link
Contributor

jayceslesar commented Sep 10, 2024

This should all be handled on the nginx side of things too -- it should not accept any http traffic or rather redirect it all to https

@megascatterbomb
Copy link
Contributor Author

Latest commits fix #92

Comment on lines +87 to +89
if not fake_ip.startswith("169.254"):
if ":" not in fake_ip:
fake_ip = f"{fake_ip}:27015"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what with this custom port?

Copy link
Contributor Author

@megascatterbomb megascatterbomb Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is the port TF2 assumes if none is specified.

Comment on lines 273 to 283
dev_mode = os.getenv("DEVELOPMENT")
if dev_mode is not None and dev_mode.lower() == "true":
if base_url.startswith("https://"):
base_url = base_url.replace("https://", "http://")
else:
base_url = "http://" + base_url
else:
if base_url.startswith("http://"):
base_url = base_url.replace("http://", "https://")
else:
base_url = "https://" + base_url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, maybe worth making this a function somewhere else and calling here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems a bit buggy..
If dev_mode is enabled and the base_url starts with http://, it will get modified to be http://http://<base url>.
If the base_url starts with https://, then it will be set to http://<base url> as expected.
Same goes for the branch when dev_mode is disabled (except with https:// instead).

You can also simplify the actual string replacement, since calling replace on "https://" on a string with "http://" is just a no-op and returns the original string.

# Default a protocol if the base_url doesn't start with one
if not base_url.startswith("http"):
    base_url = "https://" + base_url

if os.getenv('DEVELOPMENT', 'false').lower() == 'true':
    base_url = base_url.replace("https://", "http://") 
else:
    base_url = base_url.replace("http://", "https://") 

Copy link
Contributor

@lili7h lili7h Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you can do some pythonic splitting...

proto = "http://" if os.getenv('DEVELOPMENT', 'false').lower() == 'true' else "https://"
base_url = proto + base_url.split("//")[-1]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented your pythonic method with an additional check for None on os.getenv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, didn't realise the extra parameter on getenv handled that case.

@megascatterbomb
Copy link
Contributor Author

Been running this branch in production for weeks without issue, going to merge to main.

@megascatterbomb megascatterbomb merged commit a99809c into main Oct 8, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

3 participants