aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-08-25 15:48:37 -0400
committerGalen Guyer <galen@galenguyer.com>2022-08-25 16:29:08 -0400
commitc12d91acddcc8047a84eba5a9e11d4d3247412a9 (patch)
tree45073744f2f5a09282ae511b006e1ba88a86a67b
parent1989bdf34cfd0b12642841dd42efe5b49678a87b (diff)
Redirect to the configured host before OIDC if incorrecthost-redirect
-rw-r--r--packet/utils.py13
1 files changed, 12 insertions, 1 deletions
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