From c12d91acddcc8047a84eba5a9e11d4d3247412a9 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Aug 2022 15:48:37 -0400 Subject: Redirect to the configured host before OIDC if incorrect --- packet/utils.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packet/utils.py b/packet/utils.py index 75c9802..a6e9158 100644 --- a/packet/utils.py +++ b/packet/utils.py @@ -4,9 +4,10 @@ General utilities and decorators for supporting the Python logic from datetime import datetime, time, timedelta, date from functools import wraps, lru_cache from typing import Any, Callable, TypeVar, cast +from urllib.parse import urlparse import requests -from flask import session, redirect +from flask import session, redirect, request from packet import auth, app, db, ldap from packet.mail import send_start_packet_mail @@ -64,6 +65,16 @@ def is_freshman_on_floor(rit_username: str) -> bool: return False +@app.before_request +def before_reqest_callback() -> Any: + """ + Pre-request function to ensure we're on the right URL before OIDC sees anything + """ + if urlparse(request.base_url).hostname != app.config['SERVER_NAME']: + return redirect(request.base_url.replace(urlparse(request.base_url).hostname, + app.config['SERVER_NAME']), code=302) + return None + def packet_auth(func: WrappedFunc) -> WrappedFunc: """ Decorator for easily configuring oidc -- cgit v1.2.3