Skip to content

Commit

Permalink
Fixes a redirect vulnerability when the user opens the pgAdmin URL. F…
Browse files Browse the repository at this point in the history
…ixes #5343
  • Loading branch information
adityatoshniwal authored and akshay-joshi committed Sep 19, 2022
1 parent bfabcea commit e2b00dd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/en_US/release_notes_6_14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Bug fixes
| `Issue #5323 <https://github.com/postgres/pgadmin4/issues/5323>`_ - Replace the language selection 'Brazilian' with 'Portuguese (Brazilian). (RM #7693)
| `Issue #5325 <https://github.com/postgres/pgadmin4/issues/5325>`_ - Fixed an issue where server names with special characters are not displayed correctly in the process tab. (RM #7695)
| `Issue #5333 <https://github.com/postgres/pgadmin4/issues/5333>`_ - Fixed an issue where ERD throws an error if variable is added to the column. (RM #7709)
| `Issue #5343 <https://github.com/postgres/pgadmin4/issues/5343>`_ - Fixes a redirect vulnerability when the user opens the pgAdmin URL.
7 changes: 3 additions & 4 deletions web/pgadmin/authenticate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
session, redirect
from flask_babel import gettext
from flask_security.views import _security
from flask_security.utils import get_post_logout_redirect, \
get_post_login_redirect, logout_user
from flask_security.utils import get_post_logout_redirect, logout_user

from pgadmin.model import db, User
from pgadmin.utils import PgAdminModule
from pgadmin.utils import PgAdminModule, get_safe_post_login_redirect
from pgadmin.utils.constants import KERBEROS, INTERNAL, OAUTH2, LDAP
from pgadmin.authenticate.registry import AuthSourceRegistry

Expand Down Expand Up @@ -145,7 +144,7 @@ def login():

if 'auth_obj' in session:
session.pop('auth_obj')
return redirect(get_post_login_redirect())
return redirect(get_safe_post_login_redirect())

elif isinstance(msg, Response):
return msg
Expand Down
9 changes: 4 additions & 5 deletions web/pgadmin/authenticate/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
redirect, Flask, flash
from flask_babel import gettext
from flask_security import login_user, current_user
from flask_security.utils import get_post_logout_redirect, \
get_post_login_redirect, logout_user
from flask_security.utils import get_post_logout_redirect, logout_user

from pgadmin.authenticate.internal import BaseAuthentication
from pgadmin.model import User
from pgadmin.tools.user_management import create_user
from pgadmin.utils.constants import OAUTH2
from pgadmin.utils import PgAdminModule
from pgadmin.utils import PgAdminModule, get_safe_post_login_redirect
from pgadmin.utils.csrf import pgCSRFProtect
from pgadmin.model import db

Expand Down Expand Up @@ -58,12 +57,12 @@ def oauth_authorize():
session['auth_source_manager'] = auth_obj.as_dict()
if 'auth_obj' in session:
session.pop('auth_obj')
return redirect(get_post_login_redirect())
return redirect(get_safe_post_login_redirect())
if 'auth_obj' in session:
session.pop('auth_obj')
logout_user()
flash(msg, 'danger')
return redirect(get_post_login_redirect())
return redirect(get_safe_post_login_redirect())

@blueprint.route('/logout', endpoint="logout",
methods=['GET', 'POST'])
Expand Down
14 changes: 13 additions & 1 deletion web/pgadmin/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
from collections import defaultdict
from operator import attrgetter

from flask import Blueprint, current_app
from flask import Blueprint, current_app, url_for
from flask_babel import gettext
from flask_security import current_user, login_required
from flask_security.utils import get_post_login_redirect
from threading import Lock

from .paths import get_storage_directory
Expand Down Expand Up @@ -831,3 +832,14 @@ def hard_reset(self):

if user is not None:
del self.users[current_user.id]


def get_safe_post_login_redirect():
allow_list = [
url_for('browser.index')
]
url = get_post_login_redirect()
if url in allow_list:
return url

return "/"

0 comments on commit e2b00dd

Please sign in to comment.